[FIX] tests
This commit is contained in:
parent
c6c2de8269
commit
f975770466
|
|
@ -8,8 +8,7 @@ from unittest.mock import patch
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
from odoo.addons.server_environment import server_env
|
from odoo.addons.server_environment import server_env
|
||||||
|
|
||||||
import odoo.addons.server_environment.models.server_env_mixin as \
|
import odoo.addons.server_environment.models.server_env_mixin as server_env_mixin
|
||||||
server_env_mixin
|
|
||||||
|
|
||||||
|
|
||||||
class ServerEnvironmentCase(common.SavepointCase):
|
class ServerEnvironmentCase(common.SavepointCase):
|
||||||
|
|
@ -36,14 +35,13 @@ class ServerEnvironmentCase(common.SavepointCase):
|
||||||
yield
|
yield
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def load_config(self, public=None, secret=None):
|
def load_config(self, public=None, secret=None, serv_config_class=server_env_mixin):
|
||||||
original_serv_config = server_env_mixin.serv_config
|
original_serv_config = serv_config_class.serv_config
|
||||||
try:
|
try:
|
||||||
with self.set_config_dir(None), \
|
with self.set_config_dir(None), self.set_env_variables(public, secret):
|
||||||
self.set_env_variables(public, secret):
|
|
||||||
parser = server_env._load_config()
|
parser = server_env._load_config()
|
||||||
server_env_mixin.serv_config = parser
|
serv_config_class.serv_config = parser
|
||||||
yield
|
yield
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
server_env_mixin.serv_config = original_serv_config
|
serv_config_class.serv_config = original_serv_config
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,21 @@
|
||||||
# Copyright 2016-2018 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.tests import common
|
from odoo.exceptions import UserError
|
||||||
from odoo.tools import convert_file
|
from odoo.tools import convert_file
|
||||||
from odoo.modules.module import get_resource_path
|
from odoo.modules.module import get_resource_path
|
||||||
from odoo.exceptions import UserError
|
from odoo.addons.server_environment.tests.common import ServerEnvironmentCase
|
||||||
|
|
||||||
|
from ..models import ir_config_parameter
|
||||||
|
|
||||||
|
|
||||||
class TestEnv(common.TransactionCase):
|
class TestEnv(ServerEnvironmentCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.ICP = self.env['ir.config_parameter']
|
self.ICP = self.env['ir.config_parameter']
|
||||||
|
self.env_config = (
|
||||||
|
"[ir.config_parameter]\n" "ircp_from_config=config_value\n" "ircp_empty=\n"
|
||||||
|
)
|
||||||
|
|
||||||
def _load_xml(self, module, filepath):
|
def _load_xml(self, module, filepath):
|
||||||
convert_file(
|
convert_file(
|
||||||
|
|
@ -21,6 +25,9 @@ class TestEnv(common.TransactionCase):
|
||||||
|
|
||||||
def test_get_param(self):
|
def test_get_param(self):
|
||||||
""" Get system parameter from config """
|
""" Get system parameter from config """
|
||||||
|
with self.load_config(
|
||||||
|
public=self.env_config, serv_config_class=ir_config_parameter
|
||||||
|
):
|
||||||
# it's not in db
|
# it's not in db
|
||||||
res = self.ICP.search([('key', '=', 'ircp_from_config')])
|
res = self.ICP.search([('key', '=', 'ircp_from_config')])
|
||||||
self.assertFalse(res)
|
self.assertFalse(res)
|
||||||
|
|
@ -34,6 +41,9 @@ class TestEnv(common.TransactionCase):
|
||||||
|
|
||||||
def test_set_param_1(self):
|
def test_set_param_1(self):
|
||||||
""" We can't set parameters that are in config file """
|
""" We can't set parameters that are in config file """
|
||||||
|
with self.load_config(
|
||||||
|
public=self.env_config, serv_config_class=ir_config_parameter
|
||||||
|
):
|
||||||
# when creating, the value is overridden by config file
|
# when creating, the value is overridden by config file
|
||||||
self.ICP.set_param('ircp_from_config', 'new_value')
|
self.ICP.set_param('ircp_from_config', 'new_value')
|
||||||
value = self.ICP.get_param('ircp_from_config')
|
value = self.ICP.get_param('ircp_from_config')
|
||||||
|
|
@ -58,6 +68,9 @@ class TestEnv(common.TransactionCase):
|
||||||
|
|
||||||
def test_set_param_2(self):
|
def test_set_param_2(self):
|
||||||
""" We can set parameters that are not in config file """
|
""" We can set parameters that are not in config file """
|
||||||
|
with self.load_config(
|
||||||
|
public=self.env_config, serv_config_class=ir_config_parameter
|
||||||
|
):
|
||||||
self.ICP.set_param('some.param', 'new_value')
|
self.ICP.set_param('some.param', 'new_value')
|
||||||
self.assertEqual(self.ICP.get_param('some.param'), 'new_value')
|
self.assertEqual(self.ICP.get_param('some.param'), 'new_value')
|
||||||
res = self.ICP.search([('key', '=', 'some.param')])
|
res = self.ICP.search([('key', '=', 'some.param')])
|
||||||
|
|
@ -67,11 +80,17 @@ class TestEnv(common.TransactionCase):
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
""" Empty config values cause error """
|
""" Empty config values cause error """
|
||||||
|
with self.load_config(
|
||||||
|
public=self.env_config, serv_config_class=ir_config_parameter
|
||||||
|
):
|
||||||
with self.assertRaises(UserError):
|
with self.assertRaises(UserError):
|
||||||
self.ICP.get_param('ircp_empty')
|
self.ICP.get_param('ircp_empty')
|
||||||
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):
|
||||||
|
with self.load_config(
|
||||||
|
public=self.env_config, serv_config_class=ir_config_parameter
|
||||||
|
):
|
||||||
self._load_xml(
|
self._load_xml(
|
||||||
'server_environment_ir_config_parameter',
|
'server_environment_ir_config_parameter',
|
||||||
'tests/config_param_test.xml'
|
'tests/config_param_test.xml'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue