]> git.ipfire.org Git - thirdparty/python-fints.git/commitdiff
Add 1step transfer test
authorHenryk Plötz <henryk@ploetzli.ch>
Mon, 10 Sep 2018 11:08:12 +0000 (13:08 +0200)
committerRaphael Michel <mail@raphaelmichel.de>
Mon, 3 Dec 2018 18:34:29 +0000 (19:34 +0100)
tests/conftest.py
tests/test_client.py

index 0d45aa14072aab5c3ecbfeb1e81ddaa6a23cf451..2894b4eb0362dba141d77a9745b196578389ded4 100644 (file)
@@ -66,6 +66,19 @@ def fints_server():
             if b"'HKSPA:" in message:
                 result.append(b"HISPA::1:4+J:DE111234567800000001:GENODE00TES:00001::280:1234567890'")
 
+            hkccs = re.search(rb"'HKCCS:(\d+):1.*@\d+@(.*)/Document>'", message)
+            if hkccs:
+                segno = hkccs.group(1).decode('us-ascii')
+                pain = hkccs.group(2).decode('utf-8')
+
+                memomatch = re.search(r"<RmtInf[^>]*>\s*<Ustrd[^>]*>\s*([^<]+)\s*</Ustrd", pain)
+                recvrmatch = re.search(r"<CdtrAcct[^>]*>\s*<Id[^>]*>\s*<IBAN[^>]*>\s*([^<]+)\s*</IBAN", pain)
+                amountmatch = re.search(r"<Amt[^>]*><InstdAmt[^>]*>\s*([^<]+)\s*</InstdAmt", pain)
+
+                if memomatch and recvrmatch and amountmatch:
+                    if memomatch.group(1).endswith('1step'):
+                        result.append("HIRMS::2:{}+0010::Transfer {} to {} re {}'".format(segno, amountmatch.group(1), recvrmatch.group(1), repr(memomatch.group(1)).replace("'", "?'")).encode('iso-8859-1'))
+
             return b"".join(result)
 
 
index 8915af0216f1b086ffc59cf400a239ef4feb9684..d79102765ec2bc5752377a366dd95be360a183db 100644 (file)
@@ -1,4 +1,5 @@
-from fints.client import FinTS3PinTanClient
+from fints.client import FinTS3PinTanClient, TransactionResponse, NeedTANResponse, ResponseStatus
+from decimal import Decimal
 import pytest
 
 @pytest.fixture
@@ -44,3 +45,42 @@ def test_resume(fints_client, fints_server):
     with fints_client.resume_dialog(d_data):
         assert dialog_id == fints_client._standing_dialog.dialogue_id
         assert fints_client.bpd_version == 78
+
+def test_transfer_1step(fints_client):
+    with fints_client:
+        accounts = fints_client.get_sepa_accounts()
+        a = fints_client.simple_sepa_transfer(
+            accounts[0],
+            'DE111234567800000002',
+            'GENODE00TES',
+            'Test Receiver',
+            Decimal('1.23'),
+            'Test Sender',
+            'Test transfer 1step'
+        )
+
+        assert isinstance(a, TransactionResponse)
+        assert a.status == ResponseStatus.SUCCESS
+
+        assert a.responses[0].code == '0010'
+        assert a.responses[0].text == "Transfer 1.23 to DE111234567800000002 re 'Test transfer 1step'"
+
+def test_transfer_1step_regression(fints_client):
+    # Passing a float is not officially supported, but should not fail with wrong values
+    # Decimal(1.23) is Decimal('1.229999999999999982236431605997495353221893310546875')
+    # which emphatically should not be cut to 122 cents.
+
+    with fints_client:
+        accounts = fints_client.get_sepa_accounts()
+        a = fints_client.simple_sepa_transfer(
+            accounts[0],
+            'DE111234567800000002',
+            'GENODE00TES',
+            'Test Receiver',
+            1.23,
+            'Test Sender',
+            'Test transfer 1step'
+        )
+
+        assert isinstance(a, TransactionResponse)
+        assert a.responses[0].text == "Transfer 1.23 to DE111234567800000002 re 'Test transfer 1step'"