Skip to content

Commit

Permalink
test defns: Location: Add adminstrative and location-id
Browse files Browse the repository at this point in the history
Any of location/point, or location/id or location/adminstrative with a
correct vocabulary are now permitted.

#22
  • Loading branch information
Bjwebb committed Oct 12, 2023
1 parent 5cd35c9 commit ea1989c
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Feature: Sub-national location
And `recipient-region/@code` is not 998
And `default-aid-type/@code` is not any of B01, B02, F01, H01, H02, H03, H04, H05 or G01
And `transaction/aid-type/@code` is not any of B01, B02, F01, H01, H02, H03, H04, H05 or G01
Then `location` should be present
Then `location[point or administrative or location-id]` should be present

Scenario Outline: Location (sub-national) coordinates or point
Scenario Outline: Location (sub-national) point or administrative or location-id
Given an IATI activity
And the activity is current
And `activity-status/@code` is one of 2, 3 or 4
And `recipient-region/@code` is not 998
And `default-aid-type/@code` is not any of B01, B02, F01, H01, H02, H03, H04, H05 or G01
And `transaction/aid-type/@code` is not any of B01, B02, F01, H01, H02, H03, H04, H05 or G01
Then `location[coordinates or point]` should be present
Then `location/point` should be present, or at least one `location/administrative/@vocabulary | location/location-id/@vocabulary` should be on the GeographicVocabulary codelist
9 changes: 9 additions & 0 deletions test_definitions/step_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ def then_at_least_one_on_codelist_or_for_every(xml, xpath_expression, for_every_
return xml


@then(r'`([^`]+)` should be present, or at least one `([^`]+)` should be on the ([^ ]+) codelist')
def then_is_present_or_at_least_one_on_codelist(xml, present_xpath_expression, on_codelist_xpath_expression, codelist, **kwargs):
try:
then_is_present(xml, present_xpath_expression, **kwargs)
except StepException:
then_at_least_one_on_codelist(xml, on_codelist_xpath_expression, codelist, **kwargs)
return xml


@given(r'the activity is current')
def given_activity_is_current(xml, **kwargs):
try:
Expand Down
116 changes: 109 additions & 7 deletions tests/project_attributes/test_subnational.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def setUp(self):
tester = BDDTester(steps_path)
self.feature = tester.load_feature(feature_path)
self.test = self.feature.tests[1] # location point test
self.codelists = {'GeographicVocabulary': ['A1', 'A2', 'A3', 'A4', 'G1', 'G2']}

def test_basic_failure(self):
xml = '''
Expand All @@ -25,7 +26,7 @@ def test_basic_failure(self):
'''

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

assert result is False

Expand All @@ -38,7 +39,7 @@ def test_exclusion(self):
'''

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


assert result is None
Expand All @@ -55,7 +56,7 @@ def test_transaction_exclusion(self):
'''

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

assert result is None

Expand All @@ -74,22 +75,123 @@ def test_transaction_exclusion_with_2_trasactions(self):
'''

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

assert result is None

def test_pass(self):
def test_pass_point(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<location>
<point />
<point />
</location>
</iati-activity>
'''

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

assert result is True

def test_pass_location_id(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<location>
<location-id vocabulary="G1" code="1453782" />
</location>
</iati-activity>
'''

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

assert result is True

def test_fail_location_id(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<location>
<location-id code="1453782" />
</location>
</iati-activity>
'''

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

assert result is False

def test_pass_location_administrative(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<location>
<administrative vocabulary="G1" level="1" code="1453782" />
</location>
</iati-activity>
'''

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

assert result is True

def test_fail_location_administrative(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<location>
<administrative vocabulary="BAD_CODE" level="1" code="1453782" />
</location>
</iati-activity>
'''

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

assert result is False

def test_pass_no_vocabularies(self):
# This should pass because there's a point element,
# despite the fact that vocabulary is missing for
# administrative and location-id

xml = '''
<iati-activity>
<activity-status code="2"/>
<location>
<location-id />
<administrative />
<point />
</location>
</iati-activity>
'''

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

assert result is True

def test_pass_wrong_vocabularies(self):
# This should pass because there's a point element,
# despite the fact that vocabulary is missing for
# administrative and location-id

xml = '''
<iati-activity>
<activity-status code="2"/>
<location>
<location-id vocabulary="BAD_CODE" />
<administrative vocabulary="BAD_CODE" />
<point />
</location>
</iati-activity>
'''

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

assert result is True

0 comments on commit ea1989c

Please sign in to comment.