@ -1,4 +1,3 @@
# -*- 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
# Copyright 2017 Open Net Sàrl
@ -8,11 +7,10 @@ import difflib
import pprint
import pprint
import tempfile
import tempfile
from odoo.tests.common import TransactionCase
from odoo.tools.misc import file_open
from io import StringIO
DATA_DIR = ' account_bank_statement_import_camt/test_files/ '
from odoo.tests.common import TransactionCase
from odoo.modules.module import get_module_resource
class TestParser ( TransactionCase ) :
class TestParser ( TransactionCase ) :
@ -22,30 +20,41 @@ class TestParser(TransactionCase):
self . parser = self . env [ ' account.bank.statement.import.camt.parser ' ]
self . parser = self . env [ ' account.bank.statement.import.camt.parser ' ]
def _do_parse_test ( self , inputfile , goldenfile ) :
def _do_parse_test ( self , inputfile , goldenfile ) :
with file_open ( inputfile ) as testfile :
data = testfile . read ( )
print ( " \n \n inputfile = {} / 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 )
res = self . parser . parse ( data )
with tempfile . NamedTemporaryFile ( suffix = ' .pydata ' ) as temp :
pprint . pprint ( res , temp )
with file_open ( goldenfile ) as golden :
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 )
temp . seek ( 0 )
diff = list (
diff = list (
difflib . unified_diff ( golden . readlines ( ) , temp . readlines ( ) ,
difflib . unified_diff ( golden . readlines ( ) , temp . readlines ( ) ,
golden . name , temp . name ) )
golden . name , temp . name ) )
if len ( diff ) > 2 :
if len ( diff ) > 2 :
self . fail (
self . fail (
" actual output doesn ' t match expt ected output: \n %s " %
" actual output doesn ' t match expected output: \n %s " %
" " . join ( diff ) )
" " . join ( diff ) )
def test_parse ( self ) :
def test_parse ( self ) :
self . _do_parse_test (
self . _do_parse_test (
DATA_DIR + ' test-camt053 ' ,
DATA_DIR + ' golden-camt053.pydata ' )
' test-camt053 ' ,
' golden-camt053.pydata ' )
def test_parse_txdtls ( self ) :
def test_parse_txdtls ( self ) :
self . _do_parse_test (
self . _do_parse_test (
DATA_DIR + ' test-camt053-txdtls ' ,
DATA_DIR + ' golden-camt053-txdtls.pydata ' )
' test-camt053-txdtls ' ,
' golden-camt053-txdtls.pydata ' )
class TestImport ( TransactionCase ) :
class TestImport ( TransactionCase ) :
@ -76,11 +85,17 @@ class TestImport(TransactionCase):
def test_statement_import ( self ) :
def test_statement_import ( self ) :
""" Test correct creation of single statement. """
""" Test correct creation of single statement. """
action = { }
with file_open ( DATA_DIR + ' test-camt053 ' ) as testfile :
action = self . env [ ' account.bank.statement.import ' ] . create ( {
' data_file ' : base64 . b64encode ( testfile . read ( ) ) ,
} ) . import_file ( )
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 (
for statement in self . env [ ' account.bank.statement ' ] . browse (
action [ ' context ' ] [ ' statement_ids ' ]
action [ ' context ' ] [ ' statement_ids ' ]
) :
) :
@ -96,12 +111,17 @@ class TestImport(TransactionCase):
def test_zip_import ( self ) :
def test_zip_import ( self ) :
""" Test import of multiple statements from zip file. """
""" Test import of multiple statements from zip file. """
with file_open (
' account_bank_statement_import_camt/test_files/test-camt053.zip '
) as testfile :
action = self . env [ ' account.bank.statement.import ' ] . create ( {
' data_file ' : base64 . b64encode ( testfile . read ( ) ) ,
} ) . import_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 (
for statement in self . env [ ' account.bank.statement ' ] . browse (
action [ ' context ' ] [ ' statement_ids ' ]
action [ ' context ' ] [ ' statement_ids ' ]
) :
) :