Browse Source

server_environment_ir_config_parameter: handle empty values better

pull/640/head
Stéphane Bidoul (ACSONE) 8 years ago
parent
commit
bdcf4ae644
No known key found for this signature in database GPG Key ID: 866D394B4986F82D
  1. 1
      server_environment_files_sample/dev/base.conf
  2. 4
      server_environment_ir_config_parameter/models/ir_config_parameter.py
  3. 6
      server_environment_ir_config_parameter/tests/test_server_environment_ircp.py

1
server_environment_files_sample/dev/base.conf

@ -9,3 +9,4 @@ lib_path = /myHome/lib/wkhtmltopdf-linux-i386-0-9-9
[ir.config_parameter] [ir.config_parameter]
ircp_from_config=config_value ircp_from_config=config_value
ircp_empty=

4
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) cr, uid, key, default=None, context=context)
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:
raise UserError(_("Key %s is empty in "
"server_environment_file") %
(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,

6
server_environment_ir_config_parameter/tests/test_server_environment_ircp.py

@ -49,3 +49,9 @@ class TestEnv(common.SavepointCase):
res.unlink() res.unlink()
res = self.ICP.search([('key', '=', 'some.param')]) res = self.ICP.search([('key', '=', 'some.param')])
self.assertFalse(res) 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)
Loading…
Cancel
Save