| 1 |
|
| 2 |
|
| 3 |
import datetime |
| 4 |
|
| 5 |
import pytest |
| 6 |
|
| 7 |
from sepaxml import SepaDD |
| 8 |
from tests.utils import clean_ids, validate_xml |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
@pytest.fixture |
| 13 |
def sdd(): |
| 14 |
return SepaDD({ |
| 15 |
"name": "Miller & Son Ltd", |
| 16 |
"IBAN": "NL50BANK1234567890", |
| 17 |
"BIC": "BANKNL2A", |
| 18 |
"batch": True, |
| 19 |
"creditor_id": "DE26ZZZ00000000000", |
| 20 |
"currency": "EUR" |
| 21 |
}, schema="pain.008.001.02") |
| 22 |
|
| 23 |
|
| 24 |
SAMPLE_RESULT = b""" |
| 25 |
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
| 26 |
<CstmrDrctDbtInitn> |
| 27 |
<GrpHdr> |
| 28 |
<MsgId>20012017014921-ba2dab283fdd</MsgId> |
| 29 |
<CreDtTm>2017-01-20T13:49:21</CreDtTm> |
| 30 |
<NbOfTxs>1</NbOfTxs> |
| 31 |
<CtrlSum>10.12</CtrlSum> |
| 32 |
<InitgPty> |
| 33 |
<Nm>Miller & Son Ltd</Nm> |
| 34 |
<Id> |
| 35 |
<OrgId> |
| 36 |
<Othr> |
| 37 |
<Id>DE26ZZZ00000000000</Id> |
| 38 |
</Othr> |
| 39 |
</OrgId> |
| 40 |
</Id> |
| 41 |
</InitgPty> |
| 42 |
</GrpHdr> |
| 43 |
<PmtInf> |
| 44 |
<PmtInfId>MillerSonLtd-ecd6a2f680ce</PmtInfId> |
| 45 |
<PmtMtd>DD</PmtMtd> |
| 46 |
<BtchBookg>true</BtchBookg> |
| 47 |
<NbOfTxs>1</NbOfTxs> |
| 48 |
<CtrlSum>10.12</CtrlSum> |
| 49 |
<PmtTpInf> |
| 50 |
<SvcLvl> |
| 51 |
<Cd>SEPA</Cd> |
| 52 |
</SvcLvl> |
| 53 |
<LclInstrm> |
| 54 |
<Cd>CORE</Cd> |
| 55 |
</LclInstrm> |
| 56 |
<SeqTp>FRST</SeqTp> |
| 57 |
</PmtTpInf> |
| 58 |
<ReqdColltnDt>2017-01-20</ReqdColltnDt> |
| 59 |
<Cdtr> |
| 60 |
<Nm>Miller & Son Ltd</Nm> |
| 61 |
</Cdtr> |
| 62 |
<CdtrAcct> |
| 63 |
<Id> |
| 64 |
<IBAN>NL50BANK1234567890</IBAN> |
| 65 |
</Id> |
| 66 |
</CdtrAcct> |
| 67 |
<CdtrAgt> |
| 68 |
<FinInstnId> |
| 69 |
<BIC>BANKNL2A</BIC> |
| 70 |
</FinInstnId> |
| 71 |
</CdtrAgt> |
| 72 |
<ChrgBr>SLEV</ChrgBr> |
| 73 |
<CdtrSchmeId> |
| 74 |
<Id> |
| 75 |
<PrvtId> |
| 76 |
<Othr> |
| 77 |
<Id>DE26ZZZ00000000000</Id> |
| 78 |
<SchmeNm> |
| 79 |
<Prtry>SEPA</Prtry> |
| 80 |
</SchmeNm> |
| 81 |
</Othr> |
| 82 |
</PrvtId> |
| 83 |
</Id> |
| 84 |
</CdtrSchmeId> |
| 85 |
<DrctDbtTxInf> |
| 86 |
<PmtId> |
| 87 |
<EndToEndId>MillerSonLtd-1234567890ab</EndToEndId> |
| 88 |
</PmtId> |
| 89 |
<InstdAmt Ccy="GBP">10.12</InstdAmt> |
| 90 |
<DrctDbtTx> |
| 91 |
<MndtRltdInf> |
| 92 |
<MndtId>1234</MndtId> |
| 93 |
<DtOfSgntr>2017-01-20</DtOfSgntr> |
| 94 |
</MndtRltdInf> |
| 95 |
</DrctDbtTx> |
| 96 |
<DbtrAgt> |
| 97 |
<FinInstnId> |
| 98 |
<BIC>BANKNL2A</BIC> |
| 99 |
</FinInstnId> |
| 100 |
</DbtrAgt> |
| 101 |
<Dbtr> |
| 102 |
<Nm>This is a test</Nm> |
| 103 |
</Dbtr> |
| 104 |
<DbtrAcct> |
| 105 |
<Id> |
| 106 |
<IBAN>NL50BANK1234567890</IBAN> |
| 107 |
</Id> |
| 108 |
</DbtrAcct> |
| 109 |
<RmtInf> |
| 110 |
<Ustrd>Test transaction</Ustrd> |
| 111 |
</RmtInf> |
| 112 |
</DrctDbtTxInf> |
| 113 |
</PmtInf> |
| 114 |
</CstmrDrctDbtInitn> |
| 115 |
</Document> |
| 116 |
""" |
| 117 |
|
| 118 |
|
| 119 |
def test_payment_overrides_currency(sdd): |
| 120 |
"""Test that payment currency overrides config currency""" |
| 121 |
payment = { |
| 122 |
"name": "This is a test", |
| 123 |
"IBAN": "NL50BANK1234567890", |
| 124 |
"BIC": "BANKNL2A", |
| 125 |
"amount": 1012, |
| 126 |
"type": "FRST", |
| 127 |
"collection_date": datetime.date.today(), |
| 128 |
"mandate_id": "1234", |
| 129 |
"mandate_date": datetime.date.today(), |
| 130 |
"description": "Test transaction", |
| 131 |
"currency": "GBP" |
| 132 |
} |
| 133 |
|
| 134 |
sdd.add_payment(payment) |
| 135 |
xmlout = sdd.export() |
| 136 |
xmlpretty = validate_xml(xmlout, "pain.008.001.02") |
| 137 |
assert clean_ids(xmlpretty.strip()) == clean_ids(SAMPLE_RESULT.strip()) |