Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test defns: Fix commitment test to not always fail #38

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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