Browse Source
Rename module
Rename module
Also: - Use context managers for file opening/closing in tests - Changed use of deprecated `BadZipfile` exception - Removed debugging code left by mistakepull/158/head
Maxence Groine
7 years ago
28 changed files with 231 additions and 232 deletions
-
128account_bank_statement_import_camt/tests/test_import_bank_statement.py
-
0account_bank_statement_import_camt_oca/README.rst
-
0account_bank_statement_import_camt_oca/__init__.py
-
0account_bank_statement_import_camt_oca/__manifest__.py
-
6account_bank_statement_import_camt_oca/i18n/de.po
-
32account_bank_statement_import_camt_oca/i18n/es.po
-
16account_bank_statement_import_camt_oca/i18n/fi.po
-
32account_bank_statement_import_camt_oca/i18n/fr.po
-
16account_bank_statement_import_camt_oca/i18n/fr_CH.po
-
16account_bank_statement_import_camt_oca/i18n/gl.po
-
32account_bank_statement_import_camt_oca/i18n/hr.po
-
8account_bank_statement_import_camt_oca/i18n/lt_LT.po
-
16account_bank_statement_import_camt_oca/i18n/nb_NO.po
-
8account_bank_statement_import_camt_oca/i18n/nl.po
-
8account_bank_statement_import_camt_oca/i18n/pt_BR.po
-
8account_bank_statement_import_camt_oca/i18n/pt_PT.po
-
8account_bank_statement_import_camt_oca/i18n/sl.po
-
0account_bank_statement_import_camt_oca/models/__init__.py
-
2account_bank_statement_import_camt_oca/models/account_bank_statement_import.py
-
0account_bank_statement_import_camt_oca/models/parser.py
-
0account_bank_statement_import_camt_oca/test_files/golden-camt053-txdtls.pydata
-
0account_bank_statement_import_camt_oca/test_files/golden-camt053.pydata
-
0account_bank_statement_import_camt_oca/test_files/test-camt053
-
0account_bank_statement_import_camt_oca/test_files/test-camt053-txdtls
-
0account_bank_statement_import_camt_oca/test_files/test-camt053.zip
-
0account_bank_statement_import_camt_oca/tests/__init__.py
-
127account_bank_statement_import_camt_oca/tests/test_import_bank_statement.py
-
0account_bank_statement_import_camt_oca/views/account_bank_statement_import.xml
@ -1,128 +0,0 @@ |
|||||
"""Run test to import camt.053 import.""" |
|
||||
# © 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). |
|
||||
import base64 |
|
||||
import difflib |
|
||||
import pprint |
|
||||
import tempfile |
|
||||
|
|
||||
from io import StringIO |
|
||||
|
|
||||
from odoo.tests.common import TransactionCase |
|
||||
from odoo.modules.module import get_module_resource |
|
||||
|
|
||||
|
|
||||
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 _do_parse_test(self, inputfile, goldenfile): |
|
||||
print("\n\ninputfile = {} / goldenfile = {}".format(inputfile, goldenfile)) |
|
||||
testfile = get_module_resource( |
|
||||
'account_bank_statement_import_camt', |
|
||||
'test_files', |
|
||||
inputfile, |
|
||||
) |
|
||||
data = open(testfile, 'rb').read() |
|
||||
res = self.parser.parse(data) |
|
||||
with tempfile.NamedTemporaryFile(mode='w+', suffix='.pydata') as temp: |
|
||||
import ipdb; ipdb.set_trace(context=10) |
|
||||
pprint.pprint(res, temp, width=160) |
|
||||
goldenfile_res = get_module_resource( |
|
||||
'account_bank_statement_import_camt', |
|
||||
'test_files', |
|
||||
goldenfile, |
|
||||
) |
|
||||
with open(goldenfile_res, 'r') 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 expected output:\n%s" % |
|
||||
"".join(diff)) |
|
||||
|
|
||||
def test_parse(self): |
|
||||
self._do_parse_test( |
|
||||
'test-camt053', |
|
||||
'golden-camt053.pydata') |
|
||||
|
|
||||
def test_parse_txdtls(self): |
|
||||
self._do_parse_test( |
|
||||
'test-camt053-txdtls', |
|
||||
'golden-camt053-txdtls.pydata') |
|
||||
|
|
||||
|
|
||||
class TestImport(TransactionCase): |
|
||||
"""Run test to import camt import.""" |
|
||||
transactions = [ |
|
||||
{ |
|
||||
'account_number': 'NL46ABNA0499998748', |
|
||||
'amount': -754.25, |
|
||||
'date': '2014-01-05', |
|
||||
'ref': '435005714488-ABNO33052620', |
|
||||
}, |
|
||||
] |
|
||||
|
|
||||
def setUp(self): |
|
||||
super(TestImport, self).setUp() |
|
||||
bank = self.env['res.partner.bank'].create({ |
|
||||
'acc_number': 'NL77ABNA0574908765', |
|
||||
'partner_id': self.env.ref('base.main_partner').id, |
|
||||
'company_id': self.env.ref('base.main_company').id, |
|
||||
'bank_id': self.env.ref('base.res_bank_1').id, |
|
||||
}) |
|
||||
self.env['account.journal'].create({ |
|
||||
'name': 'Bank Journal - (test camt)', |
|
||||
'code': 'TBNKCAMT', |
|
||||
'type': 'bank', |
|
||||
'bank_account_id': bank.id, |
|
||||
}) |
|
||||
|
|
||||
def test_statement_import(self): |
|
||||
"""Test correct creation of single statement.""" |
|
||||
testfile = get_module_resource( |
|
||||
'account_bank_statement_import_camt', |
|
||||
'test_files', |
|
||||
'test-camt053', |
|
||||
) |
|
||||
datafile = open(testfile, 'rb').read() |
|
||||
|
|
||||
action = self.env['account.bank.statement.import'].create({ |
|
||||
'data_file': base64.b64encode(datafile) |
|
||||
}).import_file() |
|
||||
|
|
||||
for statement in self.env['account.bank.statement'].browse( |
|
||||
action['context']['statement_ids'] |
|
||||
): |
|
||||
self.assertTrue(any( |
|
||||
all( |
|
||||
line[key] == self.transactions[0][key] |
|
||||
for key in ['amount', 'date', 'ref'] |
|
||||
) and |
|
||||
line.bank_account_id.acc_number == |
|
||||
self.transactions[0]['account_number'] |
|
||||
for line in statement.line_ids |
|
||||
)) |
|
||||
|
|
||||
def test_zip_import(self): |
|
||||
"""Test import of multiple statements from zip file.""" |
|
||||
testfile = get_module_resource( |
|
||||
'account_bank_statement_import_camt', |
|
||||
'test_files', |
|
||||
'test-camt053.zip', |
|
||||
) |
|
||||
datafile = open(testfile, 'rb').read() |
|
||||
|
|
||||
action = self.env['account.bank.statement.import'].create({ |
|
||||
'data_file': base64.b64encode(datafile), |
|
||||
}).import_file() |
|
||||
|
|
||||
for statement in self.env['account.bank.statement'].browse( |
|
||||
action['context']['statement_ids'] |
|
||||
): |
|
||||
self.assertTrue(statement.line_ids) |
|
@ -0,0 +1,127 @@ |
|||||
|
"""Run test to import camt.053 import.""" |
||||
|
# © 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). |
||||
|
import base64 |
||||
|
import difflib |
||||
|
import pprint |
||||
|
import tempfile |
||||
|
|
||||
|
|
||||
|
from odoo.tests.common import TransactionCase |
||||
|
from odoo.modules.module import get_module_resource |
||||
|
|
||||
|
|
||||
|
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 _do_parse_test(self, inputfile, goldenfile): |
||||
|
testfile = get_module_resource( |
||||
|
'account_bank_statement_import_camt_oca', |
||||
|
'test_files', |
||||
|
inputfile, |
||||
|
) |
||||
|
with open(testfile, 'rb') as data: |
||||
|
res = self.parser.parse(data.read()) |
||||
|
with tempfile.NamedTemporaryFile(mode='w+', |
||||
|
suffix='.pydata') as temp: |
||||
|
pprint.pprint(res, temp, width=160) |
||||
|
goldenfile_res = get_module_resource( |
||||
|
'account_bank_statement_import_camt_oca', |
||||
|
'test_files', |
||||
|
goldenfile, |
||||
|
) |
||||
|
with open(goldenfile_res, 'r') 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 expected " + |
||||
|
"output:\n%s" % |
||||
|
"".join(diff)) |
||||
|
|
||||
|
def test_parse(self): |
||||
|
self._do_parse_test( |
||||
|
'test-camt053', |
||||
|
'golden-camt053.pydata') |
||||
|
|
||||
|
def test_parse_txdtls(self): |
||||
|
self._do_parse_test( |
||||
|
'test-camt053-txdtls', |
||||
|
'golden-camt053-txdtls.pydata') |
||||
|
|
||||
|
|
||||
|
class TestImport(TransactionCase): |
||||
|
"""Run test to import camt import.""" |
||||
|
transactions = [ |
||||
|
{ |
||||
|
'account_number': 'NL46ABNA0499998748', |
||||
|
'amount': -754.25, |
||||
|
'date': '2014-01-05', |
||||
|
'ref': '435005714488-ABNO33052620', |
||||
|
}, |
||||
|
] |
||||
|
|
||||
|
def setUp(self): |
||||
|
super(TestImport, self).setUp() |
||||
|
bank = self.env['res.partner.bank'].create({ |
||||
|
'acc_number': 'NL77ABNA0574908765', |
||||
|
'partner_id': self.env.ref('base.main_partner').id, |
||||
|
'company_id': self.env.ref('base.main_company').id, |
||||
|
'bank_id': self.env.ref('base.res_bank_1').id, |
||||
|
}) |
||||
|
self.env['account.journal'].create({ |
||||
|
'name': 'Bank Journal - (test camt)', |
||||
|
'code': 'TBNKCAMT', |
||||
|
'type': 'bank', |
||||
|
'bank_account_id': bank.id, |
||||
|
}) |
||||
|
|
||||
|
def test_statement_import(self): |
||||
|
"""Test correct creation of single statement.""" |
||||
|
testfile = get_module_resource( |
||||
|
'account_bank_statement_import_camt_oca', |
||||
|
'test_files', |
||||
|
'test-camt053', |
||||
|
) |
||||
|
with open(testfile, 'rb') as datafile: |
||||
|
action = self.env['account.bank.statement.import'].create({ |
||||
|
'data_file': base64.b64encode(datafile.read()) |
||||
|
}).import_file() |
||||
|
|
||||
|
for statement in self.env['account.bank.statement'].browse( |
||||
|
action['context']['statement_ids'] |
||||
|
): |
||||
|
self.assertTrue(any( |
||||
|
all( |
||||
|
line[key] == self.transactions[0][key] |
||||
|
for key in ['amount', 'date', 'ref'] |
||||
|
) and |
||||
|
line.bank_account_id.acc_number == |
||||
|
self.transactions[0]['account_number'] |
||||
|
for line in statement.line_ids |
||||
|
)) |
||||
|
|
||||
|
def test_zip_import(self): |
||||
|
"""Test import of multiple statements from zip file.""" |
||||
|
testfile = get_module_resource( |
||||
|
'account_bank_statement_import_camt_oca', |
||||
|
'test_files', |
||||
|
'test-camt053.zip', |
||||
|
) |
||||
|
with open(testfile, 'rb') as datafile: |
||||
|
action = self.env['account.bank.statement.import'].create({ |
||||
|
'data_file': base64.b64encode(datafile.read()), |
||||
|
}).import_file() |
||||
|
|
||||
|
for statement in self.env['account.bank.statement'].browse( |
||||
|
action['context']['statement_ids'] |
||||
|
): |
||||
|
self.assertTrue(statement.line_ids) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue