[IMP] server_environment_ir_config_parameter: black, isort

This commit is contained in:
Akim Juillerat 2020-01-28 16:32:00 +01:00 committed by Marcos Oitaben
parent f02e50dd0b
commit 193f88ddac
17 changed files with 119 additions and 98 deletions

View File

@ -14,13 +14,13 @@ Server Environment Ir Config Parameter
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github
:target: https://github.com/OCA/server-env/tree/12.0/server_environment_ir_config_parameter :target: https://github.com/OCA/server-env/tree/13.0/server_environment_ir_config_parameter
:alt: OCA/server-env :alt: OCA/server-env
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-env-12-0/server-env-12-0-server_environment_ir_config_parameter :target: https://translation.odoo-community.org/projects/server-env-13-0/server-env-13-0-server_environment_ir_config_parameter
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/254/12.0 :target: https://runbot.odoo-community.org/runbot/254/13.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -73,7 +73,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-env/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-env/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-env/issues/new?body=module:%20server_environment_ir_config_parameter%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/server-env/issues/new?body=module:%20server_environment_ir_config_parameter%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -111,6 +111,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/server-env <https://github.com/OCA/server-env/tree/12.0/server_environment_ir_config_parameter>`_ project on GitHub. This module is part of the `OCA/server-env <https://github.com/OCA/server-env/tree/13.0/server_environment_ir_config_parameter>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -2,14 +2,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Server Environment Ir Config Parameter', "name": "Server Environment Ir Config Parameter",
'summary': """ "summary": """
Override System Parameters from server environment file""", Override System Parameters from server environment file""",
'version': '13.0.1.0.0', "version": "13.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://github.com/OCA/server-env/', "website": "https://github.com/OCA/server-env/",
'depends': [ "depends": ["server_environment"],
'server_environment',
],
} }

View File

@ -19,7 +19,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: server_environment_ir_config_parameter #. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22 #: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format #, python-format
msgid "Key %s is empty in server_environment_file" msgid "Key %s is empty in server_environment_file"
msgstr "" msgstr ""

View File

@ -19,7 +19,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: server_environment_ir_config_parameter #. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22 #: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format #, python-format
msgid "Key %s is empty in server_environment_file" msgid "Key %s is empty in server_environment_file"
msgstr "" msgstr ""

View File

@ -19,7 +19,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: server_environment_ir_config_parameter #. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22 #: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format #, python-format
msgid "Key %s is empty in server_environment_file" msgid "Key %s is empty in server_environment_file"
msgstr "" msgstr ""

View File

@ -20,7 +20,7 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: server_environment_ir_config_parameter #. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22 #: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format #, python-format
msgid "Key %s is empty in server_environment_file" msgid "Key %s is empty in server_environment_file"
msgstr "sleutel %s is leeg in server_environment_file" msgstr "sleutel %s is leeg in server_environment_file"

View File

@ -20,7 +20,7 @@ msgstr ""
"2:1));\n" "2:1));\n"
#. module: server_environment_ir_config_parameter #. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22 #: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format #, python-format
msgid "Key %s is empty in server_environment_file" msgid "Key %s is empty in server_environment_file"
msgstr "" msgstr ""

View File

@ -1,12 +1,12 @@
# Translation of Odoo Server. # Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * server_environment_ir_config_parameter # * server_environment_ir_config_parameter
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n" "Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -14,7 +14,7 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: server_environment_ir_config_parameter #. module: server_environment_ir_config_parameter
#: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:22 #: code:addons/server_environment_ir_config_parameter/models/ir_config_parameter.py:0
#, python-format #, python-format
msgid "Key %s is empty in server_environment_file" msgid "Key %s is empty in server_environment_file"
msgstr "" msgstr ""
@ -23,4 +23,3 @@ msgstr ""
#: model:ir.model,name:server_environment_ir_config_parameter.model_ir_config_parameter #: model:ir.model,name:server_environment_ir_config_parameter.model_ir_config_parameter
msgid "System Parameter" msgid "System Parameter"
msgstr "" msgstr ""

View File

@ -1,17 +1,17 @@
# 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 import api, models, _ from odoo import _, api, models
from odoo.exceptions import UserError from odoo.exceptions import UserError
from odoo.addons.server_environment import serv_config from odoo.addons.server_environment import serv_config
SECTION = "ir.config_parameter"
SECTION = 'ir.config_parameter'
class IrConfigParameter(models.Model): class IrConfigParameter(models.Model):
_inherit = 'ir.config_parameter' _inherit = "ir.config_parameter"
@api.model @api.model
def get_param(self, key, default=False): def get_param(self, key, default=False):
@ -19,9 +19,9 @@ class IrConfigParameter(models.Model):
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:
raise UserError(_("Key %s is empty in " raise UserError(
"server_environment_file") % _("Key %s is empty in " "server_environment_file") % (key,)
(key, )) )
if cvalue != value: if cvalue != value:
# we write in db on first access; # we write in db on first access;
# should we have preloaded values in database at, # should we have preloaded values in database at,
@ -35,7 +35,7 @@ class IrConfigParameter(models.Model):
@api.model @api.model
def create(self, vals): def create(self, vals):
key = vals.get('key') key = vals.get("key")
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))
@ -43,7 +43,7 @@ class IrConfigParameter(models.Model):
def write(self, vals): def write(self, vals):
for rec in self: 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): if serv_config.has_option(SECTION, key):
# enforce value from config file # enforce value from config file
newvals = dict(vals, value=serv_config.get(SECTION, key)) newvals = dict(vals, value=serv_config.get(SECTION, key))

View File

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-env/tree/12.0/server_environment_ir_config_parameter"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-env-12-0/server-env-12-0-server_environment_ir_config_parameter"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/254/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/server-env/tree/13.0/server_environment_ir_config_parameter"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/server-env-13-0/server-env-13-0-server_environment_ir_config_parameter"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/254/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>Override System Parameters from server environment file.</p> <p>Override System Parameters from server environment file.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents"> <div class="contents local topic" id="contents">
@ -418,7 +418,7 @@ readonly in the user interface.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-env/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-env/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-env/issues/new?body=module:%20server_environment_ir_config_parameter%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/server-env/issues/new?body=module:%20server_environment_ir_config_parameter%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -449,7 +449,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-env/tree/12.0/server_environment_ir_config_parameter">OCA/server-env</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-env/tree/13.0/server_environment_ir_config_parameter">OCA/server-env</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
<odoo> <odoo>
<record model="ir.config_parameter" id="some_record_id"> <record model="ir.config_parameter" id="some_record_id">
<field name="key">ircp_from_config</field> <field name="key">ircp_from_config</field>
<field name="value">value_from_xml</field> <field name="value">value_from_xml</field>
</record> </record>
</odoo> </odoo>

View File

@ -2,79 +2,103 @@
# 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.exceptions import UserError from odoo.exceptions import UserError
from odoo.tests import common
from odoo.tools import convert_file
from odoo.modules.module import get_resource_path from odoo.modules.module import get_resource_path
from odoo.tools import convert_file
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(
self.env.cr, module, self.env.cr,
module,
get_resource_path(module, filepath), get_resource_path(module, filepath),
{}, mode='init', noupdate=False, kind='test') {},
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 with self.load_config(
res = self.ICP.search([('key', '=', 'ircp_from_config')]) public=self.env_config, serv_config_class=ir_config_parameter
self.assertFalse(res) ):
# read so it's created in db # it's not in db
value = self.ICP.get_param('ircp_from_config') res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(value, 'config_value') self.assertFalse(res)
# now it's in db # read so it's created in db
res = self.ICP.search([('key', '=', 'ircp_from_config')]) value = self.ICP.get_param("ircp_from_config")
self.assertEqual(len(res), 1) self.assertEqual(value, "config_value")
self.assertEqual(res.value, 'config_value') # now it's in db
res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(len(res), 1)
self.assertEqual(res.value, "config_value")
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 """
# when creating, the value is overridden by config file with self.load_config(
self.ICP.set_param('ircp_from_config', 'new_value') public=self.env_config, serv_config_class=ir_config_parameter
value = self.ICP.get_param('ircp_from_config') ):
self.assertEqual(value, 'config_value') # when creating, the value is overridden by config file
# when writing, the value is overridden by config file self.ICP.set_param("ircp_from_config", "new_value")
res = self.ICP.search([('key', '=', 'ircp_from_config')]) value = self.ICP.get_param("ircp_from_config")
self.assertEqual(len(res), 1) self.assertEqual(value, "config_value")
res.write({'value': 'new_value'}) # when writing, the value is overridden by config file
value = self.ICP.get_param('ircp_from_config') res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(value, 'config_value') self.assertEqual(len(res), 1)
# unlink works normally... res.write({"value": "new_value"})
res = self.ICP.search([('key', '=', 'ircp_from_config')]) value = self.ICP.get_param("ircp_from_config")
self.assertEqual(len(res), 1) self.assertEqual(value, "config_value")
res.unlink() # unlink works normally...
res = self.ICP.search([('key', '=', 'ircp_from_config')]) res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(len(res), 0) self.assertEqual(len(res), 1)
# but the value is recreated when getting param again res.unlink()
value = self.ICP.get_param('ircp_from_config') res = self.ICP.search([("key", "=", "ircp_from_config")])
self.assertEqual(value, 'config_value') self.assertEqual(len(res), 0)
res = self.ICP.search([('key', '=', 'ircp_from_config')]) # but the value is recreated when getting param again
self.assertEqual(len(res), 1) 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): 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 """
self.ICP.set_param('some.param', 'new_value') with self.load_config(
self.assertEqual(self.ICP.get_param('some.param'), 'new_value') public=self.env_config, serv_config_class=ir_config_parameter
res = self.ICP.search([('key', '=', 'some.param')]) ):
res.unlink() self.ICP.set_param("some.param", "new_value")
res = self.ICP.search([('key', '=', 'some.param')]) self.assertEqual(self.ICP.get_param("some.param"), "new_value")
self.assertFalse(res) res = self.ICP.search([("key", "=", "some.param")])
res.unlink()
res = self.ICP.search([("key", "=", "some.param")])
self.assertFalse(res)
def test_empty(self): def test_empty(self):
""" Empty config values cause error """ """ Empty config values cause error """
with self.assertRaises(UserError): with self.load_config(
self.ICP.get_param('ircp_empty') public=self.env_config, serv_config_class=ir_config_parameter
self.assertEqual(self.ICP.get_param('ircp_nonexistant'), False) ):
with self.assertRaises(UserError):
self.ICP.get_param("ircp_empty")
self.assertEqual(self.ICP.get_param("ircp_nonexistant"), False)
def test_override_xmldata(self): def test_override_xmldata(self):
self._load_xml( with self.load_config(
'server_environment_ir_config_parameter', public=self.env_config, serv_config_class=ir_config_parameter
'tests/config_param_test.xml' ):
) self._load_xml(
value = self.ICP.get_param('ircp_from_config') "server_environment_ir_config_parameter", "tests/config_param_test.xml"
self.assertEqual(value, 'config_value') )
value = self.ICP.get_param("ircp_from_config")
self.assertEqual(value, "config_value")