Skip to content

Commit

Permalink
test defns: Budget alignment: check transactions inside sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Oct 10, 2023
1 parent 43ee599 commit abb9517
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test_definitions/finance/13_budget_alignment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Feature: Budget Alignment
And `activity-status/@code` is one of 2, 3 or 4
And `default-aid-type/@code` is not any of A01, A02 or G01
And `transaction/aid-type/@code` is not any of A01 or A02
Then `sector/@code` should be present
And at least one `sector[not(@vocabulary) or @vocabulary="1"]/@code | transaction/sector[@vocabulary="1" or not(@vocabulary)]/@code` should be on the Sector codelist
And `sector/@code` is not any of 43010, 43050, 43081, 43082, 52010, 99810, 15110, 15111, 15112, 15114, 15130, 16010, 16061, 21010, 21020, 22010, 23110, 43030 or 43040
Then `sector/@code` should be present, or `sector/@code` should be present for every `transaction`
And at least one `sector[not(@vocabulary) or @vocabulary="1"]/@code`, or at least one `sector[not(@vocabulary) or @vocabulary="1"]/@code` for every `transaction`, should be on the Sector codelist
And `sector[not(@vocabulary) or @vocabulary="1"]/@code | transaction/sector[not(@vocabulary) or @vocabulary="1"]/@code` is not any of 43010, 43050, 43081, 43082, 52010, 99810, 15110, 15111, 15112, 15114, 15130, 16010, 16061, 21010, 21020, 22010, 23110, 43030 or 43040
21 changes: 21 additions & 0 deletions test_definitions/step_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ def then_is_present_and_nonzero(xml, xpath_expression, **kwargs):
raise StepException(msg)


@then(r'`([^`]+)` should be present, or `([^`]+)` should be present for every `([^`]+)`')
def then_is_present_or_for_every(xml, xpath_expression, for_every_xpath_expression, for_every_elements, **kwargs):
try:
then_is_present(xml, xpath_expression, **kwargs)
except StepException:
for element in xml.xpath(for_every_elements):
then_is_present(element, for_every_xpath_expression, **kwargs)
return xml


@then(r'every `([^`]+)` should be on the ([^ ]+) codelist')
def then_every_on_codelist(xml, xpath_expression, codelist, **kwargs):
vals = xml.xpath(xpath_expression)
Expand Down Expand Up @@ -116,6 +126,17 @@ def then_at_least_one_on_codelist(xml, xpath_expression, codelist, **kwargs):
raise StepException(msg)


@then(r'at least one `([^`]+)`, or at least one `([^`]+)` for every `([^`]+)`, should be on the ([^ ]+) codelist')
def then_at_least_one_on_codelist_or_for_every(xml, xpath_expression, for_every_xpath_expression, for_every_elements, codelist, **kwargs):
try:
then_at_least_one_on_codelist(xml, xpath_expression, codelist, **kwargs)
except StepException:
for element in xml.xpath(for_every_elements):
then_at_least_one_on_codelist(element, for_every_xpath_expression, codelist, **kwargs)

return xml


@given(r'the activity is current')
def given_activity_is_current(xml, **kwargs):
try:
Expand Down
63 changes: 63 additions & 0 deletions tests/finance/test_budget_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,69 @@ def test_sector_code(self):

assert result is True

def test_sector_code_in_transaction(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<default-aid-type code="A09"/>
<transaction>
<aid-type code="A03"/>
<sector code="1000"/>
</transaction>
<transaction>
<aid-type code="A03"/>
<sector code="1000"/>
<sector code="NOTDAC" vocabulary="NOTDAC"/>
</transaction>
</iati-activity>
'''

activity = etree.fromstring(xml)
result = self.test(activity, codelists=self.codelists)

assert result is True

def test_sector_code_not_in_every_transaction(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<default-aid-type code="A09"/>
<transaction>
<aid-type code="A03"/>
<sector code="1000"/>
</transaction>
<transaction>
<aid-type code="A03"/>
</transaction>
</iati-activity>
'''

activity = etree.fromstring(xml)
result = self.test(activity, codelists=self.codelists)

assert result is False

def test_sector_code_not_on_list_in_every_transaction(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<default-aid-type code="A09"/>
<transaction>
<aid-type code="A03"/>
<sector code="1000"/>
</transaction>
<transaction>
<aid-type code="A03"/>
<sector code="NOT_ON_LIST"/>
</transaction>
</iati-activity>
'''

activity = etree.fromstring(xml)
result = self.test(activity, codelists=self.codelists)

assert result is False

def test_bad_sector_code(self):
xml = '''
<iati-activity>
Expand Down

0 comments on commit abb9517

Please sign in to comment.