diff --git a/account_bank_statement_import_camt/test_files/golden-camt053.pydata b/account_bank_statement_import_camt/test_files/golden-camt053.pydata new file mode 100644 index 0000000..053e4ff --- /dev/null +++ b/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': '\n 754.25\n DBIT\n BOOK\n \n
2014-01-05
\n
\n \n
2014-01-05
\n
\n \n \n PMNT\n \n RDDT\n ESDD\n \n \n \n EI\n \n \n \n \n \n INNDNL2U20141231000142300002844\n 435005714488-ABNO33052620\n 1880000341866\n \n \n \n 754.25\n \n \n \n \n INSURANCE COMPANY TESTX\n \n TEST STREET 20\n 1234 AB TESTCITY\n NL\n \n \n \n \n NL46ABNA0499998748\n \n \n \n \n \n \n ABNANL2A\n \n \n \n \n Insurance policy 857239PERIOD 01.01.2014 - 31.12.2014\n \n MKB Insurance 859239PERIOD 01.01.2014 - 31.12.2014\n \n \n
\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': '\n 594.05\n DBIT\n true\n BOOK\n \n
2014-01-05
\n
\n \n
2014-01-05
\n
\n \n \n PMNT\n \n IDDT\n UPDD\n \n \n \n EIST\n \n \n \n \n \n TESTBANK/NL/20141229/01206408\n TESTBANK/NL/20141229/01206408\n NL22ZZZ524885430000-C0125.1\n \n \n \n 564.05\n \n \n \n \n Test Customer\n \n NL\n \n \n \n \n NL46ABNA0499998748\n \n \n \n \n \n \n ABNANL2A\n \n \n \n \n Direct Debit S14 0410\n \n \n \n AC06\n \n \n Direct debit S14 0410 AC07 Rek.nummer blokkade TESTBANK/NL/20141229/01206408\n \n \n
\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': '\n 1405.31\n CRDT\n BOOK\n \n
2014-01-05
\n
\n \n
2014-01-05
\n
\n \n \n PMNT\n \n RCDT\n ESCT\n \n \n \n ET\n \n \n \n \n \n INNDNL2U20140105000217200000708\n 115\n \n \n \n 1405.31\n \n \n \n \n 3rd party Media\n \n SOMESTREET 570-A\n 1276 ML HOUSCITY\n NL\n \n \n \n \n NL69ABNA0522123643\n \n \n \n \n \n \n ABNANL2A\n \n \n \n #RD PARTY MEDIA CUSNO 90782 4210773\n \n \n
\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'}]}]) diff --git a/account_bank_statement_import_camt/tests/test_import_bank_statement.py b/account_bank_statement_import_camt/tests/test_import_bank_statement.py index b043e71..a3dabdb 100644 --- a/account_bank_statement_import_camt/tests/test_import_bank_statement.py +++ b/account_bank_statement_import_camt/tests/test_import_bank_statement.py @@ -1,12 +1,42 @@ # -*- coding: utf-8 -*- """Run test to import camt.053 import.""" # © 2013-2016 Therp BV +# Copyright 2017 Open Net Sàrl # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import base64 +import difflib +import pprint +import tempfile from openerp.tests.common import TransactionCase 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): """Run test to import camt import.""" transactions = [