valid default/callback value in consistencies
[tiramisu.git] / test / test_option_consistency.py
index 8a6f797..c419f7e 100644 (file)
@@ -302,6 +302,41 @@ def test_consistency_network_netmask_multi_slave_default():
     c.read_only()
     assert c.a == [u'192.168.1.0']
     assert c.b == [u'255.255.255.0']
+    c.read_write()
+    raises(ValueError, "c.a[0] = u'192.168.1.2'")
+    raises(ValueError, "c.a.append(u'192.168.1.1')")
+    raises(ValueError, "c.a = [u'192.168.1.0', u'192.168.1.1']")
+    c.a.append()
+    c.b = [u'255.255.255.0', u'255.255.255.255']
+    c.a = [u'192.168.1.0', u'192.168.1.1']
+
+
+def return_netmask(*args, **kwargs):
+    return u'255.255.255.0'
+
+
+def test_consistency_network_netmask_multi_slave_callback():
+    a = NetworkOption('a', '', multi=True, properties=('mandatory',))
+    b = NetmaskOption('b', '', callback=return_netmask, multi=True, properties=('mandatory',))
+    od = OptionDescription('a', '', [a, b])
+    od.impl_set_group_type(groups.master)
+    b.impl_add_consistency('network_netmask', a)
+    c = Config(od)
+    c.read_write()
+    c.cfgimpl_get_settings().remove('cache')
+    assert c.a == []
+    assert c.b == []
+    c.a.append(u'192.168.1.0')
+    c.read_only()
+    assert c.a == [u'192.168.1.0']
+    assert c.b == [u'255.255.255.0']
+    c.read_write()
+    raises(ValueError, "c.a[0] = u'192.168.1.2'")
+    raises(ValueError, "c.a.append(u'192.168.1.1')")
+    raises(ValueError, "c.a = [u'192.168.1.0', u'192.168.1.1']")
+    c.a.append()
+    c.b = [u'255.255.255.0', u'255.255.255.255']
+    c.a = [u'192.168.1.0', u'192.168.1.1']
 
 
 def test_consistency_ip_netmask_multi_master():