Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
hvelarde committed May 25, 2018
1 parent 8df8654 commit 9875c91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 14 additions & 3 deletions src/brasil/gov/agenda/tests/test_upgrades.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,23 @@ def test_fix_subjects_on_agendas(self):
step = self.get_upgrade_step(title)
self.assertIsNotNone(step)

import datetime
date = datetime.datetime(2018, 5, 25)
with api.env.adopt_roles(['Manager']):
obj = api.content.create(self.portal, 'Agenda', 'foo')
agenda = api.content.create(self.portal, 'Agenda', 'foo')
agendadiaria = api.content.create(
agenda, 'AgendaDiaria', '2018-05-25', date=date)
compromisso = api.content.create(
agendadiaria, 'Compromisso', 'bar', start_date=date)

# simulate issue
obj.subjects = None
agenda.subjects = None
agendadiaria.subjects = None
compromisso.subjects = None

# run the upgrade step to validate the update
self.execute_upgrade_step(step)
self.assertEqual(obj.subjects, ())

self.assertEqual(agenda.subjects, ())
self.assertEqual(agendadiaria.subjects, ())
self.assertEqual(compromisso.subjects, ())
7 changes: 3 additions & 4 deletions src/brasil/gov/agenda/upgrades/v4004/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ def fix_subjects_on_agendas(setup_tool):
Refs. https://github.com/plonegovbr/brasil.gov.agenda/issues/85
"""
test = 'test' in setup_tool.REQUEST # used to ignore transactions on tests
logger.info('Reindexing the catalog')
logger.info('Fixing subject field values in agendas')
catalog = api.portal.get_tool('portal_catalog')
results = catalog(portal_type='Agenda')
logger.info(u'Found {0} agendas'.format(len(results)))
results = catalog(portal_type=['Agenda', 'AgendaDiaria', 'Compromisso'])
logger.info('{0} items will be analyzed'.format(len(results)))
n = 0
for obj in get_valid_objects(results):
if obj.subjects is not None:
continue

obj.subjects = ()
catalog.catalog_object(obj, idxs=['Subject'])
n += 1
if n % 1000 == 0 and not test:
transaction.commit()
Expand Down

0 comments on commit 9875c91

Please sign in to comment.