Skip to content

Commit

Permalink
Merge pull request #38 from pwyf/fix-commitment
Browse files Browse the repository at this point in the history
test defns: Fix commitment test to not always fail
  • Loading branch information
simon-20 committed Nov 9, 2023
2 parents a84d878 + f9027c1 commit e8cbe9a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test_definitions/finance/11_commitment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Feature: Commitment
Given an IATI activity
And the activity is current
And `activity-status/@code` is one of 2, 3 or 4
Then `transaction/transaction-type[@code="2"]` should be present and of non-zero value
Then `transaction[transaction-type/@code="2"]` should be present and of non-zero value
98 changes: 98 additions & 0 deletions tests/finance/test_commitments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from os.path import dirname, join, realpath
from unittest import TestCase

from bdd_tester import BDDTester
from lxml import etree


class TestCommitments(TestCase):
def setUp(self):
self.FILEPATH = dirname(realpath(__file__))
steps_path = join(self.FILEPATH, '..', '..', 'test_definitions',
'step_definitions.py')
feature_path = join(self.FILEPATH, '..', '..', 'test_definitions',
'finance',
'11_commitment.feature')

tester = BDDTester(steps_path)
feature = tester.load_feature(feature_path)
self.test = feature.tests[0]

def test_commitment_no_value(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<transaction>
<transaction-type code="2"/>
</transaction>
</iati-activity>
'''

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

assert result is False

def test_commitment_zero_value(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<transaction>
<transaction-type code="2"/>
<value>0</value>
</transaction>
</iati-activity>
'''

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

assert result is False

def test_commitment_zero_value_decimal(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<transaction>
<transaction-type code="2"/>
<value>0.0</value>
</transaction>
</iati-activity>
'''

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

assert result is False

def test_commitment_non_zero(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<transaction>
<transaction-type code="2"/>
<value>123.45</value>
</transaction>
</iati-activity>
'''

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

assert result is True

def test_commitment_not_present(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<transaction>
<transaction-type code="3"/>
</transaction>
</iati-activity>
'''

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

assert result is False

16 changes: 16 additions & 0 deletions tests/finance/test_disbursements_and_expenditures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ def setUp(self):
feature = tester.load_feature(feature_path)
self.test = feature.tests[0]

def test_disbursement_or_expenditure(self):
xml = '''
<iati-activity>
<activity-status code="2"/>
<transaction>
<transaction-type code="{}"/>
</transaction>
</iati-activity>
'''

for transaction_type in ['3', '4']:
activity = etree.fromstring(xml.format(transaction_type))
result = self.test(activity)

assert result is True

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

0 comments on commit e8cbe9a

Please sign in to comment.