Browse Source

more complete unit tests for camt parser

This checks the whole output data of the parser against its expected
output.
pull/102/head
Louis Bettens 8 years ago
parent
commit
5ab86ab755
  1. 44
      account_bank_statement_import_camt/test_files/golden-camt053.pydata
  2. 30
      account_bank_statement_import_camt/tests/test_import_bank_statement.py

44
account_bank_statement_import_camt/test_files/golden-camt053.pydata

@ -0,0 +1,44 @@
(None,
'NL77ABNA0574908765',
[{'balance_end_real': 15121.12,
'balance_start': 15568.27,
'name': '1234Test/1',
'transactions': [{'account_bic': 'ABNANL2A',
'account_number': 'NL46ABNA0499998748',
'amount': -754.25,
'data': '<Ntry xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02">\n <Amt Ccy="EUR">754.25</Amt>\n <CdtDbtInd>DBIT</CdtDbtInd>\n <Sts>BOOK</Sts>\n <BookgDt>\n <Dt>2014-01-05</Dt>\n </BookgDt>\n <ValDt>\n <Dt>2014-01-05</Dt>\n </ValDt>\n <BkTxCd>\n <Domn>\n <Cd>PMNT</Cd>\n <Fmly>\n <Cd>RDDT</Cd>\n <SubFmlyCd>ESDD</SubFmlyCd>\n </Fmly>\n </Domn>\n <Prtry>\n <Cd>EI</Cd>\n </Prtry>\n </BkTxCd>\n <NtryDtls>\n <TxDtls>\n <Refs>\n <InstrId>INNDNL2U20141231000142300002844</InstrId>\n <EndToEndId>435005714488-ABNO33052620</EndToEndId>\n <MndtId>1880000341866</MndtId>\n </Refs>\n <AmtDtls>\n <TxAmt>\n <Amt Ccy="EUR">754.25</Amt>\n </TxAmt>\n </AmtDtls>\n <RltdPties>\n <Cdtr>\n <Nm>INSURANCE COMPANY TESTX</Nm>\n <PstlAdr>\n <StrtNm>TEST STREET 20</StrtNm>\n <TwnNm>1234 AB TESTCITY</TwnNm>\n <Ctry>NL</Ctry>\n </PstlAdr>\n </Cdtr>\n <CdtrAcct>\n <Id>\n <IBAN>NL46ABNA0499998748</IBAN>\n </Id>\n </CdtrAcct>\n </RltdPties>\n <RltdAgts>\n <CdtrAgt>\n <FinInstnId>\n <BIC>ABNANL2A</BIC>\n </FinInstnId>\n </CdtrAgt>\n </RltdAgts>\n <RmtInf>\n <Ustrd>Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014</Ustrd>\n </RmtInf>\n <AddtlTxInf>MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014</AddtlTxInf>\n </TxDtls>\n </NtryDtls>\n </Ntry>\n ',
'date': '2014-01-05',
'execution_date': '2014-01-05',
'name': 'MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014',
'note': 'Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014',
'partner_country': 'NL',
'partner_name': 'INSURANCE COMPANY TESTX',
'ref': '435005714488-ABNO33052620',
'transfer_type': 'EI',
'value_date': '2014-01-05'},
{'account_bic': 'ABNANL2A',
'account_number': 'NL46ABNA0499998748',
'amount': -594.05,
'data': '<Ntry xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02">\n <Amt Ccy="EUR">594.05</Amt>\n <CdtDbtInd>DBIT</CdtDbtInd>\n <RvslInd>true</RvslInd>\n <Sts>BOOK</Sts>\n <BookgDt>\n <Dt>2014-01-05</Dt>\n </BookgDt>\n <ValDt>\n <Dt>2014-01-05</Dt>\n </ValDt>\n <BkTxCd>\n <Domn>\n <Cd>PMNT</Cd>\n <Fmly>\n <Cd>IDDT</Cd>\n <SubFmlyCd>UPDD</SubFmlyCd>\n </Fmly>\n </Domn>\n <Prtry>\n <Cd>EIST</Cd>\n </Prtry>\n </BkTxCd>\n <NtryDtls>\n <TxDtls>\n <Refs>\n <InstrId>TESTBANK/NL/20141229/01206408</InstrId>\n <EndToEndId>TESTBANK/NL/20141229/01206408</EndToEndId>\n <MndtId>NL22ZZZ524885430000-C0125.1</MndtId>\n </Refs>\n <AmtDtls>\n <TxAmt>\n <Amt Ccy="EUR">564.05</Amt>\n </TxAmt>\n </AmtDtls>\n <RltdPties>\n <Cdtr>\n <Nm>Test Customer</Nm>\n <PstlAdr>\n <Ctry>NL</Ctry>\n </PstlAdr>\n </Cdtr>\n <CdtrAcct>\n <Id>\n <IBAN>NL46ABNA0499998748</IBAN>\n </Id>\n </CdtrAcct>\n </RltdPties>\n <RltdAgts>\n <CdtrAgt>\n <FinInstnId>\n <BIC>ABNANL2A</BIC>\n </FinInstnId>\n </CdtrAgt>\n </RltdAgts>\n <RmtInf>\n <Ustrd>Direct Debit S14 0410</Ustrd>\n </RmtInf>\n <RtrInf>\n <Rsn>\n <Cd>AC06</Cd>\n </Rsn>\n </RtrInf>\n <AddtlTxInf>Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408</AddtlTxInf>\n </TxDtls>\n </NtryDtls>\n </Ntry>\n ',
'date': '2014-01-05',
'execution_date': '2014-01-05',
'name': 'Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408',
'note': 'Direct Debit S14 0410',
'partner_country': 'NL',
'partner_name': 'Test Customer',
'ref': 'TESTBANK/NL/20141229/01206408',
'transfer_type': 'EIST',
'value_date': '2014-01-05'},
{'account_bic': 'ABNANL2A',
'account_number': 'NL69ABNA0522123643',
'amount': 1405.31,
'data': '<Ntry xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02">\n <Amt Ccy="EUR">1405.31</Amt>\n <CdtDbtInd>CRDT</CdtDbtInd>\n <Sts>BOOK</Sts>\n <BookgDt>\n <Dt>2014-01-05</Dt>\n </BookgDt>\n <ValDt>\n <Dt>2014-01-05</Dt>\n </ValDt>\n <BkTxCd>\n <Domn>\n <Cd>PMNT</Cd>\n <Fmly>\n <Cd>RCDT</Cd>\n <SubFmlyCd>ESCT</SubFmlyCd>\n </Fmly>\n </Domn>\n <Prtry>\n <Cd>ET</Cd>\n </Prtry>\n </BkTxCd>\n <NtryDtls>\n <TxDtls>\n <Refs>\n <InstrId>INNDNL2U20140105000217200000708</InstrId>\n <EndToEndId>115</EndToEndId>\n </Refs>\n <AmtDtls>\n <TxAmt>\n <Amt Ccy="EUR">1405.31</Amt>\n </TxAmt>\n </AmtDtls>\n <RltdPties>\n <Dbtr>\n <Nm>3rd party Media</Nm>\n <PstlAdr>\n <StrtNm>SOMESTREET 570-A</StrtNm>\n <TwnNm>1276 ML HOUSCITY</TwnNm>\n <Ctry>NL</Ctry>\n </PstlAdr>\n </Dbtr>\n <DbtrAcct>\n <Id>\n <IBAN>NL69ABNA0522123643</IBAN>\n </Id>\n </DbtrAcct>\n </RltdPties>\n <RltdAgts>\n <DbtrAgt>\n <FinInstnId>\n <BIC>ABNANL2A</BIC>\n </FinInstnId>\n </DbtrAgt>\n </RltdAgts>\n <AddtlTxInf>#RD PARTY MEDIA CUSNO 90782 4210773</AddtlTxInf>\n </TxDtls>\n </NtryDtls>\n </Ntry>\n ',
'date': '2014-01-05',
'execution_date': '2014-01-05',
'name': '#RD PARTY MEDIA CUSNO 90782 4210773',
'note': 'INNDNL2U20140105000217200000708',
'partner_country': 'NL',
'partner_name': '3rd party Media',
'ref': '115',
'transfer_type': 'ET',
'value_date': '2014-01-05'}]}])

30
account_bank_statement_import_camt/tests/test_import_bank_statement.py

@ -1,12 +1,42 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Run test to import camt.053 import.""" """Run test to import camt.053 import."""
# © 2013-2016 Therp BV <http://therp.nl> # © 2013-2016 Therp BV <http://therp.nl>
# Copyright 2017 Open Net Sàrl
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import base64 import base64
import difflib
import pprint
import tempfile
from openerp.tests.common import TransactionCase from openerp.tests.common import TransactionCase
from openerp.tools.misc import file_open from openerp.tools.misc import file_open
class TestParser(TransactionCase):
"""Tests for the camt parser itself."""
def setUp(self):
super(TestParser, self).setUp()
self.parser = self.env['account.bank.statement.import.camt.parser']
def test_parse(self):
with file_open(
'account_bank_statement_import_camt/test_files/test-camt053'
) as testfile:
data = testfile.read()
res = self.parser.parse(data)
with tempfile.NamedTemporaryFile(suffix='.pydata') as temp:
pprint.pprint(res, temp)
with file_open('account_bank_statement_import_camt/test_files/'
'golden-camt053.pydata') as golden:
temp.seek(0)
diff = list(
difflib.unified_diff(golden.readlines(), temp.readlines(),
golden.name, temp.name))
if len(diff) > 2:
self.fail(
"actual output doesn't match exptected output:\n%s" %
"".join(diff))
class TestImport(TransactionCase): class TestImport(TransactionCase):
"""Run test to import camt import.""" """Run test to import camt import."""
transactions = [ transactions = [

Loading…
Cancel
Save