Esempio n. 1
0
    def test_preamble_and_friends_in_table_of_contents(self):
        a = Act(act_fixture("""
        <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>
        """))

        toc = a.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'},
            ])
Esempio n. 2
0
    def test_publication_date(self):
        a = Act()
        assert_is_none(a.publication_date)

        a.publication_date = '2012-01-02'
        assert_equal(datestring(a.publication_date), '2012-01-02')
        assert_is_instance(a.publication_date, date)
Esempio n. 3
0
    def test_set_repeal(self):
        a = Act()
        a.body_xml = """
        <body xmlns="http://www.akomantoso.org/2.0"/>
        """

        a.repeal = RepealEvent(date='2012-02-01', repealing_uri='/za/act/1980/10', repealing_title='Foo')

        assert_equal(a.to_xml(), """<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="originalVersion">
    <meta>
      <identification source="#cobalt">
        <FRBRWork>
          <FRBRthis value="/za/act/1900/1/main"/>
          <FRBRuri value="/za/act/1900/1"/>
          <FRBRalias value="Untitled"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRcountry value="za"/>
        </FRBRWork>
        <FRBRExpression>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRlanguage language="eng"/>
        </FRBRExpression>
        <FRBRManifestation>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
        </FRBRManifestation>
      </identification>
      <lifecycle source="#cobalt">
        <eventRef id="repeal-2012-02-01" date="2012-02-01" type="repeal" source="#repeal-source"/>
      </lifecycle>
      <references>
        <TLCOrganization id="cobalt" href="https://github.com/Code4SA/cobalt" showAs="cobalt"/>
        <passiveRef id="repeal-source" href="/za/act/1980/10" showAs="Foo"/>
      </references>
    </meta>
    <body/>
  </act>
</akomaNtoso>
""")

        assert_equal(a.repeal.repealing_uri, '/za/act/1980/10')
        assert_equal(a.repeal.repealing_title, 'Foo')
        assert_equal(datestring(a.repeal.date), '2012-02-01')

        # check that clearing it works
        a.repeal = None
        assert_is_none(a.repeal)
Esempio n. 4
0
def randomise_uris(apps, schema_editor):
    # randomise the FRBR URIs that are the old-style generic "/za/act/1980/01" URIs.
    Document = apps.get_model("indigo_api", "Document")
    for doc in Document.objects.filter(frbr_uri='/za/act/1980/01'):
        uri = random_frbr_uri()
        uri.date = str(doc.created_at.year)

        act = Act(doc.document_xml)
        act.frbr_uri = uri.work_uri(False)
        doc.frbr_uri = uri.work_uri(False)
        doc.document_xml = act.to_xml()
        doc.save()
Esempio n. 5
0
    def test_frbr_uri(self):
        a = Act()
        a.expression_date = '2012-01-01'
        a.frbr_uri = '/zm/act/2007/01'

        assert_equal(a.frbr_uri.work_uri(), '/zm/act/2007/01')
        assert_equal(a.number, '01')

        assert_equal(a.meta.identification.FRBRWork.FRBRthis.get('value'), '/zm/act/2007/01/main')
        assert_equal(a.meta.identification.FRBRWork.FRBRuri.get('value'), '/zm/act/2007/01')
        assert_equal(a.meta.identification.FRBRWork.FRBRcountry.get('value'), 'zm')

        assert_equal(a.meta.identification.FRBRExpression.FRBRthis.get('value'), '/zm/act/2007/01/eng@2012-01-01/main')
        assert_equal(a.meta.identification.FRBRExpression.FRBRuri.get('value'), '/zm/act/2007/01/eng@2012-01-01')

        assert_equal(a.meta.identification.FRBRManifestation.FRBRthis.get('value'), '/zm/act/2007/01/eng@2012-01-01/main')
        assert_equal(a.meta.identification.FRBRManifestation.FRBRuri.get('value'), '/zm/act/2007/01/eng@2012-01-01')
Esempio n. 6
0
 def test_table_of_contents(self):
     a = Act()
     a.body_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>
     """
     toc = a.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': 'Chapter 1. - The Chapter', 'children': [
             {'id': 'part-A', 'num': 'A', 'type': 'part', 'heading': 'The Part',
               'component': 'main', 'subcomponent': 'chapter/1/part/A', 'title': 'Part A - The Part', 'children': [
                 {'id': 'section-2', 'num': '2.', 'type': 'section', 'heading': 'Other',
                   'component': 'main', 'subcomponent': 'section/2', 'title': '2. Other'},
                 ]
             },
             ]
         },
         ])
Esempio n. 7
0
    def test_get_subcomponent(self):
        a = Act()
        a.body_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(a.components()['main'])
        elem = a.get_subcomponent('main', 'chapter/2')
        assert_equal(elem.get('id'), "chapter-2")

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

        assert_is_none(a.get_subcomponent('main', 'chapter/99'))
        assert_is_none(a.get_subcomponent('main', 'section/99'))
Esempio n. 8
0
def set_repeal_details(apps, schema_editor):
    Document = apps.get_model("indigo_api", "Document")
    db_alias = schema_editor.connection.alias
    for doc in Document.objects.using(db_alias).all():
        a = Act(doc.document_xml)
        repeal = a.repeal
        if repeal:
            doc.repeal_event = {
                'date': datestring(repeal.date),
                'repealing_title': repeal.repealing_title,
                'repealing_uri': repeal.repealing_uri,
            }
            doc.save()
Esempio n. 9
0
def set_amendment_details(apps, schema_editor):
    Document = apps.get_model("indigo_api", "Document")
    db_alias = schema_editor.connection.alias
    for doc in Document.objects.using(db_alias).all():
        a = Act(doc.document_xml)
        amendments = a.amendments
        if amendments:
            doc.amendment_events = [{
                'date': datestring(e.date),
                'amending_title': e.amending_title,
                'amending_uri': e.amending_uri,
            } for e in amendments]
            doc.save()
Esempio n. 10
0
    def test_migration_without_heading(self):
        migration = ScheduleArticleToHcontainer()

        xml = OLD_SCHEDULE % ("""
        <paragraph id="schedule2.paragraph-0">
          <content>
            <p>None</p>
          </content>
        </paragraph>""")
        act = Act(xml)
        migration.migrate_act(act)

        expected = NEW_SCHEDULE % """
        <heading>Schedule</heading><paragraph id="schedule2.paragraph-0">
          <content>
            <p>None</p>
          </content>
        </paragraph>"""
        self.assertMultiLineEqual(
            expected,
            etree.tostring(act.root, encoding='utf-8',
                           pretty_print=True).decode('utf-8'))
Esempio n. 11
0
    def test_component_table_of_contents(self):
        a = Act("""
<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>
        """)
        toc = a.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)
Esempio n. 12
0
 def _make_act(self, xml):
     id = re.sub(r'[^a-zA-Z0-9]', '-', settings.INDIGO_ORGANISATION)
     doc = Act(xml)
     doc.source = [settings.INDIGO_ORGANISATION, id, settings.INDIGO_URL]
     return doc
Esempio n. 13
0
 def test_language(self):
     a = Act()
     a.language = 'fre'
     assert_equal(a.language, 'fre')
Esempio n. 14
0
    def test_publication_name(self):
        a = Act()
        assert_is_none(a.publication_name)

        a.publication_name = 'Publication'
        assert_equal(a.publication_name, 'Publication')
Esempio n. 15
0
    def test_publication_number(self):
        a = Act()
        assert_is_none(a.publication_number)

        a.publication_number = '1234'
        assert_equal(a.publication_number, '1234')
Esempio n. 16
0
 def test_manifestation_date(self):
     a = Act()
     a.manifestation_date = '2012-01-02'
     assert_equal(datestring(a.manifestation_date), '2012-01-02')
     assert_is_instance(a.manifestation_date, date)
Esempio n. 17
0
 def test_expression_date(self):
     a = Act()
     a.expression_date = '2012-01-02'
     assert_equal(datestring(a.expression_date), '2012-01-02')
     assert_is_instance(a.expression_date, date)
Esempio n. 18
0
 def test_work_date(self):
     a = Act()
     a.work_date = '2012-01-02'
     assert_equal(datestring(a.work_date), '2012-01-02')
     assert_is_instance(a.work_date, date)
Esempio n. 19
0
 def test_empty_body(self):
     a = Act()
     assert_not_equal(a.body_xml, '')
     a.body_xml = ''
     assert_not_equal(a.body_xml, '')
Esempio n. 20
0
    def test_set_amendments(self):
        a = Act()
        a.body_xml = """
        <body xmlns="http://www.akomantoso.org/2.0"/>
        """

        a.amendments = [AmendmentEvent(date='2012-02-01', amending_uri='/za/act/1980/10', amending_title="Foo")]

        assert_equal(a.to_xml(), """<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="#cobalt">
        <FRBRWork>
          <FRBRthis value="/za/act/1900/1/main"/>
          <FRBRuri value="/za/act/1900/1"/>
          <FRBRalias value="Untitled"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRcountry value="za"/>
        </FRBRWork>
        <FRBRExpression>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRlanguage language="eng"/>
        </FRBRExpression>
        <FRBRManifestation>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
        </FRBRManifestation>
      </identification>
      <lifecycle source="#cobalt">
        <eventRef id="amendment-2012-02-01" date="2012-02-01" type="amendment" source="#amendment-0-source"/>
      </lifecycle>
      <references>
        <TLCOrganization id="cobalt" href="https://github.com/Code4SA/cobalt" showAs="cobalt"/>
        <passiveRef id="amendment-0-source" href="/za/act/1980/10" showAs="Foo"/>
      </references>
    </meta>
    <body/>
  </act>
</akomaNtoso>
""")

        a.amendments = [
            AmendmentEvent(date='2012-02-01', amending_uri='/za/act/1980/22', amending_title="Corrected"),
            AmendmentEvent(date='2013-03-03', amending_uri='/za/act/1990/5', amending_title="Bar"),
        ]
        assert_equals(a.to_xml(), """<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="#cobalt">
        <FRBRWork>
          <FRBRthis value="/za/act/1900/1/main"/>
          <FRBRuri value="/za/act/1900/1"/>
          <FRBRalias value="Untitled"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRcountry value="za"/>
        </FRBRWork>
        <FRBRExpression>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
          <FRBRlanguage language="eng"/>
        </FRBRExpression>
        <FRBRManifestation>
          <FRBRthis value="/za/act/1900/1/eng@/main"/>
          <FRBRuri value="/za/act/1900/1/eng@"/>
          <FRBRdate date="1900-01-01" name="Generation"/>
          <FRBRauthor href="#council" as="#author"/>
        </FRBRManifestation>
      </identification>
      <lifecycle source="#cobalt">
        <eventRef id="amendment-2012-02-01" date="2012-02-01" type="amendment" source="#amendment-0-source"/>
        <eventRef id="amendment-2013-03-03" date="2013-03-03" type="amendment" source="#amendment-1-source"/>
      </lifecycle>
      <references>
        <TLCOrganization id="cobalt" href="https://github.com/Code4SA/cobalt" showAs="cobalt"/>
        <passiveRef id="amendment-0-source" href="/za/act/1980/22" showAs="Corrected"/>
        <passiveRef id="amendment-1-source" href="/za/act/1990/5" showAs="Bar"/>
      </references>
    </meta>
    <body/>
  </act>
</akomaNtoso>
""")

        amendment = a.amendments[0]
        assert_equal(datestring(amendment.date), '2012-02-01')
        assert_equal(amendment.amending_uri, '/za/act/1980/22')
        assert_equal(amendment.amending_title, 'Corrected')

        amendment = a.amendments[1]
        assert_equal(datestring(amendment.date), '2013-03-03')
        assert_equal(amendment.amending_uri, '/za/act/1990/5')
        assert_equal(amendment.amending_title, 'Bar')