Example #1
0
    def test_find_simple(self):
        document = Document(document_xml=document_fixture(xml="""
        <section id="section-1">
          <num>1.</num>
          <heading>Tester</heading>
          <paragraph id="section-1.paragraph-0">
            <content>
              <p>Something to do with Act no 22 of 2012.</p>
              <p>And another thing about Act 4 of 1998.</p>
            </content>
          </paragraph>
        </section>"""),
                            language=self.eng)

        expected = Document(document_xml=document_fixture(xml="""
        <section id="section-1">
          <num>1.</num>
          <heading>Tester</heading>
          <paragraph id="section-1.paragraph-0">
            <content>
              <p>Something to do with Act <ref href="/za/act/2012/22">no 22 of 2012</ref>.</p>
              <p>And another thing about Act <ref href="/za/act/1998/4">4 of 1998</ref>.</p>
            </content>
          </paragraph>
        </section>"""),
                            language=self.eng)

        self.finder.find_references_in_document(document)
        root = etree.fromstring(expected.content)
        expected.content = etree.tostring(root,
                                          encoding='utf-8').decode('utf-8')
        self.assertEqual(expected.content, document.content)
Example #2
0
    def test_subpart_without_number(self):
        d = Document()
        d.work = self.work
        d.content = document_fixture(xml="""
        <body>
          <subpart eId="subpart_1">
            <heading>My subpart</heading>
          </subpart>
        </body>
        """)
        d.language = Language.objects.get(language__pk='en')

        toc = d.table_of_contents()
        toc = [t.as_dict() for t in toc]
        self.maxDiff = None
        self.assertEqual([
            {
                'type': 'subpart',
                'component': 'main',
                'subcomponent': 'subpart',
                'title': 'My subpart',
                'heading': 'My subpart',
                'id': 'subpart_1'
            },
        ], toc)
Example #3
0
    def test_preamble_and_friends_in_table_of_contents(self):
        d = Document()
        d.work = self.work
        d.content = document_fixture(xml="""
        <coverpage>
            <content><p>hi</p></content>
        </coverpage>
        <preface>
            <content><p>hi</p></content>
        </preface>
        <preamble>
            <content><p>hi</p></content>
        </preamble>
        <body>
            <content><p>hi</p></content>
        </body>
        <conclusions>
            <content><p>hi></p></content>
        </conclusions>
        """)
        d.language = Language.objects.get(language__pk='en')

        toc = d.table_of_contents()
        toc = [t.as_dict() for t in toc]
        self.maxDiff = None
        self.assertEqual(toc, [
            {'type': 'coverpage', 'component': 'main', 'subcomponent': 'coverpage', 'title': 'Coverpage'},
            {'type': 'preface', 'component': 'main', 'subcomponent': 'preface', 'title': 'Preface'},
            {'type': 'preamble', 'component': 'main', 'subcomponent': 'preamble', 'title': 'Preamble'},
            {'type': 'conclusions', 'component': 'main', 'subcomponent': 'conclusions', 'title': 'Conclusions'},
        ])
Example #4
0
    def test_set_content(self):
        d = Document()
        d.content = document_fixture(u'γνωρίζω')

        assert_equal(d.frbr_uri, '/za/act/1900/1')
        assert_equal(d.country, 'za')
        assert_equal(d.doc.publication_date, date(2005, 7, 24))
Example #5
0
    def test_italics_markup(self):
        document = Document(work=self.work,
                            document_xml=document_fixture(xml="""
        <section id="section-1">
          <num>1.</num>
          <heading>Application of Act</heading>
          <content>
            <p>In the Gazette it says that habeus corpus is XYZ. As per the evidence of person X, Y.</p>
          </content>
        </section>
                """))

        expected = Document(work=self.work,
                            document_xml=document_fixture(xml="""
        <section id="section-1">
          <num>1.</num>
          <heading>Application of Act</heading>
          <content>
            <p>In the <i>Gazette</i> it says that <i>habeus corpus</i> is XYZ. As <i>per</i> the evidence of person X, Y.</p>
          </content>
        </section>
                """))

        self.italics_terms_finder.mark_up_italics_in_document(
            document, self.italics_terms)
        root = etree.fromstring(expected.content)
        expected.content = etree.tostring(root,
                                          encoding='utf-8').decode('utf-8')
        self.assertEqual(expected.content, document.content)
Example #6
0
    def test_get_subcomponent(self):
        d = Document(language=self.eng)
        d.work = self.work
        d.content = document_fixture(xml="""
        <body xmlns="http://www.akomantoso.org/2.0">
          <section id="section-1">
            <num>1.</num>
            <heading>Foo</heading>
            <content>
              <p>hello</p>
            </content>
          </section>
          <chapter id="chapter-2">
            <num>2.</num>
            <heading>The Chapter</heading>
            <content>
              <p>hi</p>
            </content>
          </chapter>
        </body>
        """)

        assert_is_not_none(d.doc.components()['main'])
        elem = d.get_subcomponent('main', 'chapter/2')
        assert_equal(elem.get('id'), "chapter-2")

        elem = d.get_subcomponent('main', 'section/1')
        assert_equal(elem.get('id'), "section-1")

        assert_is_none(d.get_subcomponent('main', 'chapter/99'))
        assert_is_none(d.get_subcomponent('main', 'section/99'))
Example #7
0
    def test_find_simple(self):
        document = Document(work=self.work,
                            document_xml=document_fixture(xml="""
        <section eId="sec_1">
          <num>1.</num>
          <heading>Tester</heading>
          <paragraph eId="sec_1.paragraph-0">
            <content>
              <p>Something to do with GN no 102 of 2012.</p>
              <p>And another thing about SI 4 of 1998.</p>
            </content>
          </paragraph>
        </section>"""),
                            language=self.eng)

        expected = Document(work=self.work,
                            document_xml=document_fixture(xml="""
        <section eId="sec_1">
          <num>1.</num>
          <heading>Tester</heading>
          <paragraph eId="sec_1.paragraph-0">
            <content>
              <p>Something to do with <ref href="/akn/za/act/gn/2012/102">GN no 102 of 2012</ref>.</p>
              <p>And another thing about <ref href="/akn/za/act/si/1998/4">SI 4 of 1998</ref>.</p>
            </content>
          </paragraph>
        </section>"""),
                            language=self.eng)

        self.finder.find_references_in_document(document)
        root = etree.fromstring(expected.content)
        expected.content = etree.tostring(root,
                                          encoding='utf-8').decode('utf-8')
        self.assertEqual(expected.content, document.content)
Example #8
0
    def test_section_of_this(self):
        document = Document(
            work=self.work,
            document_xml=document_fixture(
                xml="""
      <section eId="sec_7">
        <num>7.</num>
        <heading>Active ref heading</heading>
        <content>
          <p>As given in section 26 of this Act, blah.</p>
          <p>As given in section 26 (1) of this Act, blah.</p>
          <p>As given in section 26 (1) of this Proclamation, blah.</p>
          <p>As given in section 26(1)(b)(iii)(dd)(A) of this Act, blah.</p>
          <p>In section 26 of Act 5 of 2012 it says one thing and in section 26 of this Act it says another.</p>
          <p>As <i>given</i> in (we're now in a tail) section 26 of this Act, blah.</p>
        </content>
      </section>
      <section eId="sec_26">
        <num>26.</num>
        <heading>Important heading</heading>
        <content>
          <p>An important provision.</p>
        </content>
      </section>
        """
            ),
            language=self.eng)

        expected = Document(
            work=self.work,
            document_xml=document_fixture(
                xml="""
      <section eId="sec_7">
        <num>7.</num>
        <heading>Active ref heading</heading>
        <content>
          <p>As given in <ref href="#sec_26">section 26</ref> of this Act, blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref> (1) of this Act, blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref> (1) of this Proclamation, blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref>(1)(b)(iii)(dd)(A) of this Act, blah.</p>
          <p>In section 26 of Act 5 of 2012 it says one thing and in <ref href="#sec_26">section 26</ref> of this Act it says another.</p>
          <p>As <i>given</i> in (we're now in a tail) <ref href="#sec_26">section 26</ref> of this Act, blah.</p>
        </content>
      </section>
      <section eId="sec_26">
        <num>26.</num>
        <heading>Important heading</heading>
        <content>
          <p>An important provision.</p>
        </content>
      </section>
        """
            ),
            language=self.eng)

        self.section_refs_finder.find_references_in_document(document)
        root = etree.fromstring(expected.content)
        expected.content = etree.tostring(root, encoding='utf-8').decode('utf-8')
        self.assertEqual(expected.content, document.content)
Example #9
0
    def test_empty_expression_date(self):
        d = Document()
        d.content = document_fixture('test')
        d.expression_date = ''
        assert_equal(d.expression_date, '')

        d.expression_date = None
        assert_equal(d.expression_date, None)
Example #10
0
    def test_find_simple(self):
        za = Country.objects.get(pk=1)
        user1 = User.objects.get(pk=1)
        settings.INDIGO['WORK_PROPERTIES'] = {
            'za': {
                'cap': 'Chapter (cap)',
            }
        }

        work = Work(
            frbr_uri='/akn/za/act/2002/5',
            title='Act 5 of 2002',
            country=za,
            created_by_user=user1,
        )
        work.properties['cap'] = '12'
        work.updated_by_user = user1
        work.save()

        document = Document(
            document_xml=document_fixture(
                xml="""
        <section eId="sec_1">
          <num>1.</num>
          <heading>Tester</heading>
          <paragraph eId="sec_1.paragraph-0">
            <content>
              <p>Something to do with Cap. 12.</p>
            </content>
          </paragraph>
        </section>"""
            ),
            language=self.eng,
            work=work)

        expected = Document(
            document_xml=document_fixture(
                xml="""
        <section eId="sec_1">
          <num>1.</num>
          <heading>Tester</heading>
          <paragraph eId="sec_1.paragraph-0">
            <content>
              <p>Something to do with <ref href="/akn/za/act/2002/5">Cap. 12</ref>.</p>
            </content>
          </paragraph>
        </section>"""
            ),
            language=self.eng,
            work=work)

        self.finder.find_references_in_document(document)
        root = etree.fromstring(expected.content)
        expected.content = etree.tostring(root, encoding='utf-8').decode('utf-8')
        self.assertEqual(expected.content, document.content)
Example #11
0
    def test_table_of_contents_afr(self):
        d = Document()
        d.work = self.work
        d.content = document_fixture(xml="""
        <body xmlns="http://www.akomantoso.org/2.0">
          <section id="section-1">
            <num>1.</num>
            <heading>Foo</heading>
            <content>
              <p>hello</p>
            </content>
          </section>
          <chapter id="chapter-1">
            <num>1.</num>
            <heading>The Chapter</heading>
            <part id="part-A">
              <num>A</num>
              <heading>The Part</heading>
              <section id="section-2">
                <num>2.</num>
                <heading>Other</heading>
                <content>
                  <p>hi</p>
                </content>
              </section>
            </part>
          </chapter>
        </body>
        """)
        d.language = Language.objects.get(language__pk='af')

        toc = d.table_of_contents()
        toc = [t.as_dict() for t in toc]
        self.maxDiff = None
        self.assertEqual(toc, [
            {'id': 'section-1', 'num': '1.', 'type': 'section', 'heading': 'Foo',
                'component': 'main', 'subcomponent': 'section/1', 'title': '1. Foo'},
            {'id': 'chapter-1', 'num': '1.', 'type': 'chapter', 'heading': 'The Chapter',
                'component': 'main', 'subcomponent': 'chapter/1', 'title': 'Hoofstuk 1. – The Chapter', 'children': [
                    {'id': 'part-A', 'num': 'A', 'type': 'part', 'heading': 'The Part',
                     'component': 'main', 'subcomponent': 'chapter/1/part/A', 'title': 'Deel A – The Part', 'children': [
                         {'id': 'section-2', 'num': '2.', 'type': 'section', 'heading': 'Other',
                          'component': 'main', 'subcomponent': 'section/2', 'title': '2. Other'},
                     ]
                     },
                ]},
        ])
Example #12
0
    def test_italics_repeated_terms(self):
        """ Checks that if a word is both an italics term and part of a longer italics term,
        both are marked up appropriately.
        """
        document = Document(work=self.work,
                            document_xml=document_fixture(xml="""
        <section id="section-1">
          <num>1.</num>
          <heading>Notification in Gazette</heading>
          <content>
            <p>In the Government Gazette it says:</p>
            <p>that advertising executives should be ad idem.</p>
            <p>However, ad something else and ad hoc policies</p>
            <p>should be discouraged. The Gazetted text is clear on this</p>
            <p>(in case of doubt check the Gazette).</p>
            <p>Both Gazette and Government Gazette should be italicised.</p>
          </content>
        </section>
                """))

        expected = Document(work=self.work,
                            document_xml=document_fixture(xml="""
        <section id="section-1">
          <num>1.</num>
          <heading>Notification in <i>Gazette</i></heading>
          <content>
            <p>In the <i>Government Gazette</i> it says:</p>
            <p>that advertising executives should be <i>ad idem</i>.</p>
            <p>However, <i>ad</i> something else and <i>ad hoc</i> policies</p>
            <p>should be discouraged. The Gazetted text is clear on this</p>
            <p>(in case of doubt check the <i>Gazette</i>).</p>
            <p>Both <i>Gazette</i> and <i>Government Gazette</i> should be italicised.</p>
          </content>
        </section>
                """))

        self.italics_terms_finder.mark_up_italics_in_document(
            document, self.italics_terms)
        root = etree.fromstring(expected.content)
        expected.content = etree.tostring(root,
                                          encoding='utf-8').decode('utf-8')
        self.assertEqual(expected.content, document.content)
Example #13
0
    def test_section_edge(self):
        document = Document(work=self.work,
                            document_xml=document_fixture(xml="""
      <section eId="sec_1">
        <num>1.</num>
        <heading>Unimportant heading</heading>
        <content>
          <p>An unimportant provision.</p>
        </content>
      </section>
      <section eId="sec_2">
        <num>2.</num>
        <heading>Unimportant heading</heading>
        <content>
          <p>An unimportant provision.</p>
        </content>
      </section>
      <section eId="sec_3">
        <num>3.</num>
        <heading>Unimportant heading</heading>
        <content>
          <p>An unimportant provision.</p>
        </content>
      </section>
      <section eId="sec_4">
        <num>4.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_5">
        <num>5.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_6">
        <num>6.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_7">
        <num>7.</num>
        <heading>Active ref heading</heading>
        <content>
          <p>As given in section 26(1), blah.</p>
          <p>As given in section 26 (1), blah.</p>
          <p>As given in section 26(1), (2) and (3), blah.</p>
          <p>As given in section 26 (1), (2) and (3), blah.</p>
          <p>As given in sections 26(1), (2) and (3), blah.</p>
          <p>As given in sections 26 (1), (2) and (3), blah.</p>
          <p>As given in section 26 (2) and (3), blah.</p>
          <p>As given in section 26(2) and (3), blah.</p>
          <p>As given in sections 26 (2) and (3), blah.</p>
          <p>As given in sections 26(2) and (3), blah.</p>
          <p>A person who contravenes sections 4(1), (2) and (3), 6(3) and 10(1) and (2) is guilty of an offence.</p>
          <p>Subject to sections 1(4) and (5) and 4(6), no person is guilty of an offence.</p>
          <p>A person who contravenes sections 4(1) and (2), 6(3), 10(1) and (2), 11(1), 12(1), 19(1), 19(3), 20(1), 20(2), 21(1), 22(1), 24(1), 25(3), (4) , (5) and (6) , 26(1), (2), (3) and (5), 28(1), (2) and (3) is guilty of an offence.</p>
        </content>
      </section>
      <section eId="sec_10">
        <num>10.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_11">
        <num>11.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_12">
        <num>12.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_19">
        <num>19.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_20">
        <num>20.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_21">
        <num>21.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_22">
        <num>22.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_24">
        <num>24.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_25">
        <num>25.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_26">
        <num>26.</num>
        <heading>Important heading</heading>
        <content>
          <p>An important provision.</p>
        </content>
      </section>
      <section eId="sec_28">
        <num>28.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_30">
        <num>30.</num>
        <heading>Less important</heading>
        <content>
          <p>Meh.</p>
        </content>
      </section>
      <section eId="sec_31">
        <num>31.</num>
        <heading>More important</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
        """),
                            language=self.eng)

        expected = Document(work=self.work,
                            document_xml=document_fixture(xml="""
      <section eId="sec_1">
        <num>1.</num>
        <heading>Unimportant heading</heading>
        <content>
          <p>An unimportant provision.</p>
        </content>
      </section>
      <section eId="sec_2">
        <num>2.</num>
        <heading>Unimportant heading</heading>
        <content>
          <p>An unimportant provision.</p>
        </content>
      </section>
      <section eId="sec_3">
        <num>3.</num>
        <heading>Unimportant heading</heading>
        <content>
          <p>An unimportant provision.</p>
        </content>
      </section>
      <section eId="sec_4">
        <num>4.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_5">
        <num>5.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_6">
        <num>6.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_7">
        <num>7.</num>
        <heading>Active ref heading</heading>
        <content>
          <p>As given in <ref href="#sec_26">section 26</ref>(1), blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref> (1), blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref>(1), (2) and (3), blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref> (1), (2) and (3), blah.</p>
          <p>As given in <ref href="#sec_26">sections 26</ref>(1), (2) and (3), blah.</p>
          <p>As given in <ref href="#sec_26">sections 26</ref> (1), (2) and (3), blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref> (2) and (3), blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref>(2) and (3), blah.</p>
          <p>As given in <ref href="#sec_26">sections 26</ref> (2) and (3), blah.</p>
          <p>As given in <ref href="#sec_26">sections 26</ref>(2) and (3), blah.</p>
          <p>A person who contravenes sections <ref href="#sec_4">4</ref>(1), (2) and (3), <ref href="#sec_6">6</ref>(3) and <ref href="#sec_10">10</ref>(1) and (2) is guilty of an offence.</p>
          <p>Subject to sections <ref href="#sec_1">1</ref>(4) and (5) and <ref href="#sec_4">4</ref>(6), no person is guilty of an offence.</p>
          <p>A person who contravenes sections <ref href="#sec_4">4</ref>(1) and (2), <ref href="#sec_6">6</ref>(3), <ref href="#sec_10">10</ref>(1) and (2), <ref href="#sec_11">11</ref>(1), <ref href="#sec_12">12</ref>(1), <ref href="#sec_19">19</ref>(1), <ref href="#sec_19">19</ref>(3), <ref href="#sec_20">20</ref>(1), <ref href="#sec_20">20</ref>(2), <ref href="#sec_21">21</ref>(1), <ref href="#sec_22">22</ref>(1), <ref href="#sec_24">24</ref>(1), <ref href="#sec_25">25</ref>(3), (4) , (5) and (6) , <ref href="#sec_26">26</ref>(1), (2), (3) and (5), <ref href="#sec_28">28</ref>(1), (2) and (3) is guilty of an offence.</p>
        </content>
      </section>
      <section eId="sec_10">
        <num>10.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_11">
        <num>11.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_12">
        <num>12.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_19">
        <num>19.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_20">
        <num>20.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_21">
        <num>21.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_22">
        <num>22.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_24">
        <num>24.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_25">
        <num>25.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_26">
        <num>26.</num>
        <heading>Important heading</heading>
        <content>
          <p>An important provision.</p>
        </content>
      </section>
      <section eId="sec_28">
        <num>28.</num>
        <heading>Unimportant</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
      <section eId="sec_30">
        <num>30.</num>
        <heading>Less important</heading>
        <content>
          <p>Meh.</p>
        </content>
      </section>
      <section eId="sec_31">
        <num>31.</num>
        <heading>More important</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
        """),
                            language=self.eng)

        self.section_refs_finder.find_references_in_document(document)
        root = etree.fromstring(expected.content)
        expected.content = etree.tostring(root,
                                          encoding='utf-8').decode('utf-8')
        self.assertEqual(expected.content, document.content)
Example #14
0
    def test_section_basic(self):
        document = Document(work=self.work,
                            document_xml=document_fixture(xml="""
      <section eId="sec_7">
        <num>7.</num>
        <heading>Active ref heading</heading>
        <content>
          <p>As given in section 26, blah.</p>
          <p>As given in section 26(b), blah.</p>
          <p>As given in section 26(1)(b)(iii), blah.</p>
          <p>As given in section 26(1)(b)(iii)(bb), blah.</p>
          <p>As given in section 26(1)(b)(iii)(dd)(A), blah.</p>
          <p>As given in section 26B, blah.</p>
          <p>As given in section 26 and section 31, blah.</p>
          <p>As <i>given</i> in (we're now in a tail) section 26, blah.</p>
        </content>
      </section>
      <section eId="sec_26">
        <num>26.</num>
        <heading>Important heading</heading>
        <content>
          <p>An important provision.</p>
        </content>
      </section>
      <section eId="sec_26B">
        <num>26B.</num>
        <heading>Another important heading</heading>
        <content>
          <p>Another important provision.</p>
        </content>
      </section>
      <section eId="sec_31">
        <num>31.</num>
        <heading>More important</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
        """),
                            language=self.eng)

        expected = Document(work=self.work,
                            document_xml=document_fixture(xml="""
      <section eId="sec_7">
        <num>7.</num>
        <heading>Active ref heading</heading>
        <content>
          <p>As given in <ref href="#sec_26">section 26</ref>, blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref>(b), blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref>(1)(b)(iii), blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref>(1)(b)(iii)(bb), blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref>(1)(b)(iii)(dd)(A), blah.</p>
          <p>As given in <ref href="#sec_26B">section 26B</ref>, blah.</p>
          <p>As given in <ref href="#sec_26">section 26</ref> and <ref href="#sec_31">section 31</ref>, blah.</p>
          <p>As <i>given</i> in (we're now in a tail) <ref href="#sec_26">section 26</ref>, blah.</p>
        </content>
      </section>
      <section eId="sec_26">
        <num>26.</num>
        <heading>Important heading</heading>
        <content>
          <p>An important provision.</p>
        </content>
      </section>
      <section eId="sec_26B">
        <num>26B.</num>
        <heading>Another important heading</heading>
        <content>
          <p>Another important provision.</p>
        </content>
      </section>
      <section eId="sec_31">
        <num>31.</num>
        <heading>More important</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
        """),
                            language=self.eng)

        self.section_refs_finder.find_references_in_document(document)
        root = etree.fromstring(expected.content)
        expected.content = etree.tostring(root,
                                          encoding='utf-8').decode('utf-8')
        self.assertEqual(expected.content, document.content)
Example #15
0
    def test_section_multiple(self):
        document = Document(work=self.work,
                            document_xml=document_fixture(xml="""
      <section eId="sec_7">
        <num>7.</num>
        <heading>Active ref heading</heading>
        <content>
          <p>As given in sections 26 and 31, blah.</p>
          <p>As given in sections 26, 26B, 30 and 31, blah.</p>
          <p>As given in section 26 or 31, blah.</p>
          <p>As given in sections 26 or 31, blah.</p>
          <p>As given in sections 26, 30(1) and 31, blah.</p>
          <p>As given in sections 26, 30 (1) and 31, blah.</p>
          <p>As given in sections 26(b), 30(1) or 31, blah.</p>
          <p>As given in section 26 (b), 30 (1) or 31, blah.</p>
          <p>As <i>given</i> in (we're now in a tail) section 26, 30 and 31.</p>
          <p>under sections 26,30 or 31 of this Act, blah.</p>
          <p>As given in sections 26, 30, and 31 of this Act, blah.</p>
        </content>
      </section>
      <section eId="sec_26">
        <num>26.</num>
        <heading>Important heading</heading>
        <content>
          <p>An important provision.</p>
        </content>
      </section>
      <section eId="sec_26B">
        <num>26B.</num>
        <heading>Another important heading</heading>
        <content>
          <p>Another important provision.</p>
        </content>
      </section>
      <section eId="sec_30">
        <num>30.</num>
        <heading>Less important</heading>
        <content>
          <p>Meh.</p>
        </content>
      </section>
      <section eId="sec_31">
        <num>31.</num>
        <heading>More important</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
        """),
                            language=self.eng)

        expected = Document(work=self.work,
                            document_xml=document_fixture(xml="""
      <section eId="sec_7">
        <num>7.</num>
        <heading>Active ref heading</heading>
        <content>
          <p>As given in sections <ref href="#sec_26">26</ref> and <ref href="#sec_31">31</ref>, blah.</p>
          <p>As given in sections <ref href="#sec_26">26</ref>, <ref href="#sec_26B">26B</ref>, <ref href="#sec_30">30</ref> and <ref href="#sec_31">31</ref>, blah.</p>
          <p>As given in section <ref href="#sec_26">26</ref> or <ref href="#sec_31">31</ref>, blah.</p>
          <p>As given in sections <ref href="#sec_26">26</ref> or <ref href="#sec_31">31</ref>, blah.</p>
          <p>As given in sections <ref href="#sec_26">26</ref>, <ref href="#sec_30">30</ref>(1) and <ref href="#sec_31">31</ref>, blah.</p>
          <p>As given in sections <ref href="#sec_26">26</ref>, <ref href="#sec_30">30</ref> (1) and <ref href="#sec_31">31</ref>, blah.</p>
          <p>As given in sections <ref href="#sec_26">26</ref>(b), <ref href="#sec_30">30</ref>(1) or <ref href="#sec_31">31</ref>, blah.</p>
          <p>As given in section <ref href="#sec_26">26</ref> (b), <ref href="#sec_30">30</ref> (1) or <ref href="#sec_31">31</ref>, blah.</p>
          <p>As <i>given</i> in (we're now in a tail) section <ref href="#sec_26">26</ref>, <ref href="#sec_30">30</ref> and <ref href="#sec_31">31</ref>.</p>
          <p>under sections <ref href="#sec_26">26</ref>,<ref href="#sec_30">30</ref> or <ref href="#sec_31">31</ref> of this Act, blah.</p>
          <p>As given in sections <ref href="#sec_26">26</ref>, <ref href="#sec_30">30</ref>, and <ref href="#sec_31">31</ref> of this Act, blah.</p>
        </content>
      </section>
      <section eId="sec_26">
        <num>26.</num>
        <heading>Important heading</heading>
        <content>
          <p>An important provision.</p>
        </content>
      </section>
      <section eId="sec_26B">
        <num>26B.</num>
        <heading>Another important heading</heading>
        <content>
          <p>Another important provision.</p>
        </content>
      </section>
      <section eId="sec_30">
        <num>30.</num>
        <heading>Less important</heading>
        <content>
          <p>Meh.</p>
        </content>
      </section>
      <section eId="sec_31">
        <num>31.</num>
        <heading>More important</heading>
        <content>
          <p>Hi!</p>
        </content>
      </section>
        """),
                            language=self.eng)

        self.section_refs_finder.find_references_in_document(document)
        root = etree.fromstring(expected.content)
        expected.content = etree.tostring(root,
                                          encoding='utf-8').decode('utf-8')
        self.assertEqual(expected.content, document.content)
Example #16
0
    def test_component_table_of_contents(self):
        d = Document()
        d.work = self.work
        d.content = """<akomaNtoso xmlns="http://docs.oasis-open.org/legaldocml/ns/akn/3.0">
  <act contains="singleVersion">
    <meta>
      <identification source="#openbylaws">
        <FRBRWork>
          <FRBRthis value="/za/by-law/cape-town/2002/community-fire-safety/!main"/>
          <FRBRuri value="/za/by-law/cape-town/2002/community-fire-safety"/>
          <FRBRalias value="Community Fire Safety By-law"/>
          <FRBRdate date="2002-02-28" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRcountry value="za"/>
        </FRBRWork>
        <FRBRExpression>
          <FRBRthis value="/za/by-law/cape-town/2002/community-fire-safety/main/eng@"/>
          <FRBRuri value="/za/by-law/cape-town/2002/community-fire-safety/eng@"/>
          <FRBRdate date="2002-02-28" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRlanguage language="eng"/>
        </FRBRExpression>
        <FRBRManifestation>
          <FRBRthis value="/za/by-law/cape-town/2002/community-fire-safety/main/eng@"/>
          <FRBRuri value="/za/by-law/cape-town/2002/community-fire-safety/eng@"/>
          <FRBRdate date="2014-01-14" name="Generation"/>
          <FRBRauthor href="#openbylaws" as="#author"/>
        </FRBRManifestation>
      </identification>
    </meta>
    <body></body>
    <attachments>
      <attachment eId="att_1">
        <heading>A Title</heading>
        <doc name="schedule">
          <meta>
            <identification source="#slaw">
              <FRBRWork>
                <FRBRthis value="/za/act/1980/01/!schedule1"/>
                <FRBRuri value="/za/act/1980/01"/>
                <FRBRalias value="A Title"/>
                <FRBRdate date="1980-01-01" name="Generation"/>
                <FRBRauthor href="#council" as="#author"/>
                <FRBRcountry value="za"/>
              </FRBRWork>
              <FRBRExpression>
                <FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
                <FRBRuri value="/za/act/1980/01/eng@"/>
                <FRBRdate date="1980-01-01" name="Generation"/>
                <FRBRauthor href="#council" as="#author"/>
                <FRBRlanguage language="eng"/>
              </FRBRExpression>
              <FRBRManifestation>
                <FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
                <FRBRuri value="/za/act/1980/01/eng@"/>
                <FRBRdate date="2015-04-22" name="Generation"/>
                <FRBRauthor href="#slaw" as="#author"/>
              </FRBRManifestation>
            </identification>
          </meta>
          <mainBody>
            <section eId="sec_1">
              <content>
                <p>1. Foo</p>
                <p>2. Bar</p>
              </content>
            </section>
          </mainBody>
        </doc>
      </attachment>
      <attachment eId="att_2">
        <heading>Schedule 2</heading>
        <doc name="schedule">
          <meta>
            <identification source="#slaw">
              <FRBRWork>
                <FRBRthis value="/za/act/1980/01/!schedule2"/>
                <FRBRuri value="/za/act/1980/01"/>
                <FRBRdate date="1980-01-01" name="Generation"/>
                <FRBRauthor href="#council" as="#author"/>
                <FRBRcountry value="za"/>
              </FRBRWork>
              <FRBRExpression>
                <FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
                <FRBRuri value="/za/act/1980/01/eng@"/>
                <FRBRdate date="1980-01-01" name="Generation"/>
                <FRBRauthor href="#council" as="#author"/>
                <FRBRlanguage language="eng"/>
              </FRBRExpression>
              <FRBRManifestation>
                <FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
                <FRBRuri value="/za/act/1980/01/eng@"/>
                <FRBRdate date="2015-04-22" name="Generation"/>
                <FRBRauthor href="#slaw" as="#author"/>
              </FRBRManifestation>
            </identification>
          </meta>
          <mainBody>
            <section eId="sec_1">
              <content>
                <p>Baz</p>
                <p>Boom</p>
              </content>
            </section>
          </mainBody>
        </doc>
      </attachment>
    </attachments>
  </act>
</akomaNtoso>
        """
        d.language = Language.objects.get(language__pk='en')
        toc = d.table_of_contents()
        toc = [t.as_dict() for t in toc]
        self.maxDiff = None
        self.assertEqual([{
            'component':
            'schedule1',
            'type':
            'attachment',
            'subcomponent':
            None,
            'id':
            'att_1',
            'heading':
            'A Title',
            'title':
            'A Title',
            'children': [{
                'component': 'schedule1',
                'type': 'section',
                'id': 'sec_1',
                'subcomponent': 'section',
                'title': 'Section',
            }]
        }, {
            'component':
            'schedule2',
            'type':
            'attachment',
            'subcomponent':
            None,
            'id':
            'att_2',
            'heading':
            'Schedule 2',
            'title':
            'Schedule 2',
            'children': [{
                'component': 'schedule2',
                'type': 'section',
                'id': 'sec_1',
                'subcomponent': 'section',
                'title': 'Section'
            }]
        }], toc)
Example #17
0
 def test_expression_date(self):
     d = Document()
     d.content = document_fixture('test')
     d.expression_date = date(2014, 1, 1)
     assert_equal(d.expression_date, date(2014, 1, 1))
Example #18
0
    def test_component_table_of_contents(self):
        d = Document()
        d.work = self.work
        d.content = """<akomaNtoso xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.akomantoso.org/2.0" xsi:schemaLocation="http://www.akomantoso.org/2.0 akomantoso20.xsd">
  <act contains="singleVersion">
    <meta>
      <identification source="#openbylaws">
        <FRBRWork>
          <FRBRthis value="/za/by-law/cape-town/2002/community-fire-safety/main"/>
          <FRBRuri value="/za/by-law/cape-town/2002/community-fire-safety"/>
          <FRBRalias value="Community Fire Safety By-law"/>
          <FRBRdate date="2002-02-28" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRcountry value="za"/>
        </FRBRWork>
        <FRBRExpression>
          <FRBRthis value="/za/by-law/cape-town/2002/community-fire-safety/main/eng@"/>
          <FRBRuri value="/za/by-law/cape-town/2002/community-fire-safety/eng@"/>
          <FRBRdate date="2002-02-28" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRlanguage language="eng"/>
        </FRBRExpression>
        <FRBRManifestation>
          <FRBRthis value="/za/by-law/cape-town/2002/community-fire-safety/main/eng@"/>
          <FRBRuri value="/za/by-law/cape-town/2002/community-fire-safety/eng@"/>
          <FRBRdate date="2014-01-14" name="Generation"/>
          <FRBRauthor href="#openbylaws" as="#author"/>
        </FRBRManifestation>
      </identification>
    </meta>
    <body></body>
  </act>
  <components>
    <component id="component-1">
      <doc name="schedule1">
        <meta>
          <identification source="#slaw">
            <FRBRWork>
              <FRBRthis value="/za/act/1980/01/schedule1"/>
              <FRBRuri value="/za/act/1980/01"/>
              <FRBRalias value="A Title"/>
              <FRBRdate date="1980-01-01" name="Generation"/>
              <FRBRauthor href="#council" as="#author"/>
              <FRBRcountry value="za"/>
            </FRBRWork>
            <FRBRExpression>
              <FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
              <FRBRuri value="/za/act/1980/01/eng@"/>
              <FRBRdate date="1980-01-01" name="Generation"/>
              <FRBRauthor href="#council" as="#author"/>
              <FRBRlanguage language="eng"/>
            </FRBRExpression>
            <FRBRManifestation>
              <FRBRthis value="/za/act/1980/01/eng@/schedule1"/>
              <FRBRuri value="/za/act/1980/01/eng@"/>
              <FRBRdate date="2015-04-22" name="Generation"/>
              <FRBRauthor href="#slaw" as="#author"/>
            </FRBRManifestation>
          </identification>
        </meta>
        <mainBody>
          <section id="schedule-1.section-0">
            <content>
              <p>1. Foo</p>
              <p>2. Bar</p>
            </content>
          </section>
        </mainBody>
      </doc>
    </component>
    <component id="component-2">
      <doc name="schedule2">
        <meta>
          <identification source="#slaw">
            <FRBRWork>
              <FRBRthis value="/za/act/1980/01/schedule2"/>
              <FRBRuri value="/za/act/1980/01"/>
              <FRBRdate date="1980-01-01" name="Generation"/>
              <FRBRauthor href="#council" as="#author"/>
              <FRBRcountry value="za"/>
            </FRBRWork>
            <FRBRExpression>
              <FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
              <FRBRuri value="/za/act/1980/01/eng@"/>
              <FRBRdate date="1980-01-01" name="Generation"/>
              <FRBRauthor href="#council" as="#author"/>
              <FRBRlanguage language="eng"/>
            </FRBRExpression>
            <FRBRManifestation>
              <FRBRthis value="/za/act/1980/01/eng@/schedule2"/>
              <FRBRuri value="/za/act/1980/01/eng@"/>
              <FRBRdate date="2015-04-22" name="Generation"/>
              <FRBRauthor href="#slaw" as="#author"/>
            </FRBRManifestation>
          </identification>
        </meta>
        <mainBody>
          <section id="schedule-2.section-0">
            <content>
              <p>Baz</p>
              <p>Boom</p>
            </content>
          </section>
        </mainBody>
      </doc>
    </component>
  </components>
</akomaNtoso>
        """
        d.language = Language.objects.get(language__pk='en')
        toc = d.table_of_contents()
        toc = [t.as_dict() for t in toc]
        self.maxDiff = None
        self.assertEqual([
            {
                'component':
                'schedule1',
                'type':
                'doc',
                'subcomponent':
                None,
                'heading':
                'A Title',
                'title':
                'A Title',
                'children': [{
                    'component': 'schedule1',
                    'type': 'section',
                    'id': 'schedule-1.section-0',
                    'subcomponent': 'section',
                    'title': 'Section'
                }]
            },
            {
                'component':
                'schedule2',
                'type':
                'doc',
                'subcomponent':
                None,
                'heading':
                'Schedule 2',
                'title':
                'Schedule 2',
                'children': [{
                    'component': 'schedule2',
                    'type': 'section',
                    'id': 'schedule-2.section-0',
                    'subcomponent': 'section',
                    'title': 'Section'
                }]
            },
        ], toc)