[MIG] fix tests
Manual forward port of 11.0 migration commit by Thierry Ducrest.
This commit is contained in:
parent
5d77a38c31
commit
6495d9ffce
|
|
@ -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).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
Override System Parameters from server environment file""",
|
Override System Parameters from server environment file""",
|
||||||
'version': '12.0.1.0.0',
|
'version': '12.0.1.0.0',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
|
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
|
||||||
'website': 'https://odoo-community.org/',
|
'website': 'https://github.com/OCA/server-env/',
|
||||||
'depends': [
|
'depends': [
|
||||||
'server_environment',
|
'server_environment',
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -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).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import api, models, _
|
from odoo import api, models, _
|
||||||
|
|
@ -15,7 +15,7 @@ class IrConfigParameter(models.Model):
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_param(self, key, default=False):
|
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):
|
if serv_config.has_option(SECTION, key):
|
||||||
cvalue = serv_config.get(SECTION, key)
|
cvalue = serv_config.get(SECTION, key)
|
||||||
if not cvalue:
|
if not cvalue:
|
||||||
|
|
@ -39,7 +39,7 @@ class IrConfigParameter(models.Model):
|
||||||
if serv_config.has_option(SECTION, key):
|
if serv_config.has_option(SECTION, key):
|
||||||
# enforce value from config file
|
# enforce value from config file
|
||||||
vals = dict(vals, value=serv_config.get(SECTION, key))
|
vals = dict(vals, value=serv_config.get(SECTION, key))
|
||||||
return super(IrConfigParameter, self).create(vals)
|
return super().create(vals)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
|
@ -50,5 +50,5 @@ class IrConfigParameter(models.Model):
|
||||||
newvals = dict(vals, value=serv_config.get(SECTION, key))
|
newvals = dict(vals, value=serv_config.get(SECTION, key))
|
||||||
else:
|
else:
|
||||||
newvals = vals
|
newvals = vals
|
||||||
super(IrConfigParameter, rec).write(newvals)
|
super().write(newvals)
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
* Stéphane Bidoul <stephane.bidoul@acsone.eu> (https://acsone.eu)
|
* Stéphane Bidoul <stephane.bidoul@acsone.eu> (https://acsone.eu)
|
||||||
* Gilles Meyomesse <gilles.meyomesse@acsone.eu> (https://acsone.eu)
|
* Thierry Ducrest <thierry.ducrest@camptocamp.com>
|
||||||
|
* Gilles Meyomesse <gilles.meyomesse@acsone.eu> (https://acsone.eu)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<odoo>
|
||||||
|
<record model="ir.config_parameter" id="some_record_id">
|
||||||
|
<field name="key">ircp_from_config</field>
|
||||||
|
<field name="value">value_from_xml</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
|
|
@ -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).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from cStringIO import StringIO
|
|
||||||
|
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
from odoo.tests import common
|
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):
|
class TestEnv(common.TransactionCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestEnv, self).setUp()
|
super().setUp()
|
||||||
self.ICP = self.env['ir.config_parameter']
|
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):
|
def test_get_param(self):
|
||||||
""" Get system parameter from config """
|
""" Get system parameter from config """
|
||||||
# it's not in db
|
# it's not in db
|
||||||
|
|
@ -67,14 +72,9 @@ class TestEnv(common.TransactionCase):
|
||||||
self.assertEqual(self.ICP.get_param('ircp_nonexistant'), False)
|
self.assertEqual(self.ICP.get_param('ircp_nonexistant'), False)
|
||||||
|
|
||||||
def test_override_xmldata(self):
|
def test_override_xmldata(self):
|
||||||
xml = """<odoo>
|
self._load_xml(
|
||||||
<data>
|
'server_environment_ir_config_parameter',
|
||||||
<record model="ir.config_parameter" id="some_record_id">
|
'tests/config_param_test.xml'
|
||||||
<field name="key">ircp_from_config</field>
|
)
|
||||||
<field name="value">value_from_xml</field>
|
|
||||||
</record>
|
|
||||||
</data>
|
|
||||||
</odoo>"""
|
|
||||||
convert.convert_xml_import(self.env.cr, 'testmodule', StringIO(xml))
|
|
||||||
value = self.ICP.get_param('ircp_from_config')
|
value = self.ICP.get_param('ircp_from_config')
|
||||||
self.assertEqual(value, 'config_value')
|
self.assertEqual(value, 'config_value')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue