def test_make_cfr_change_nav(self, fetch_meta, fetch_toc): """Add amendments for two different CFR parts. Verify that the table of contents contains only the changed data. Also validate that changes to subparts do not include a ToC entry""" version_info = {'111': {'left': 'v1', 'right': 'v2'}, '222': {'left': 'vold', 'right': 'vnew'}} fetch_toc.return_value = [ dict(index=['111', '1'], title='§ 111.1 Something'), dict(index=['111', '1', 'a'], title='1 a'), dict(index=['111', '2'], title='§ 111.2 Else Here'), dict(index=['111', '3'], title='Unparsable'), # Realistically we wouldn't have these together, but it makes # mocking these results easier dict(index=['222', '4'], title='Section 4') ] fetch_meta.return_value = dict(cfr_title_number='99', statutory_name='Some name') toc = navigation.make_cfr_change_nav('docdoc', version_info, [ dict(cfr_part='111', instruction='1. inst1', authority='auth1'), # subpart change -- doesn't affect ToC dict(cfr_part='111', instruction='2. inst2', changes=[['111-Subpart-A', []]]), dict(cfr_part='111', instruction='2. inst2', # The second element of each pair would be # non-empty in realistic scenarios changes=[['111-1', []], ['111-3-b', []]]), # only authority change dict(cfr_part='222', instruction='3. inst3', authority='auth2') ]) self.assertEqual(toc, [ navigation.NavItem( url='/preamble/docdoc/cfr_changes/111', title=navigation.Title('Authority', '99 CFR 111', 'Authority'), markup_id='docdoc-cfr-111', category='99 CFR 111', section_id=''), navigation.NavItem( url='/preamble/docdoc/cfr_changes/111-1', title=navigation.Title( '§ 111.1 Something', '§ 111.1', 'Something'), markup_id='docdoc-cfr-111-1', category='99 CFR 111'), navigation.NavItem( url='/preamble/docdoc/cfr_changes/111-3', title=navigation.Title('Unparsable', 'Unparsable'), markup_id='docdoc-cfr-111-3', category='99 CFR 111'), navigation.NavItem( url='/preamble/docdoc/cfr_changes/222', title=navigation.Title('Authority', '99 CFR 222', 'Authority'), markup_id='docdoc-cfr-222', category='99 CFR 222', section_id='') ])
def common_context(doc_number): """All of the "preamble" views share common context, such as preamble data, toc info, etc. This function retrieves that data and returns the results as a dict. This may throw a 404""" preamble, meta, notice = notice_data(doc_number) preamble_toc = navigation.make_preamble_nav(preamble['children']) versions, amendments = merge_cfr_changes(doc_number, notice) cfr_toc = navigation.make_cfr_change_nav(doc_number, versions, amendments) return { 'cfr_change_toc': cfr_toc, 'doc_number': doc_number, 'meta': meta, 'notice': notice, 'preamble': preamble, 'preamble_toc': preamble_toc, }