Skip to content

Commit

Permalink
Don't set unnecessary contains="originalVersion"
Browse files Browse the repository at this point in the history
This is the default and is not being set/not-set consistently. So just
don't set it.
  • Loading branch information
longhotsummer committed Mar 28, 2022
1 parent 6d12595 commit b78edc2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
32 changes: 16 additions & 16 deletions cobalt/hierarchical.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ def empty_document_content(cls, E):
eId="sec_nn_1")
)

@classmethod
def empty_document_attrs(cls):
attrs = super().empty_document_attrs()
attrs['contains'] = 'originalVersion'
return attrs

@property
def publication_name(self):
""" Name of the publication in which this act was published.
Expand Down Expand Up @@ -90,18 +84,24 @@ def amendments(self):
@amendments.setter
def amendments(self, value):
# delete existing entries
for e in self.meta.iterfind(f'.//{{{self.namespace}}}lifecycle/{{{self.namespace}}}eventRef[@type="amendment"]'):
# delete the passive ref elements
eid = e.get('source')[1:]
for node in self.meta.iterfind(f'.//{{{self.namespace}}}references/{{{self.namespace}}}passiveRef[@eId="{eid}"]'):
node.getparent().remove(node)

# delete the event
e.getparent().remove(e)
lifecycle = self.meta.find(f'{{{self.namespace}}}lifecycle')
if lifecycle is not None:
for e in lifecycle.findall(f'./{{{self.namespace}}}eventRef[@type="amendment"]'):
# delete the passive ref elements
eid = e.get('source')[1:]
for node in self.meta.iterfind(f'.//{{{self.namespace}}}references/{{{self.namespace}}}passiveRef[@eId="{eid}"]'):
node.getparent().remove(node)
# delete the event
lifecycle.remove(e)

if not value:
# no amendments
self.act.set('contains', 'originalVersion')
# no amendments, default is originalVersion so it doesn't need to be set explicitly
if 'contains' in self.act.attrib:
del self.act.attrib['contains']
# lifecycle cannot be empty§
if lifecycle is not None and not lifecycle.getchildren():
lifecycle.getparent().remove(lifecycle)

else:
self.act.set('contains', 'singleVersion')
lifecycle = self._ensure_lifecycle()
Expand Down
50 changes: 49 additions & 1 deletion tests/test_act.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,54 @@ def test_set_amendments(self):

assert_validates(a)

# clear them
a.amendments = []
xml = a.to_xml(encoding='unicode', pretty_print=True)
xml = xml.replace(datestring(date.today()), 'TODAY')

self.assertMultiLineEqual(
"""<akomaNtoso xmlns="http://docs.oasis-open.org/legaldocml/ns/akn/3.0">
<act name="act">
<meta>
<identification source="#cobalt">
<FRBRWork>
<FRBRthis value="/akn/za/act/1900/1/!main"/>
<FRBRuri value="/akn/za/act/1900/1"/>
<FRBRalias value="Untitled" name="title"/>
<FRBRdate date="1900" name="Generation"/>
<FRBRauthor href=""/>
<FRBRcountry value="za"/>
<FRBRnumber value="1"/>
</FRBRWork>
<FRBRExpression>
<FRBRthis value="/akn/za/act/1900/1/eng@TODAY/!main"/>
<FRBRuri value="/akn/za/act/1900/1/eng@TODAY"/>
<FRBRdate date="TODAY" name="Generation"/>
<FRBRauthor href=""/>
<FRBRlanguage language="eng"/>
</FRBRExpression>
<FRBRManifestation>
<FRBRthis value="/akn/za/act/1900/1/eng@TODAY/!main"/>
<FRBRuri value="/akn/za/act/1900/1/eng@TODAY"/>
<FRBRdate date="TODAY" name="Generation"/>
<FRBRauthor href=""/>
</FRBRManifestation>
</identification>
<references source="#cobalt">
<TLCOrganization eId="cobalt" href="https://github.com/laws-africa/cobalt" showAs="cobalt"/>
</references>
</meta>
<body>
<section eId="sec_nn_1">
<content>
<p eId="sec_nn_1__p_1"/>
</content>
</section>
</body>
</act>
</akomaNtoso>
""", xml)

def test_set_repeal(self):
a = Act()
a.frbr_uri = "/akn/za/act/1900/1"
Expand All @@ -178,7 +226,7 @@ def test_set_repeal(self):

self.assertMultiLineEqual(
"""<akomaNtoso xmlns="http://docs.oasis-open.org/legaldocml/ns/akn/3.0">
<act name="act" contains="originalVersion">
<act name="act">
<meta>
<identification source="#cobalt">
<FRBRWork>
Expand Down

0 comments on commit b78edc2

Please sign in to comment.