From e33a69183e25e13eb5bcdec4ff534a6df1fad242 Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 28 Jan 2020 16:32:00 +0100 Subject: [PATCH] [IMP] server_environment_ir_config_parameter: black, isort --- .../__manifest__.py | 16 ++--- .../models/ir_config_parameter.py | 18 ++--- .../readme/CONFIGURE.rst | 2 +- .../readme/CREDITS.rst | 2 +- .../readme/DESCRIPTION.rst | 2 +- .../readme/ROADMAP.rst | 2 +- .../readme/USAGE.rst | 2 +- .../tests/test_server_environment_ircp.py | 67 ++++++++++--------- 8 files changed, 56 insertions(+), 55 deletions(-) diff --git a/server_environment_ir_config_parameter/__manifest__.py b/server_environment_ir_config_parameter/__manifest__.py index 072990d..54a7d5c 100644 --- a/server_environment_ir_config_parameter/__manifest__.py +++ b/server_environment_ir_config_parameter/__manifest__.py @@ -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"], } 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 ab44ec9..2ad3eae 100644 --- a/server_environment_ir_config_parameter/models/ir_config_parameter.py +++ b/server_environment_ir_config_parameter/models/ir_config_parameter.py @@ -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)) diff --git a/server_environment_ir_config_parameter/readme/CONFIGURE.rst b/server_environment_ir_config_parameter/readme/CONFIGURE.rst index ce786cb..03cccf5 100644 --- a/server_environment_ir_config_parameter/readme/CONFIGURE.rst +++ b/server_environment_ir_config_parameter/readme/CONFIGURE.rst @@ -14,4 +14,4 @@ For example you can use this module in combination with web_environment_ribbon: .. code:: [ir.config_parameter] - ribbon.name=DEV \ No newline at end of file + ribbon.name=DEV diff --git a/server_environment_ir_config_parameter/readme/CREDITS.rst b/server_environment_ir_config_parameter/readme/CREDITS.rst index e8134ce..c08e96d 100644 --- a/server_environment_ir_config_parameter/readme/CREDITS.rst +++ b/server_environment_ir_config_parameter/readme/CREDITS.rst @@ -1,2 +1,2 @@ This module is maintained by: -* Odoo Community Association \ No newline at end of file +* Odoo Community Association diff --git a/server_environment_ir_config_parameter/readme/DESCRIPTION.rst b/server_environment_ir_config_parameter/readme/DESCRIPTION.rst index 141459e..8ffc000 100644 --- a/server_environment_ir_config_parameter/readme/DESCRIPTION.rst +++ b/server_environment_ir_config_parameter/readme/DESCRIPTION.rst @@ -1 +1 @@ -Override System Parameters from server environment file. \ No newline at end of file +Override System Parameters from server environment file. diff --git a/server_environment_ir_config_parameter/readme/ROADMAP.rst b/server_environment_ir_config_parameter/readme/ROADMAP.rst index 42a26d8..27b704a 100644 --- a/server_environment_ir_config_parameter/readme/ROADMAP.rst +++ b/server_environment_ir_config_parameter/readme/ROADMAP.rst @@ -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. \ No newline at end of file +readonly in the user interface. diff --git a/server_environment_ir_config_parameter/readme/USAGE.rst b/server_environment_ir_config_parameter/readme/USAGE.rst index 300775c..44c0bc6 100644 --- a/server_environment_ir_config_parameter/readme/USAGE.rst +++ b/server_environment_ir_config_parameter/readme/USAGE.rst @@ -1,2 +1,2 @@ Before using this module, you must be familiar with the -server_environment module. \ No newline at end of file +server_environment module. 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 8843f79..7f5b519 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 @@ -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")