From 126f83fba7c0180948f2c2f6edcdee1eb852ef5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?= Date: Sun, 20 Nov 2016 23:18:38 +0100 Subject: [PATCH] [IMP] server_environment_ir_config_parameter: handle empty values better --- server_environment_files_sample/dev/base.conf | 1 + .../models/ir_config_parameter.py | 4 ++++ .../tests/test_server_environment_ircp.py | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/server_environment_files_sample/dev/base.conf b/server_environment_files_sample/dev/base.conf index b2cc8330e..036aea7a1 100644 --- a/server_environment_files_sample/dev/base.conf +++ b/server_environment_files_sample/dev/base.conf @@ -9,3 +9,4 @@ lib_path = /myHome/lib/wkhtmltopdf-linux-i386-0-9-9 [ir.config_parameter] ircp_from_config=config_value +ircp_empty= 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 819ef8f62..14bad0ca8 100644 --- a/server_environment_ir_config_parameter/models/ir_config_parameter.py +++ b/server_environment_ir_config_parameter/models/ir_config_parameter.py @@ -20,6 +20,10 @@ class IrConfigParameter(models.Model): cr, uid, key, default=None, context=context) 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, )) if cvalue != value: # we write in db on first access; # should we have preloaded values in database at, 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 9566bb126..07fae4469 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 @@ -49,3 +49,9 @@ class TestEnv(common.SavepointCase): res.unlink() 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)