From ff9358da0b34fe1e352fcb66e0b2611ae5da71a9 Mon Sep 17 00:00:00 2001 From: Emanuel Cino Date: Fri, 29 Jun 2018 15:03:10 +0200 Subject: [PATCH] FIX tests of import_save_file module to avoid conflicts with others --- .../tests/test_save_file.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/account_bank_statement_import_save_file/tests/test_save_file.py b/account_bank_statement_import_save_file/tests/test_save_file.py index 3a65886..b6fbd58 100644 --- a/account_bank_statement_import_save_file/tests/test_save_file.py +++ b/account_bank_statement_import_save_file/tests/test_save_file.py @@ -9,13 +9,24 @@ from odoo.tests.common import TransactionCase acc_number = 'BE1234567890' +module_name = 'account_bank_statement_import_save_file' class HelloWorldParser(models.TransientModel): + """ Fake parser that will return custom data if the file contains the + name of the module. """ _inherit = 'account.bank.statement.import' @api.model def _parse_file(self, data_file): + if module_name in data_file: + return self._mock_parse(data_file) + else: + return super(HelloWorldParser, self)._parse_file(data_file) + + def _mock_parse(self, data_file): + """ method that can be inherited in other tests to mock a statement + parser. """ return ( 'EUR', acc_number, @@ -48,11 +59,13 @@ class TestSaveFile(TransactionCase): import_wizard = self.env['account.bank.statement.import'] journal_id = self.bank_journal_euro.id import_wizard_id = import_wizard.with_context(journal_id=journal_id)\ - .create( - {'data_file': base64.b64encode(bytes('Hello world'))}) + .create({ + 'data_file': base64.b64encode(bytes( + 'account_bank_statement_import_save_file: Hello world')) + }) action = import_wizard_id.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') + 'account_bank_statement_import_save_file: Hello world')