From f2be23d41f2e34e9d8853886c1abd26c784f29b3 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 9 Mar 2022 11:32:07 +0000 Subject: [PATCH] [FIX] account_statement_import_online: use unittest.mock and don't import tests at install Installing this module failed because `mock` couldn't be found. Indeed there was a migration problem. However, I was not testing the module; just installing. At install, tests shouldn't be imported. This file was being imported because the dummy model was expected to exist in database for tests. Using odoo-test-helper for that now. @moduon MT-295 --- account_statement_import_online/__init__.py | 1 - .../__manifest__.py | 3 +- ...st_account_bank_statement_import_online.py | 32 ++++++++++++------- .../tests/test_account_journal.py | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/account_statement_import_online/__init__.py b/account_statement_import_online/__init__.py index a82a91d6..adc6207f 100644 --- a/account_statement_import_online/__init__.py +++ b/account_statement_import_online/__init__.py @@ -2,4 +2,3 @@ from . import models from . import wizards -from .tests import online_bank_statement_provider_dummy diff --git a/account_statement_import_online/__manifest__.py b/account_statement_import_online/__manifest__.py index 25150d5f..177135c9 100644 --- a/account_statement_import_online/__manifest__.py +++ b/account_statement_import_online/__manifest__.py @@ -4,13 +4,14 @@ { "name": "Online Bank Statements", - "version": "14.0.2.1.0", + "version": "14.0.2.1.1", "author": "CorporateHub, Odoo Community Association (OCA)", "maintainers": ["alexey-pelykh"], "website": "https://github.com/OCA/bank-statement-import", "license": "AGPL-3", "category": "Accounting", "summary": "Online bank statements update", + "external_dependencies": {"python": ["odoo_test_helper"]}, "depends": [ "account", "account_statement_import", diff --git a/account_statement_import_online/tests/test_account_bank_statement_import_online.py b/account_statement_import_online/tests/test_account_bank_statement_import_online.py index ad132adf..7d0a5c17 100644 --- a/account_statement_import_online/tests/test_account_bank_statement_import_online.py +++ b/account_statement_import_online/tests/test_account_bank_statement_import_online.py @@ -7,6 +7,7 @@ from unittest import mock from urllib.error import HTTPError from dateutil.relativedelta import relativedelta +from odoo_test_helper import FakeModelLoader from psycopg2 import IntegrityError from odoo import fields @@ -20,18 +21,27 @@ mock_obtain_statement_data = ( ) -class TestAccountBankAccountStatementImportOnline(common.TransactionCase): - def setUp(self): - super().setUp() +class TestAccountBankAccountStatementImportOnline(common.SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() - self.now = fields.Datetime.now() - self.AccountJournal = self.env["account.journal"] - self.OnlineBankStatementProvider = self.env["online.bank.statement.provider"] - self.OnlineBankStatementPullWizard = self.env[ - "online.bank.statement.pull.wizard" - ] - self.AccountBankStatement = self.env["account.bank.statement"] - self.AccountBankStatementLine = self.env["account.bank.statement.line"] + # Load fake model + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + cls.addClassCleanup(cls.loader.restore_registry) + from .online_bank_statement_provider_dummy import ( + OnlineBankStatementProviderDummy, + ) + + cls.loader.update_registry((OnlineBankStatementProviderDummy,)) + + cls.now = fields.Datetime.now() + cls.AccountJournal = cls.env["account.journal"] + cls.OnlineBankStatementProvider = cls.env["online.bank.statement.provider"] + cls.OnlineBankStatementPullWizard = cls.env["online.bank.statement.pull.wizard"] + cls.AccountBankStatement = cls.env["account.bank.statement"] + cls.AccountBankStatementLine = cls.env["account.bank.statement.line"] def test_provider_unlink_restricted(self): journal = self.AccountJournal.create( diff --git a/account_statement_import_online/tests/test_account_journal.py b/account_statement_import_online/tests/test_account_journal.py index 476200a5..f0d63c90 100644 --- a/account_statement_import_online/tests/test_account_journal.py +++ b/account_statement_import_online/tests/test_account_journal.py @@ -1,6 +1,6 @@ # Copyright 2021 Therp BV (https://therp.nl). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from mock import patch +from unittest.mock import patch from odoo.tests import common