"""
$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/param/test/utest_parameter_database.py $
$Id: utest_parameter_database.py 28105 2006-03-30 16:24:19Z dbinger $
"""
from dulcinea.common import CommonTest
from dulcinea.param import get_parameter_db
from dulcinea.param.parameter_template import MasterTemplate
from dulcinea.param.parameter_type import get_string_parameter_type
from sancho.utest import raises

class ParameterDatabaseTest (CommonTest):

    def check_master_templates (self):
        if get_parameter_db() is None:
            return
        parameter_db = get_parameter_db()
        raises(TypeError, parameter_db.add_master_template, 'foo')

        s = get_string_parameter_type()
        self.foo = MasterTemplate('foo',s)
        self.bar = MasterTemplate('bar',s)
        raises(ValueError, parameter_db.rename_master_template, self.bar,'foo')

        parameter_db.add_master_template(self.foo)
        parameter_db.add_master_template(self.bar)
        raises(ValueError, parameter_db.add_master_template, self.foo)

        raises(ValueError, parameter_db.rename_master_template, self.bar, 'foo')
        parameter_db.rename_master_template(self.bar,'baz')
        assert self.bar == parameter_db.get_master_template('baz')


if __name__ == "__main__":
    ParameterDatabaseTest()
