def test_footer(self): toc = navigation.make_preamble_nav(self.nodes) nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-I') assert_equal(nav['next'].section_id, 'doc_id-preamble-doc_id-II') assert_is_none(nav['previous']) nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-II') assert_equal(nav['previous'].section_id, 'doc_id-preamble-doc_id-I') assert_is_none(nav['next'])
def test_footer(self): toc = navigation.make_preamble_nav(self.nodes) nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-I') assert nav['next'].section_id == 'doc_id-preamble-doc_id-II' assert nav['previous'] is None nav = navigation.footer(toc, [], 'doc_id-preamble-doc_id-II') assert nav['previous'].section_id == 'doc_id-preamble-doc_id-I' assert nav['next'] is None
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, }
def test_preamble_toc(self): toc = navigation.make_preamble_nav(self.nodes) self.assertEqual(toc, [ navigation.NavItem( url='/preamble/doc_id/I', title=navigation.Title('one', 'I', 'one'), markup_id='doc_id-preamble-doc_id-I', children=[navigation.NavItem( url='/preamble/doc_id/I#doc_id-I-A', title=navigation.Title('two', 'A', 'two'), markup_id='doc_id-preamble-doc_id-I-A', )] ), navigation.NavItem( url='/preamble/doc_id/II', title=navigation.Title('three', 'II', 'three'), markup_id='doc_id-preamble-doc_id-II', ) ])
def test_get_integration(self, ApiReader, api_reader, CFRChangeBuilder): """Verify that the contexts are built correctly before being sent to the template. AJAX/partial=true requests should only get the inner context (i.e. no UI-related context)""" ApiReader.return_value.preamble.return_value = self._mock_preamble api_reader.ApiReader.return_value.layer.return_value = { '1-c-x': ['something'] } view = preamble.PreambleView.as_view() path = '/preamble/1/c/x?layers=meta' response = view(RequestFactory().get(path), paragraphs='1/c/x') self.assertEqual( response.context_data['sub_context']['node']['text'], '4') self.assertEqual( response.context_data['sub_context']['node']['children'], []) # layer data is present self.assertEqual( response.context_data['sub_context']['node']['meta'], 'something') self.assertEqual( response.context_data['preamble_toc'], make_preamble_nav(self._mock_preamble['children']), ) self.assertNotIn('node', response.context_data) response = view(RequestFactory().get(path + '&partial=true'), paragraphs='1/c/x') self.assertIn('sub_context', response.context_data) self.assertEqual( response.context_data['sub_context']['node']['text'], '4', ) request = RequestFactory().get( path, HTTP_X_REQUESTED_WITH='XMLHttpRequest') response = view(request, paragraphs='1/c/x') self.assertIn('sub_context', response.context_data) self.assertEqual( response.context_data['sub_context']['node']['text'], '4', )
def test_max_depth(self): toc = navigation.make_preamble_nav(self.nodes, max_depth=1) self.assertEqual(toc[0].children, [])