import datetime import pytest from sepaxml import SepaDD from sepaxml.validation import ValidationError from tests.utils import clean_ids, validate_xml @pytest.fixture def sdd(): return SepaDD({ "name": "TestCreditor", "IBAN": "NL50BANK1234567890", "BIC": "BANKNL2A", "batch": True, "creditor_id": "DE26ZZZ00000000000", "currency": "EUR" }, schema="pain.008.001.09") SAMPLE_RESULT = b""" 20012017014921-ba2dab283fdd 2017-01-20T13:49:21 2 60.12 TestCreditor DE26ZZZ00000000000 TestCreditor-ecd6a2f680ce DD true 1 10.12 SEPA CORE FRST 2017-01-20 TestCreditor NL50BANK1234567890 BANKNL2A SLEV DE26ZZZ00000000000 SEPA TestCreditor-4431989789fb 10.12 1234 2017-01-20 BANKNL2A Test von Testenstein NL50BANK1234567890 Test transaction1 TestCreditor-d547a1b3882f DD true 1 50.00 SEPA CORE RCUR 2017-01-20 TestCreditor NL50BANK1234567890 BANKNL2A SLEV DE26ZZZ00000000000 SEPA TestCreditor-7e989083e265 50.00 1234 2017-01-20 BANKNL2A Test du Test NL50BANK1234567890 Test transaction2 """ def test_two_debits(sdd): payment1 = { "name": "Test von Testenstein", "IBAN": "NL50BANK1234567890", "BIC": "BANKNL2A", "amount": 1012, "type": "FRST", "collection_date": datetime.date.today(), "mandate_id": "1234", "mandate_date": datetime.date.today(), "description": "Test transaction1" } payment2 = { "name": "Test du Test", "IBAN": "NL50BANK1234567890", "BIC": "BANKNL2A", "amount": 5000, "type": "RCUR", "collection_date": datetime.date.today(), "mandate_id": "1234", "mandate_date": datetime.date.today(), "description": "Test transaction2" } sdd.add_payment(payment1) sdd.add_payment(payment2) xmlout = sdd.export() xmlpretty = validate_xml(xmlout, "pain.008.001.09") assert clean_ids(xmlpretty.strip()).decode() == clean_ids(SAMPLE_RESULT.strip()).decode()