def test_toc_subpart_reserved(self):
     layer = {'1001-Subpart-A': [{'title': '1001.1 - Content',
                                  'index': ['1001', '1']},
                                 {'title': '1001.2 - Other',
                                  'index': ['1001', '2']}]}
     data = {'title': u'[Reserved]', 'index': ['1001', 'Subpart', 'B']}
     result = toc.toc_subpart(data, [], layer)
     self.assertEqual('Subpart B', result['label'])
     self.assertEqual('[Reserved]', result['sub_label'])
     self.assertEqual(['1001', 'Subpart', 'B'], result['index'])
     self.assertEqual('1001-Subpart-B', result['section_id'])
     self.assertTrue(result.get('is_subpart'))
     self.assertEqual(0, len(result['sub_toc']))
 def test_toc_subpart_reserved(self):
     layer = {
         '1001-Subpart-A': [{
             'title': '1001.1 - Content',
             'index': ['1001', '1']
         }, {
             'title': '1001.2 - Other',
             'index': ['1001', '2']
         }]
     }
     data = {'title': u'[Reserved]', 'index': ['1001', 'Subpart', 'B']}
     result = toc.toc_subpart(data, [], layer)
     self.assertEqual('Subpart B', result['label'])
     self.assertEqual('[Reserved]', result['sub_label'])
     self.assertEqual(['1001', 'Subpart', 'B'], result['index'])
     self.assertEqual('1001-Subpart-B', result['section_id'])
     self.assertTrue(result.get('is_subpart'))
     self.assertEqual(0, len(result['sub_toc']))
    def test_toc_subpart_with_nondigits(self):
        layer = {'1001-Subpart-A': [{'title': u'§ 1001.1a - Content',
                                     'index': ['1001', '1a']},
                                    {'title': u'§ 1001.2 - Other',
                                     'index': ['1001', '2']}]}
        data = {'title': u'General', 'index': ['1001', 'Subpart', 'A']}
        result = toc.toc_subpart(data, [], layer)
        self.assertEqual('Subpart A', result['label'])
        self.assertEqual('General', result['sub_label'])
        self.assertEqual(['1001', 'Subpart', 'A'], result['index'])
        self.assertEqual('1001-Subpart-A', result['section_id'])
        self.assertTrue(result.get('is_subpart'))
        self.assertEqual(2, len(result['sub_toc']))

        s1, s2 = result['sub_toc']
        self.assertEqual('Content', s1['sub_label'])
        self.assertEqual(['1001', '1a'], s1['index'])
        self.assertEqual('Other', s2['sub_label'])
        self.assertEqual(['1001', '2'], s2['index'])
Example #4
0
    def apply_layer(self, text_index):
        if text_index in self.layer:
            layer_elements = self.layer[text_index]

            toc_list = []
            for data in layer_elements:
                if 'Subpart' in data['index']:
                    toc_list.append(toc_subpart(data, toc_list, self.layer))
                elif 'Interp' in data['index']:
                    toc_list.append(toc_interp(data, toc_list, self.layer))
                else:
                    toc_list.append(toc_sect_appendix(data, toc_list))

            for el in toc_list:
                el['url'] = self.section_url.fetch(el['index'], self.version,
                                                   self.sectional)
                for sub in el.get('sub_toc', []):
                    sub['url'] = self.section_url.fetch(
                        sub['index'], self.version, self.sectional)
            return ('TOC', toc_list)
Example #5
0
    def apply_layer(self, text_index):
        if text_index in self.layer:
            layer_elements = self.layer[text_index]

            toc_list = []
            for data in layer_elements:
                if 'Subpart' in data['index']:
                    toc_list.append(toc_subpart(data, toc_list, self.layer))
                elif 'Interp' in data['index']:
                    toc_list.append(toc_interp(data, toc_list, self.layer))
                else:
                    toc_list.append(toc_sect_appendix(data, toc_list))

            for el in toc_list:
                el['url'] = self.section_url.fetch(
                    el['index'], self.version, self.sectional)
                for sub in el.get('sub_toc', []):
                    sub['url'] = self.section_url.fetch(
                        sub['index'], self.version, self.sectional)
            return ('TOC', toc_list)
Example #6
0
    def attach_metadata(self, node):
        text_index = node['label_id']
        if text_index in self.layer:
            layer_elements = self.layer[text_index]

            toc_list = []
            for data in layer_elements:
                if 'Subpart' in data['index']:
                    toc_list.append(toc_subpart(data, toc_list, self.layer))
                elif 'Interp' in data['index']:
                    toc_list.append(toc_interp(data, toc_list, self.layer))
                else:
                    toc_list.append(toc_sect_appendix(data, toc_list))

            for el in toc_list:
                el['url'] = self.section_url.fetch(
                    el['index'], self.version, self.sectional)
                for sub in el.get('sub_toc', []):
                    sub['url'] = self.section_url.fetch(
                        sub['index'], self.version, self.sectional)
            node['TOC'] = toc_list
    def test_toc_subpart(self):
        layer = {
            '1001-Subpart-A': [{
                'title': '1001.1 - Content',
                'index': ['1001', '1']
            }, {
                'title': '1001.2 - Other',
                'index': ['1001', '2']
            }]
        }
        data = {'title': u'General', 'index': ['1001', 'Subpart', 'A']}
        result = toc.toc_subpart(data, [], layer)
        self.assertEqual('Subpart A', result['label'])
        self.assertEqual('General', result['sub_label'])
        self.assertEqual(['1001', 'Subpart', 'A'], result['index'])
        self.assertEqual('1001-Subpart-A', result['section_id'])
        self.assertTrue(result.get('is_subpart'))
        self.assertEqual(2, len(result['sub_toc']))

        s1, s2 = result['sub_toc']
        self.assertEqual('Content', s1['sub_label'])
        self.assertEqual(['1001', '1'], s1['index'])
        self.assertEqual('Other', s2['sub_label'])
        self.assertEqual(['1001', '2'], s2['index'])