diff --git a/tests/test_at_transaction_level.py b/tests/test_at_transaction_level.py index 86c8e40..86b00dd 100644 --- a/tests/test_at_transaction_level.py +++ b/tests/test_at_transaction_level.py @@ -1 +1,48 @@ -# TODO When country, sector, etc specified on transaction directly, no splits should occur. Test that here +from iati_activity_details_split_by_fields.iati_activity import IATIActivity +from iati_activity_details_split_by_fields.iati_activity_transaction import ( + IATIActivityTransaction, +) +from iati_activity_details_split_by_fields.iati_activity_transaction_sector import ( + IATIActivityTransactionSector, +) + + +def test_country_set(): + + iati_activity = IATIActivity( + transactions=[IATIActivityTransaction(value=1000, recipient_country_code="GB")], + ) + + results = iati_activity.get_transactions_split_as_json() + + assert [ + { + "recipient_country_code": "GB", + "sectors": [], + "value": 1000, + } + ] == results + + +def test_sector_set(): + + iati_activity = IATIActivity( + transactions=[ + IATIActivityTransaction( + value=1000, + sectors=[ + IATIActivityTransactionSector(vocabulary="cats", code="Henry") + ], + ) + ], + ) + + results = iati_activity.get_transactions_split_as_json() + + assert [ + { + "recipient_country_code": None, + "sectors": [{"code": "Henry", "vocabulary": "cats"}], + "value": 1000, + }, + ] == results diff --git a/tests/test_both_at_activity_and_transaction_level.py b/tests/test_both_at_activity_and_transaction_level.py new file mode 100644 index 0000000..29a5826 --- /dev/null +++ b/tests/test_both_at_activity_and_transaction_level.py @@ -0,0 +1,4 @@ +# TODO +# What happens when a country, region, sector is set at BOTH Activity and Transaction? +# According to standard, this isn't allowed! +# But we should test this to make sure bad data is ok