# encoding: utf-8 import datetime from unittest import mock import pytest from sepaxml import SepaDD from tests.utils import validate_xml @pytest.fixture def freeze_random(): import random with mock.patch("sepaxml.utils.random", random.Random(123456)): yield @pytest.fixture def now(): return datetime.datetime(2021, 10, 2, 20, 17, 35, tzinfo=datetime.timezone.utc) @pytest.fixture def today(now): return now.date() @pytest.fixture def freeze_datetime(now): _datetime = mock.Mock( date=datetime.date, datetime=mock.Mock(now=mock.Mock(return_value=now)), ) with mock.patch("sepaxml.debit.datetime", _datetime), mock.patch( "sepaxml.utils.datetime", _datetime ): yield @pytest.fixture def sdd(): return SepaDD({ "name": "Miller & Son Ltd", "IBAN": "NL50BANK1234567890", "BIC": "BANKNL2A", "batch": True, "creditor_id": "DE26ZZZ00000000000", "currency": "EUR" }, schema="pain.008.001.02") SAMPLE_RESULT = b""" 20211002081735-9050218037f5 2021-10-02T20:17:35 2 60.12 Miller & Son Ltd DE26ZZZ00000000000 MillerSonLtd-04cb151eee51 DD true 1 10.12 SEPA CORE FRST 2021-10-02 Miller & Son Ltd NL50BANK1234567890 BANKNL2A SLEV DE26ZZZ00000000000 SEPA ebd75e7e649375d91b33dc11ae44c0e1 10.12 1234 2021-10-02 BANKNL2A Test & Co. NL50BANK1234567890 Test transaction1 MillerSonLtd-323224a9eab8 DD true 1 50.00 SEPA CORE RCUR 2021-10-02 Miller & Son Ltd NL50BANK1234567890 BANKNL2A SLEV DE26ZZZ00000000000 SEPA af755a40cb692551ed9f9d55f7179525 50.00 1234 2021-10-02 BANKNL2A Test du Test NL50BANK1234567890 Testgrusse <html> """ @pytest.mark.usefixtures("freeze_random", "freeze_datetime") def test_two_debits(sdd, today): payment1 = { "name": "Test & Co.", "IBAN": "NL50BANK1234567890", "BIC": "BANKNL2A", "amount": 1012, "type": "FRST", "collection_date": today, "mandate_id": "1234", "mandate_date": today, "description": "Test transaction1", "endtoend_id": "ebd75e7e649375d91b33dc11ae44c0e1" } payment2 = { "name": "Test du Test", "IBAN": "NL50BANK1234567890", "BIC": "BANKNL2A", "amount": 5000, "type": "RCUR", "collection_date": today, "mandate_id": "1234", "mandate_date": today, "description": u"Testgrüße ", "endtoend_id": "af755a40cb692551ed9f9d55f7179525" } sdd.add_payment(payment1) sdd.add_payment(payment2) xmlout = sdd.export() xmlpretty = validate_xml(xmlout, "pain.008.001.02") assert xmlpretty.strip() == SAMPLE_RESULT.strip()