def test_footnote_refs(self): psv = ParagraphSXSView() psv.footnote_tpl = template_engines['django'].from_string( "[{{footnote.reference}}]") sxs = { 'paragraphs': [ 'This is paragraph 1, I mean zero', 'Will the real paragraph one please stand up?', 'I am paragraph 10. Is that good enough?'], 'footnote_refs': [ {'reference': '1', 'paragraph': 0, 'offset': 7}, {'reference': '2', 'paragraph': 0, 'offset': 27}, {'reference': '12', 'paragraph': 2, 'offset': 1}], 'children': [ {'paragraphs': ['Subparagraph here'], 'footnote_refs': [ {'reference': '22', 'paragraph': 0, 'offset': 12}], 'children': []}]} psv.footnote_refs(sxs) self.assertEqual('This is[1] paragraph 1, I mean[2] zero', sxs['paragraphs'][0]) self.assertEqual('Will the real paragraph one please stand up?', sxs['paragraphs'][1]) self.assertEqual('I[12] am paragraph 10. Is that good enough?', sxs['paragraphs'][2]) self.assertEqual('Subparagraph[22] here', sxs['children'][0]['paragraphs'][0])
def test_footnote_refs(self): psv = ParagraphSXSView() psv.footnote_tpl = Template("[{{footnote.reference}}]") sxs = { 'paragraphs': [ 'This is paragraph 1, I mean zero', 'Will the real paragraph one please stand up?', 'I am paragraph 10. Is that good enough?'], 'footnote_refs': [ {'reference': '1', 'paragraph': 0, 'offset': 7}, {'reference': '2', 'paragraph': 0, 'offset': 27}, {'reference': '12', 'paragraph': 2, 'offset': 1}], 'children': [ {'paragraphs': ['Subparagraph here'], 'footnote_refs': [ {'reference': '22', 'paragraph': 0, 'offset': 12}], 'children': []}]} psv.footnote_refs(sxs) self.assertEqual('This is[1] paragraph 1, I mean[2] zero', sxs['paragraphs'][0]) self.assertEqual('Will the real paragraph one please stand up?', sxs['paragraphs'][1]) self.assertEqual('I[12] am paragraph 10. Is that good enough?', sxs['paragraphs'][2]) self.assertEqual('Subparagraph[22] here', sxs['children'][0]['paragraphs'][0])
def test_get_context_data(self, further_analyses, notices, generator): psv = ParagraphSXSView() generator.get_sxs.return_value = { 'labels': ['lablab', 'another-label'], 'children': [], 'page': 1234, 'paragraphs': ['some', 'content'] } context = psv.get_context_data(label_id='lablab', notice_id='nnnn', version='vvv') self.assertTrue('sxs' in context) self.assertTrue('label' in context['sxs'])
def test_further_analyses(self, api_reader): doc1 = {'publication_date': '2009-04-05', 'fr_volume': 21, 'fr_page': 98989, 'reference': ['doc1', '1212-31']} doc2 = {'publication_date': '2010-03-03', 'fr_volume': 22, 'fr_page': 87655, 'reference': ['doc2', '1212-31']} doc3 = {'publication_date': '2010-10-12', 'fr_volume': 22, 'fr_page': 90123, 'reference': ['doc3', '1212-31']} doc4 = {'publication_date': '2009-03-07', 'fr_volume': 21, 'fr_page': 98888, 'reference': ['doc4', '1212-31-b']} api_reader.ApiReader.return_value.layer.return_value = { '1212-31': [doc1, doc2, doc3], '1212-31-b': [doc4] } psv = ParagraphSXSView() self.assertEqual( psv.further_analyses('1212-31', 'doc1', 98989, 'v1'), convert_to_python([doc3, doc2])) self.assertEqual( psv.further_analyses('1212-31', 'doc5', 0, 'v1'), convert_to_python([doc3, doc2, doc1])) self.assertEqual( psv.further_analyses('1212-31', 'doc3', 90123, 'v1'), convert_to_python([doc2, doc1])) self.assertEqual( psv.further_analyses('1212-31-b', 'doc3', 90123, 'v1'), convert_to_python([doc4])) self.assertEqual(psv.further_analyses('1212-31-b', 'doc4', 98888, 'v1'), []) self.assertEqual(psv.further_analyses('1212-31-c', 'doc1', 98989, 'v1'), []) # Same notice + label. Different page doc5 = {'publication_date': '2009-04-05', 'fr_volume': 21, 'fr_page': 10101, 'reference': ['doc1', '1212-31']} api_reader.ApiReader.return_value.layer.return_value = { '1212-31': [doc1, doc2, doc3, doc5], '1212-31-b': [doc4] } self.assertEqual( psv.further_analyses('1212-31', 'doc1', 98989, 'v1'), convert_to_python([doc5, doc3, doc2])) self.assertEqual( psv.further_analyses('1212-31', 'doc1', 10101, 'v1'), convert_to_python([doc3, doc2, doc1])) self.assertEqual( psv.further_analyses('1212-31', 'doc3', 90123, 'v1'), convert_to_python([doc5, doc2, doc1]))
def content(self, context): partial_view = ParagraphSXSView.as_view() response = partial_view(self.request, label_id=context['label_id'], notice_id=context['notice_id']) self._assert_good(response) response.render() return response.content
def test_footnotes(self): psv = ParagraphSXSView() notice = { 'footnotes': { '12': 'Twelve', '22': 'Twenty-two', '31': 'Thirty-one', '45': 'Forty-five' } } sxs = { 'footnote_refs': [{ 'reference': '12', 'paragraph': 4, 'offset': 233 }, { 'reference': '22', 'paragraph': 2, 'offset': 111 }], 'children': [{ 'footnote_refs': [{ 'reference': '45', 'paragraph': 3, 'offset': 22 }], 'children': [] }] } footnotes = psv.footnotes(notice, sxs) self.assertEqual(len(footnotes), 3) self.assertEqual(footnotes[0]['reference'], '12') self.assertEqual(footnotes[0]['text'], 'Twelve') self.assertEqual(footnotes[1]['reference'], '22') self.assertEqual(footnotes[1]['text'], 'Twenty-two') self.assertEqual(footnotes[2]['reference'], '45') self.assertEqual(footnotes[2]['text'], 'Forty-five')
def test_footnotes(self): psv = ParagraphSXSView() notice = {'footnotes': { '12': 'Twelve', '22': 'Twenty-two', '31': 'Thirty-one', '45': 'Forty-five' }} sxs = { 'footnote_refs': [ {'reference': '12', 'paragraph': 4, 'offset': 233}, {'reference': '22', 'paragraph': 2, 'offset': 111}], 'children': [ {'footnote_refs': [ {'reference': '45', 'paragraph': 3, 'offset': 22}], 'children': []}]} footnotes = psv.footnotes(notice, sxs) self.assertEqual(len(footnotes), 3) self.assertEqual(footnotes[0]['reference'], '12') self.assertEqual(footnotes[0]['text'], 'Twelve') self.assertEqual(footnotes[1]['reference'], '22') self.assertEqual(footnotes[1]['text'], 'Twenty-two') self.assertEqual(footnotes[2]['reference'], '45') self.assertEqual(footnotes[2]['text'], 'Forty-five')
url(r'^partial/search(?:/cfr)?/%s$' % reg_pattern, PartialSearch.as_view(), name='partial_search', kwargs={'doc_type': 'cfr'}), url(r'^partial/search/preamble/%s$' % preamble_pattern, PartialSearch.as_view(), name='partial_search', kwargs={'doc_type': 'preamble'}), # A diff view of a section (without chrome) url(r'^partial/diff/%s/%s/%s$' % ( section_pattern, version_pattern, newer_version_pattern), lt_cache(PartialSectionDiffView.as_view()), name='partial_section_diff_view'), # A section by section paragraph (without chrome) # Example: http://.../partial/sxs/201-2-g/2011-1738 url(r'^partial/sxs/%s/%s$' % (paragraph_pattern, notice_pattern), lt_cache(ParagraphSXSView.as_view()), name='paragraph_sxs_view'), # A definition templated to be displayed in the sidebar (without chrome) # Example: http://.../partial/definition/201-2-g/2011-1738 url(r'^partial/definition/%s/%s$' % (paragraph_pattern, version_pattern), lt_cache(PartialDefinitionView.as_view()), name='partial_definition_view'), # A regulation section without chrome # Example: http://.../partial/201-4/2013-10704 url(r'^partial/%s/%s$' % (section_pattern, version_pattern), lt_cache(PartialSectionView.as_view()), name='partial_section_view'), # Subterp, interpretations of a whole subpart, emptypart or appendices # Example: http://.../partial/201-Subpart-A-Interp/2013-10706 # http://.../partial/201-Subpart-Interp/2013-10706 # http://.../partial/201-Appendices-Interp/2013-10706
name='sidebar'), # Load just search results url(r'^partial/search/%s$' % reg_pattern, PartialSearch.as_view(), name='partial_search'), #A diff view of a section (without chrome) url(r'^partial/diff/%s/%s/%s$' % ( section_pattern, version_pattern, newer_version_pattern), lt_cache(PartialSectionDiffView.as_view()), name='partial_section_diff_view'), #A section by section paragraph (without chrome) #Example: http://.../partial/sxs/201-2-g/2011-1738 url(r'^partial/sxs/%s/%s$' % (paragraph_pattern, notice_pattern), lt_cache(ParagraphSXSView.as_view()), name='paragraph_sxs_view'), #A definition templated to be displayed in the sidebar (without chrome) #Example: http://.../partial/definition/201-2-g/2011-1738 url(r'^partial/definition/%s/%s$' % (paragraph_pattern, version_pattern), lt_cache(PartialDefinitionView.as_view()), name='partial_definition_view'), #A regulation section without chrome #Example: http://.../partial/201-4/2013-10704 url(r'^partial/%s/%s$' % (section_pattern, version_pattern), lt_cache(PartialSectionView.as_view()), name='partial_section_view'), # Subterp, interpretations of a whole subpart, emptypart or appendices # Example: http://.../partial/201-Subpart-A-Interp/2013-10706 # http://.../partial/201-Subpart-Interp/2013-10706 # http://.../partial/201-Appendices-Interp/2013-10706
# Load just the sidebar # Example: http://.../partial/sidebar/201-2/2013-10704 url(r"^partial/sidebar/%s/%s$" % (paragraph_pattern, version_pattern), SideBarView.as_view(), name="sidebar"), # Load just search results url(r"^partial/search/%s$" % reg_pattern, PartialSearch.as_view(), name="partial_search"), # A diff view of a section (without chrome) url( r"^partial/diff/%s/%s/%s$" % (section_pattern, version_pattern, newer_version_pattern), PartialSectionDiffView.as_view(), name="partial_section_diff_view", ), # A section by section paragraph (without chrome) # Example: http://.../partial/sxs/201-2-g/2011-1738 url( r"^partial/sxs/%s/%s$" % (paragraph_pattern, notice_pattern), ParagraphSXSView.as_view(), name="paragraph_sxs_view", ), # A definition templated to be displayed in the sidebar (without chrome) # Example: http://.../partial/definition/201-2-g/2011-1738 url( r"^partial/definition/%s/%s$" % (paragraph_pattern, version_pattern), PartialDefinitionView.as_view(), name="partial_definition_view", ), # A regulation section without chrome # Example: http://.../partial/201-4/2013-10704 url( r"^partial/%s/%s$" % (section_pattern, version_pattern), PartialSectionView.as_view(), name="partial_section_view",
name='sidebar'), # Load just search results url(r'^partial/search/%s$' % reg_pattern, PartialSearch.as_view(), name='partial_search'), #A diff view of a section (without chrome) url(r'^partial/diff/%s/%s/%s$' % (section_pattern, version_pattern, newer_version_pattern), PartialSectionDiffView.as_view(), name='partial_section_diff_view'), #A section by section paragraph (without chrome) #Example: http://.../partial/sxs/201-2-g/2011-1738 url(r'^partial/sxs/%s/%s$' % (paragraph_pattern, notice_pattern), ParagraphSXSView.as_view(), name='paragraph_sxs_view'), #A definition templated to be displayed in the sidebar (without chrome) #Example: http://.../partial/definition/201-2-g/2011-1738 url(r'^partial/definition/%s/%s$' % (paragraph_pattern, version_pattern), PartialDefinitionView.as_view(), name='partial_definition_view'), #A regulation section without chrome #Example: http://.../partial/201-4/2013-10704 url(r'^partial/%s/%s$' % (section_pattern, version_pattern), PartialSectionView.as_view(), name='partial_section_view'), # Subterp, interpretations of a whole subpart, emptypart or appendices # Example: http://.../partial/201-Subpart-A-Interp/2013-10706 # http://.../partial/201-Subpart-Interp/2013-10706 # http://.../partial/201-Appendices-Interp/2013-10706
def test_further_analyses(self, api_reader): doc1 = { 'publication_date': '2009-04-05', 'fr_volume': 21, 'fr_page': 98989, 'reference': ['doc1', '1212-31'] } doc2 = { 'publication_date': '2010-03-03', 'fr_volume': 22, 'fr_page': 87655, 'reference': ['doc2', '1212-31'] } doc3 = { 'publication_date': '2010-10-12', 'fr_volume': 22, 'fr_page': 90123, 'reference': ['doc3', '1212-31'] } doc4 = { 'publication_date': '2009-03-07', 'fr_volume': 21, 'fr_page': 98888, 'reference': ['doc4', '1212-31-b'] } api_reader.ApiReader.return_value.layer.return_value = { '1212-31': [doc1, doc2, doc3], '1212-31-b': [doc4] } psv = ParagraphSXSView() self.assertEqual(psv.further_analyses('1212-31', 'doc1', 98989, 'v1'), convert_to_python([doc3, doc2])) self.assertEqual(psv.further_analyses('1212-31', 'doc5', 0, 'v1'), convert_to_python([doc3, doc2, doc1])) self.assertEqual(psv.further_analyses('1212-31', 'doc3', 90123, 'v1'), convert_to_python([doc2, doc1])) self.assertEqual( psv.further_analyses('1212-31-b', 'doc3', 90123, 'v1'), convert_to_python([doc4])) self.assertEqual( psv.further_analyses('1212-31-b', 'doc4', 98888, 'v1'), []) self.assertEqual( psv.further_analyses('1212-31-c', 'doc1', 98989, 'v1'), []) # Same notice + label. Different page doc5 = { 'publication_date': '2009-04-05', 'fr_volume': 21, 'fr_page': 10101, 'reference': ['doc1', '1212-31'] } api_reader.ApiReader.return_value.layer.return_value = { '1212-31': [doc1, doc2, doc3, doc5], '1212-31-b': [doc4] } self.assertEqual(psv.further_analyses('1212-31', 'doc1', 98989, 'v1'), convert_to_python([doc5, doc3, doc2])) self.assertEqual(psv.further_analyses('1212-31', 'doc1', 10101, 'v1'), convert_to_python([doc3, doc2, doc1])) self.assertEqual(psv.further_analyses('1212-31', 'doc3', 90123, 'v1'), convert_to_python([doc5, doc2, doc1]))