From 6495d9ffce2304fb50cf22d9242ef74ebe8a6eeb Mon Sep 17 00:00:00 2001 From: Thierry Ducrest Date: Thu, 15 Nov 2018 15:39:30 +0100 Subject: [PATCH] [MIG] fix tests Manual forward port of 11.0 migration commit by Thierry Ducrest. --- .../__manifest__.py | 6 ++-- .../models/ir_config_parameter.py | 8 +++--- .../readme/CONTRIBUTORS.rst | 3 +- .../tests/config_param_test.xml | 6 ++++ .../tests/test_server_environment_ircp.py | 28 +++++++++---------- 5 files changed, 29 insertions(+), 22 deletions(-) create mode 100644 server_environment_ir_config_parameter/tests/config_param_test.xml diff --git a/server_environment_ir_config_parameter/__manifest__.py b/server_environment_ir_config_parameter/__manifest__.py index 65c790e..a0dd28a 100644 --- a/server_environment_ir_config_parameter/__manifest__.py +++ b/server_environment_ir_config_parameter/__manifest__.py @@ -1,4 +1,4 @@ -# Copyright 2016 ACSONE SA/NV +# Copyright 2016-2018 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { @@ -7,8 +7,8 @@ Override System Parameters from server environment file""", 'version': '12.0.1.0.0', 'license': 'AGPL-3', - 'author': 'ACSONE SA/NV,Odoo Community Association (OCA)', - 'website': 'https://odoo-community.org/', + 'author': 'ACSONE SA/NV, Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/server-env/', 'depends': [ 'server_environment', ], diff --git a/server_environment_ir_config_parameter/models/ir_config_parameter.py b/server_environment_ir_config_parameter/models/ir_config_parameter.py index c0f18e2..29ddc44 100644 --- a/server_environment_ir_config_parameter/models/ir_config_parameter.py +++ b/server_environment_ir_config_parameter/models/ir_config_parameter.py @@ -1,4 +1,4 @@ -# Copyright 2016 ACSONE SA/NV +# Copyright 2016-2018 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, models, _ @@ -15,7 +15,7 @@ class IrConfigParameter(models.Model): @api.model def get_param(self, key, default=False): - value = super(IrConfigParameter, self).get_param(key, default=None) + value = super().get_param(key, default=None) if serv_config.has_option(SECTION, key): cvalue = serv_config.get(SECTION, key) if not cvalue: @@ -39,7 +39,7 @@ class IrConfigParameter(models.Model): if serv_config.has_option(SECTION, key): # enforce value from config file vals = dict(vals, value=serv_config.get(SECTION, key)) - return super(IrConfigParameter, self).create(vals) + return super().create(vals) @api.multi def write(self, vals): @@ -50,5 +50,5 @@ class IrConfigParameter(models.Model): newvals = dict(vals, value=serv_config.get(SECTION, key)) else: newvals = vals - super(IrConfigParameter, rec).write(newvals) + super().write(newvals) return True diff --git a/server_environment_ir_config_parameter/readme/CONTRIBUTORS.rst b/server_environment_ir_config_parameter/readme/CONTRIBUTORS.rst index 0ac3128..c3ae88d 100644 --- a/server_environment_ir_config_parameter/readme/CONTRIBUTORS.rst +++ b/server_environment_ir_config_parameter/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Stéphane Bidoul (https://acsone.eu) -* Gilles Meyomesse (https://acsone.eu) \ No newline at end of file +* Thierry Ducrest +* Gilles Meyomesse (https://acsone.eu) diff --git a/server_environment_ir_config_parameter/tests/config_param_test.xml b/server_environment_ir_config_parameter/tests/config_param_test.xml new file mode 100644 index 0000000..61303a8 --- /dev/null +++ b/server_environment_ir_config_parameter/tests/config_param_test.xml @@ -0,0 +1,6 @@ + + + ircp_from_config + value_from_xml + + diff --git a/server_environment_ir_config_parameter/tests/test_server_environment_ircp.py b/server_environment_ir_config_parameter/tests/test_server_environment_ircp.py index 31fd4d7..8843f79 100644 --- a/server_environment_ir_config_parameter/tests/test_server_environment_ircp.py +++ b/server_environment_ir_config_parameter/tests/test_server_environment_ircp.py @@ -1,19 +1,24 @@ -# Copyright 2016 ACSONE SA/NV +# Copyright 2016-2018 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from cStringIO import StringIO - from odoo.exceptions import UserError from odoo.tests import common -from odoo.tools import convert +from odoo.tools import convert_file +from odoo.modules.module import get_resource_path class TestEnv(common.TransactionCase): def setUp(self): - super(TestEnv, self).setUp() + super().setUp() self.ICP = self.env['ir.config_parameter'] + def _load_xml(self, module, filepath): + convert_file( + self.env.cr, module, + get_resource_path(module, filepath), + {}, mode='init', noupdate=False, kind='test') + def test_get_param(self): """ Get system parameter from config """ # it's not in db @@ -67,14 +72,9 @@ class TestEnv(common.TransactionCase): self.assertEqual(self.ICP.get_param('ircp_nonexistant'), False) def test_override_xmldata(self): - xml = """ - - - ircp_from_config - value_from_xml - - - """ - convert.convert_xml_import(self.env.cr, 'testmodule', StringIO(xml)) + self._load_xml( + 'server_environment_ir_config_parameter', + 'tests/config_param_test.xml' + ) value = self.ICP.get_param('ircp_from_config') self.assertEqual(value, 'config_value')