@ -2,11 +2,14 @@
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from cStringIO import StringIO
from openerp.exceptions import UserError
from openerp.tests import common
from openerp.tools import convert
class TestEnv ( common . Savepoint Case) :
class TestEnv ( common . Transaction Case) :
def setUp ( self ) :
super ( TestEnv , self ) . setUp ( )
@ -27,19 +30,27 @@ class TestEnv(common.SavepointCase):
def test_set_param_1 ( self ) :
""" We can ' t set parameters that are in config file """
# create
with self . assertRaises ( UserError ) :
self . ICP . set_param ( ' ircp_from_config ' , ' new_value ' )
# read so it's created in db
self . ICP . get_param ( ' ircp_from_config ' )
# write
# 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 ' )
# when writing, the value is overridden by config file
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 ' )
# unlink works normally...
res = self . ICP . search ( [ ( ' key ' , ' = ' , ' ircp_from_config ' ) ] )
self . assertEqual ( len ( res ) , 1 )
res . unlink ( )
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 ' ) ] )
self . assertEqual ( len ( res ) , 1 )
with self . assertRaises ( UserError ) :
res . write ( { ' ircp_from_config ' : ' new_value ' } )
# unlink
with self . assertRaises ( UserError ) :
res . unlink ( )
def test_set_param_2 ( self ) :
""" We can set parameters that are not in config file """
@ -55,3 +66,16 @@ class TestEnv(common.SavepointCase):
with self . assertRaises ( UserError ) :
self . ICP . get_param ( ' ircp_empty ' )
self . assertEqual ( self . ICP . get_param ( ' ircp_nonexistant ' ) , False )
def test_override_xmldata ( self ) :
xml = """ <odoo>
< data >
< record model = " ir.config_parameter " id = " some_record_id " >
< field name = " key " > ircp_from_config < / field >
< field name = " value " > value_from_xml < / field >
< / record >
< / data >
< / odoo > """
convert . convert_xml_import ( self . env . cr , ' testmodule ' , StringIO ( xml ) )
value = self . ICP . get_param ( ' ircp_from_config ' )
self . assertEqual ( value , ' config_value ' )