Skip to content

Commit

Permalink
flake8 fixes, with better section testing.
Browse files Browse the repository at this point in the history
dracos committed Jun 16, 2017
1 parent 9fb853d commit 5d5c5f6
Showing 4 changed files with 53 additions and 50 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ def read_file(filename):
filepath = os.path.join(file_dir, filename)
return open(filepath).read()


# Fix for dateutil/SSL py3 support
if sys.version_info >= (3,):
dateutil = 'python-dateutil >= 2'
1 change: 1 addition & 0 deletions speeches/forms.py
Original file line number Diff line number Diff line change
@@ -615,6 +615,7 @@ def clean(self):
_('Timestamps must be distinct'))
previous_timestamp = timestamp


RecordingTimestampFormSet = inlineformset_factory(
Recording,
RecordingTimestamp,
1 change: 1 addition & 0 deletions speeches/templatetags/pagination_tags.py
Original file line number Diff line number Diff line change
@@ -135,5 +135,6 @@ def paginate(context, window=DEFAULT_WINDOW, hashtag=''):
except (KeyError, AttributeError):
return {}


register.inclusion_tag('pagination/pagination.html', takes_context=True)(
paginate)
100 changes: 50 additions & 50 deletions speeches/tests/importer_tests.py
Original file line number Diff line number Diff line change
@@ -40,12 +40,12 @@ def setUp(self):
self.importer = ImportAkomaNtoso(instance=self.instance, commit=True)

def _list_sections(self):
# Make mapping {section name: list of its speeches' texts}
# Make list [section name: list of its speeches' texts}
sections = {section.id: [] for section in Section.objects.all()}
for speech in Speech.objects.all():
if speech.section_id:
sections[speech.section_id].append(speech.text)
return {section.title: sections[section.id] for section in Section.objects.all()}
return [(section.title, sections[section.id]) for section in Section.objects.all()]

def test_import_sample_file(self):
self.importer.import_document(
@@ -65,127 +65,127 @@ def test_already_imported(self):
'speeches/fixtures/test_inputs/test_xpath.xml')
self.assertEqual(
self._list_sections(),
{'This is the title': ['<p>Hello</p>']}
[('This is the title', ['<p>Hello</p>'])]
)

ImportAkomaNtoso(instance=self.instance, commit=True, clobber='skip').import_document(
'speeches/tests/data/fake_http/test_clobber.xml')
self.assertEqual(
self._list_sections(),
{'This is the title': ['<p>Hello</p>']}
[('This is the title', ['<p>Hello</p>'])]
)

ImportAkomaNtoso(instance=self.instance, commit=True, clobber='merge').import_document(
'speeches/tests/data/fake_http/test_clobber.xml')
self.assertEqual(
self._list_sections(),
{'This is the title': ['<p>Hello</p>', '<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('This is the title', ['<p>Hello</p>', '<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])

ImportAkomaNtoso(instance=self.instance, commit=True, clobber='replace').import_document(
'speeches/tests/data/fake_http/test_clobber.xml')
self.assertEqual(
self._list_sections(),
{'This is the title': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('This is the title', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])

ImportAkomaNtoso(instance=self.instance, commit=True).import_document(
'speeches/tests/data/fake_http/test_clobber.xml')
self.assertEqual(
self._list_sections(),
{'This is the title': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
'This is the title': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('This is the title', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
('This is the title', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])

def test_not_already_imported(self):
ImportAkomaNtoso(instance=self.instance, commit=True, clobber='skip').import_document(
'speeches/tests/data/fake_http/test_clobber.xml')
self.assertEqual(
self._list_sections(),
{'This is the title': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('This is the title', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])
Section.objects.all().delete()

ImportAkomaNtoso(instance=self.instance, commit=True, clobber='merge').import_document(
'speeches/tests/data/fake_http/test_clobber.xml')
self.assertEqual(
self._list_sections(),
{'This is the title': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('This is the title', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])
Section.objects.all().delete()

ImportAkomaNtoso(instance=self.instance, commit=True, clobber='replace').import_document(
'speeches/tests/data/fake_http/test_clobber.xml')
self.assertEqual(
self._list_sections(),
{'This is the title': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('This is the title', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])
Section.objects.all().delete()

ImportAkomaNtoso(instance=self.instance, commit=True).import_document(
'speeches/tests/data/fake_http/test_clobber.xml')
self.assertEqual(
self._list_sections(),
{'This is the title': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('This is the title', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])
Section.objects.all().delete()

def test_empty_title(self):
self.importer.import_document(
'speeches/fixtures/test_inputs/test_empty_title.xml')
self.assertEqual(
self._list_sections(),
{'Untitled': ['<p>Hello</p>'],
'Untitled': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('Untitled', ['<p>Hello</p>']),
('Untitled', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])

ImportAkomaNtoso(instance=self.instance, commit=True, clobber='skip').import_document(
'speeches/fixtures/test_inputs/test_empty_title.xml')
self.assertEqual(
self._list_sections(),
{'Untitled': ['<p>Hello</p>'],
'Untitled': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('Untitled', ['<p>Hello</p>']),
('Untitled', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])

ImportAkomaNtoso(instance=self.instance, commit=True, clobber='merge').import_document(
'speeches/fixtures/test_inputs/test_empty_title.xml')
self.assertEqual(
self._list_sections(),
{'Untitled': ['<p>Hello</p>', '<p>Hello</p>', '<p>Howdy</p>'],
'Untitled': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>', '<p>Bye</p>'],
})
[('Untitled', ['<p>Hello</p>', '<p>Hello</p>', '<p>Howdy</p>']),
('Untitled', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>', '<p>Bye</p>']),
])

ImportAkomaNtoso(instance=self.instance, commit=True, clobber='replace').import_document(
'speeches/fixtures/test_inputs/test_empty_title.xml')
self.assertEqual(
self._list_sections(),
{'Untitled': ['<p>Hello</p>'],
'Untitled': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('Untitled', ['<p>Hello</p>']),
('Untitled', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])

ImportAkomaNtoso(instance=self.instance, commit=True).import_document(
'speeches/fixtures/test_inputs/test_empty_title.xml')
self.assertEqual(
self._list_sections(),
{'Untitled': ['<p>Hello</p>'],
'Untitled': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
'Untitled': ['<p>Hello</p>'],
'Untitled': ['<p>Howdy</p>'],
'Conclusions': ['<p>Bye</p>'],
})
[('Untitled', ['<p>Hello</p>']),
('Untitled', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
('Untitled', ['<p>Hello</p>']),
('Untitled', ['<p>Howdy</p>']),
('Conclusions', ['<p>Bye</p>']),
])

def test_empty_docDate(self):
self.importer.import_document(

0 comments on commit 5d5c5f6

Please sign in to comment.