mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
Merge pull request #188 from hbrunn/8.0-account_bank_statement_import_save_file-fix_test
[FIX][account_bank_statement_import_save_file] don't mess with the registry for tests
This commit is contained in:
@@ -19,60 +19,52 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
import base64
|
import base64
|
||||||
from openerp import api, models
|
from mock import patch
|
||||||
from openerp.tests.common import TransactionCase
|
from openerp.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
acc_number = 'BE1234567890'
|
acc_number = 'BE1234567890'
|
||||||
|
|
||||||
|
|
||||||
class HelloWorldParser(models.TransientModel):
|
|
||||||
_inherit = 'account.bank.statement.import'
|
|
||||||
|
|
||||||
@api.model
|
|
||||||
def _parse_file(self, data_file):
|
|
||||||
return (
|
|
||||||
'EUR',
|
|
||||||
acc_number,
|
|
||||||
[{
|
|
||||||
'name': '000000123',
|
|
||||||
'date': '2013-06-26',
|
|
||||||
'transactions': [{
|
|
||||||
'name': 'KBC-INVESTERINGSKREDIET 787-5562831-01',
|
|
||||||
'date': '2013-06-26',
|
|
||||||
'amount': 42,
|
|
||||||
'unique_import_id': 'hello',
|
|
||||||
}],
|
|
||||||
}],
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestSaveFile(TransactionCase):
|
class TestSaveFile(TransactionCase):
|
||||||
def test_SaveFile(self):
|
def test_SaveFile(self):
|
||||||
HelloWorldParser._build_model(self.registry, self.cr)
|
with patch.object(
|
||||||
import_wizard = self.env['account.bank.statement.import']
|
self.env.registry
|
||||||
import_wizard._prepare_setup()
|
.models['account.bank.statement.import'].__class__,
|
||||||
import_wizard._setup_base(False)
|
'_parse_file'
|
||||||
import_wizard._setup_fields()
|
) as _parse_file:
|
||||||
import_wizard._setup_complete()
|
_parse_file.side_effect = lambda data_file: (
|
||||||
import_wizard._auto_init()
|
'EUR',
|
||||||
journal_id = self.env['res.partner.bank'].search([
|
acc_number,
|
||||||
('acc_number', '=', acc_number),
|
[{
|
||||||
]).journal_id.id
|
'name': '000000123',
|
||||||
if not journal_id:
|
'date': '2013-06-26',
|
||||||
account = import_wizard._create_bank_account(acc_number)
|
'transactions': [{
|
||||||
journal_id = self.env['account.journal']\
|
'name': 'KBC-INVESTERINGSKREDIET 787-5562831-01',
|
||||||
.search([
|
'date': '2013-06-26',
|
||||||
'|',
|
'amount': 42,
|
||||||
('currency.name', '=', 'EUR'),
|
'unique_import_id': 'hello',
|
||||||
('currency', '=', False)
|
}],
|
||||||
]).ids[0]
|
}],
|
||||||
account.journal_id = journal_id
|
)
|
||||||
action = import_wizard.with_context(journal_id=journal_id)\
|
import_wizard = self.env['account.bank.statement.import']
|
||||||
.create({'data_file': base64.b64encode('hello world')})\
|
journal_id = self.env['res.partner.bank'].search([
|
||||||
.import_file()
|
('acc_number', '=', acc_number),
|
||||||
for statement in self.env['account.bank.statement'].browse(
|
]).journal_id.id
|
||||||
action['context']['statement_ids']):
|
if not journal_id:
|
||||||
self.assertEqual(
|
account = import_wizard._create_bank_account(acc_number)
|
||||||
base64.b64decode(statement.import_file.datas),
|
journal_id = self.env['account.journal']\
|
||||||
'hello world')
|
.search([
|
||||||
|
'|',
|
||||||
|
('currency.name', '=', 'EUR'),
|
||||||
|
('currency', '=', False)
|
||||||
|
]).ids[0]
|
||||||
|
account.journal_id = journal_id
|
||||||
|
action = import_wizard.with_context(journal_id=journal_id)\
|
||||||
|
.create({'data_file': base64.b64encode('hello world')})\
|
||||||
|
.import_file()
|
||||||
|
for statement in self.env['account.bank.statement'].browse(
|
||||||
|
action['context']['statement_ids']):
|
||||||
|
self.assertEqual(
|
||||||
|
base64.b64decode(statement.import_file.datas),
|
||||||
|
'hello world')
|
||||||
|
|||||||
Reference in New Issue
Block a user