コード例 #1
0
 def test_preamble_toc(self):
     toc = preamble.make_preamble_toc(self.nodes)
     self.assertEqual(
         toc,
         [
             preamble.PreambleSect(
                 depth=1,
                 title='l1',
                 url='/preamble/doc_id/I',
                 full_id='doc_id-preamble-doc_id-I',
                 children=[
                     preamble.PreambleSect(
                         depth=2,
                         title='l2',
                         url='/preamble/doc_id/I#doc_id-I-A',
                         full_id='doc_id-preamble-doc_id-I-A',
                         children=[],
                     )
                 ]),
             preamble.PreambleSect(depth=1,
                                   title='l2',
                                   url='/preamble/doc_id/II',
                                   full_id='doc_id-preamble-doc_id-II',
                                   children=[]),
         ],
     )
コード例 #2
0
 def test_preamble_toc(self):
     toc = preamble.make_preamble_toc(self.nodes)
     self.assertEqual(
         toc,
         [
             preamble.PreambleSect(
                 depth=1,
                 title='l1',
                 url='/preamble/doc_id/I',
                 full_id='doc_id-preamble-doc_id-I',
                 children=[
                     preamble.PreambleSect(
                         depth=2,
                         title='l2',
                         url='/preamble/doc_id/I#doc_id-I-A',
                         full_id='doc_id-preamble-doc_id-I-A',
                         children=[],
                     )
                 ]
             ),
             preamble.PreambleSect(
                 depth=1,
                 title='l2',
                 url='/preamble/doc_id/II',
                 full_id='doc_id-preamble-doc_id-II',
                 children=[]
             ),
         ],
     )
コード例 #3
0
    def test_navigation(self):
        toc = preamble.make_preamble_toc(self.nodes)

        nav = preamble.section_navigation(toc, [],
                                          full_id='doc_id-preamble-doc_id-I')
        assert_equal(nav['next'].section_id, 'doc_id-preamble-doc_id-II')
        assert_is_none(nav['previous'])

        nav = preamble.section_navigation(toc, [],
                                          full_id='doc_id-preamble-doc_id-II')
        assert_equal(nav['previous'].section_id, 'doc_id-preamble-doc_id-I')
        assert_is_none(nav['next'])
コード例 #4
0
    def test_navigation(self):
        toc = preamble.make_preamble_toc(self.nodes)

        nav = preamble.section_navigation(
            toc, [], full_id='doc_id-preamble-doc_id-I')
        assert_equal(nav['next'].section_id, 'doc_id-preamble-doc_id-II')
        assert_is_none(nav['previous'])

        nav = preamble.section_navigation(
            toc, [], full_id='doc_id-preamble-doc_id-II')
        assert_equal(nav['previous'].section_id, 'doc_id-preamble-doc_id-I')
        assert_is_none(nav['next'])
コード例 #5
0
    def test_get_integration(self, ApiReader, api_reader, CFRChangeToC):
        """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'],
            preamble.make_preamble_toc(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',
        )
コード例 #6
0
    def test_get_integration(self, ApiReader, api_reader, CFRChangeToC):
        """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'],
            preamble.make_preamble_toc(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',
        )
コード例 #7
0
 def test_preamble_toc(self):
     toc = preamble.make_preamble_toc(self.nodes)
     self.assertEqual(
         toc,
         [
             preamble.PreambleSect(
                 depth=1,
                 title='l1',
                 url='/preamble/abc/123#abc-123-I',
                 full_id='abc-preamble-abc-123-I',
                 children=[
                     preamble.PreambleSect(
                         depth=2,
                         title='l2',
                         url='/preamble/abc/123#abc-123-I-A',
                         full_id='abc-preamble-abc-123-I-A',
                         children=[],
                     )
                 ])
         ],
     )
コード例 #8
0
 def test_preamble_toc(self):
     toc = preamble.make_preamble_toc(self.nodes)
     self.assertEqual(
         toc,
         [
             preamble.PreambleSect(
                 depth=1,
                 title='l1',
                 url='/preamble/abc/123#abc-123-I',
                 full_id='abc-preamble-abc-123-I',
                 children=[
                     preamble.PreambleSect(
                         depth=2,
                         title='l2',
                         url='/preamble/abc/123#abc-123-I-A',
                         full_id='abc-preamble-abc-123-I-A',
                         children=[],
                     )
                 ]
             )
         ],
     )
コード例 #9
0
 def test_max_depth(self):
     toc = preamble.make_preamble_toc(self.nodes, max_depth=1)
     self.assertEqual(toc[0].children, [])
コード例 #10
0
 def test_max_depth(self):
     toc = preamble.make_preamble_toc(self.nodes, max_depth=1)
     self.assertEqual(toc[0].children, [])