[IMP] server_environment_ir_config_parameter: black, isort
This commit is contained in:
parent
783f41d1cb
commit
e33a69183e
|
|
@ -2,14 +2,12 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Server Environment Ir Config Parameter',
|
||||
'summary': """
|
||||
"name": "Server Environment Ir Config Parameter",
|
||||
"summary": """
|
||||
Override System Parameters from server environment file""",
|
||||
'version': '13.0.1.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
|
||||
'website': 'https://github.com/OCA/server-env/',
|
||||
'depends': [
|
||||
'server_environment',
|
||||
],
|
||||
"version": "13.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/server-env/",
|
||||
"depends": ["server_environment"],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
# Copyright 2016-2018 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, models, _
|
||||
from odoo import _, api, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from odoo.addons.server_environment import serv_config
|
||||
|
||||
|
||||
SECTION = 'ir.config_parameter'
|
||||
SECTION = "ir.config_parameter"
|
||||
|
||||
|
||||
class IrConfigParameter(models.Model):
|
||||
|
||||
_inherit = 'ir.config_parameter'
|
||||
_inherit = "ir.config_parameter"
|
||||
|
||||
@api.model
|
||||
def get_param(self, key, default=False):
|
||||
|
|
@ -19,9 +19,9 @@ class IrConfigParameter(models.Model):
|
|||
if serv_config.has_option(SECTION, key):
|
||||
cvalue = serv_config.get(SECTION, key)
|
||||
if not cvalue:
|
||||
raise UserError(_("Key %s is empty in "
|
||||
"server_environment_file") %
|
||||
(key, ))
|
||||
raise UserError(
|
||||
_("Key %s is empty in " "server_environment_file") % (key,)
|
||||
)
|
||||
if cvalue != value:
|
||||
# we write in db on first access;
|
||||
# should we have preloaded values in database at,
|
||||
|
|
@ -35,7 +35,7 @@ class IrConfigParameter(models.Model):
|
|||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
key = vals.get('key')
|
||||
key = vals.get("key")
|
||||
if serv_config.has_option(SECTION, key):
|
||||
# enforce value from config file
|
||||
vals = dict(vals, value=serv_config.get(SECTION, key))
|
||||
|
|
@ -43,7 +43,7 @@ class IrConfigParameter(models.Model):
|
|||
|
||||
def write(self, vals):
|
||||
for rec in self:
|
||||
key = vals.get('key') or rec.key
|
||||
key = vals.get("key") or rec.key
|
||||
if serv_config.has_option(SECTION, key):
|
||||
# enforce value from config file
|
||||
newvals = dict(vals, value=serv_config.get(SECTION, key))
|
||||
|
|
|
|||
|
|
@ -14,4 +14,4 @@ For example you can use this module in combination with web_environment_ribbon:
|
|||
.. code::
|
||||
|
||||
[ir.config_parameter]
|
||||
ribbon.name=DEV
|
||||
ribbon.name=DEV
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
This module is maintained by:
|
||||
* Odoo Community Association
|
||||
* Odoo Community Association
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Override System Parameters from server environment file.
|
||||
Override System Parameters from server environment file.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
When the user modifies System Parameters that are defined in the config
|
||||
file, the changes are ignored. It would be nice to display which system
|
||||
parameters come from the config file and possibly make their key and value
|
||||
readonly in the user interface.
|
||||
readonly in the user interface.
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
Before using this module, you must be familiar with the
|
||||
server_environment module.
|
||||
server_environment module.
|
||||
|
|
|
|||
|
|
@ -2,79 +2,82 @@
|
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.modules.module import get_resource_path
|
||||
from odoo.tests import common
|
||||
from odoo.tools import convert_file
|
||||
from odoo.modules.module import get_resource_path
|
||||
|
||||
|
||||
class TestEnv(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
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,
|
||||
self.env.cr,
|
||||
module,
|
||||
get_resource_path(module, filepath),
|
||||
{}, mode='init', noupdate=False, kind='test')
|
||||
{},
|
||||
mode="init",
|
||||
noupdate=False,
|
||||
kind="test",
|
||||
)
|
||||
|
||||
def test_get_param(self):
|
||||
""" Get system parameter from config """
|
||||
# it's not in db
|
||||
res = self.ICP.search([('key', '=', 'ircp_from_config')])
|
||||
res = self.ICP.search([("key", "=", "ircp_from_config")])
|
||||
self.assertFalse(res)
|
||||
# read so it's created in db
|
||||
value = self.ICP.get_param('ircp_from_config')
|
||||
self.assertEqual(value, 'config_value')
|
||||
value = self.ICP.get_param("ircp_from_config")
|
||||
self.assertEqual(value, "config_value")
|
||||
# now it's in db
|
||||
res = self.ICP.search([('key', '=', 'ircp_from_config')])
|
||||
res = self.ICP.search([("key", "=", "ircp_from_config")])
|
||||
self.assertEqual(len(res), 1)
|
||||
self.assertEqual(res.value, 'config_value')
|
||||
self.assertEqual(res.value, "config_value")
|
||||
|
||||
def test_set_param_1(self):
|
||||
""" We can't set parameters that are in config file """
|
||||
# when creating, the value is overridden by config file
|
||||
self.ICP.set_param('ircp_from_config', 'new_value')
|
||||
value = self.ICP.get_param('ircp_from_config')
|
||||
self.assertEqual(value, 'config_value')
|
||||
self.ICP.set_param("ircp_from_config", "new_value")
|
||||
value = self.ICP.get_param("ircp_from_config")
|
||||
self.assertEqual(value, "config_value")
|
||||
# when writing, the value is overridden by config file
|
||||
res = self.ICP.search([('key', '=', 'ircp_from_config')])
|
||||
res = self.ICP.search([("key", "=", "ircp_from_config")])
|
||||
self.assertEqual(len(res), 1)
|
||||
res.write({'value': 'new_value'})
|
||||
value = self.ICP.get_param('ircp_from_config')
|
||||
self.assertEqual(value, 'config_value')
|
||||
res.write({"value": "new_value"})
|
||||
value = self.ICP.get_param("ircp_from_config")
|
||||
self.assertEqual(value, "config_value")
|
||||
# unlink works normally...
|
||||
res = self.ICP.search([('key', '=', 'ircp_from_config')])
|
||||
res = self.ICP.search([("key", "=", "ircp_from_config")])
|
||||
self.assertEqual(len(res), 1)
|
||||
res.unlink()
|
||||
res = self.ICP.search([('key', '=', 'ircp_from_config')])
|
||||
res = self.ICP.search([("key", "=", "ircp_from_config")])
|
||||
self.assertEqual(len(res), 0)
|
||||
# but the value is recreated when getting param again
|
||||
value = self.ICP.get_param('ircp_from_config')
|
||||
self.assertEqual(value, 'config_value')
|
||||
res = self.ICP.search([('key', '=', 'ircp_from_config')])
|
||||
value = self.ICP.get_param("ircp_from_config")
|
||||
self.assertEqual(value, "config_value")
|
||||
res = self.ICP.search([("key", "=", "ircp_from_config")])
|
||||
self.assertEqual(len(res), 1)
|
||||
|
||||
def test_set_param_2(self):
|
||||
""" We can set parameters that are not in config file """
|
||||
self.ICP.set_param('some.param', 'new_value')
|
||||
self.assertEqual(self.ICP.get_param('some.param'), 'new_value')
|
||||
res = self.ICP.search([('key', '=', 'some.param')])
|
||||
self.ICP.set_param("some.param", "new_value")
|
||||
self.assertEqual(self.ICP.get_param("some.param"), "new_value")
|
||||
res = self.ICP.search([("key", "=", "some.param")])
|
||||
res.unlink()
|
||||
res = self.ICP.search([('key', '=', 'some.param')])
|
||||
res = self.ICP.search([("key", "=", "some.param")])
|
||||
self.assertFalse(res)
|
||||
|
||||
def test_empty(self):
|
||||
""" Empty config values cause error """
|
||||
with self.assertRaises(UserError):
|
||||
self.ICP.get_param('ircp_empty')
|
||||
self.assertEqual(self.ICP.get_param('ircp_nonexistant'), False)
|
||||
self.ICP.get_param("ircp_empty")
|
||||
self.assertEqual(self.ICP.get_param("ircp_nonexistant"), False)
|
||||
|
||||
def test_override_xmldata(self):
|
||||
self._load_xml(
|
||||
'server_environment_ir_config_parameter',
|
||||
'tests/config_param_test.xml'
|
||||
"server_environment_ir_config_parameter", "tests/config_param_test.xml"
|
||||
)
|
||||
value = self.ICP.get_param('ircp_from_config')
|
||||
self.assertEqual(value, 'config_value')
|
||||
value = self.ICP.get_param("ircp_from_config")
|
||||
self.assertEqual(value, "config_value")
|
||||
|
|
|
|||
Loading…
Reference in New Issue