[IMP] ir.values: add (breaking) testcase for conditional defaults, currently misbehaving
authorOlivier Dony <odo@openerp.com>
Thu, 9 Feb 2012 13:05:26 +0000 (14:05 +0100)
committerOlivier Dony <odo@openerp.com>
Thu, 9 Feb 2012 13:05:26 +0000 (14:05 +0100)
bzr revid: odo@openerp.com-20120209130526-b6rg5qlf07sucafq

openerp/addons/base/test/test_ir_values.yml

index a8912e0..c26e725 100644 (file)
@@ -2,15 +2,30 @@
     Create some default value for some (non-existing) model, for all users.
 -
     !python {model: ir.values }: |
+        # use the old API
         self.set(cr, uid, 'default', False, 'my_test_field',['unexisting_model'], 'global value')
+        # use the new API
+        self.set_default(cr, uid, 'other_unexisting_model', 'my_other_test_field', 'conditional value', condition='foo=bar')
 -
-    Retrieve it.
+    Retrieve them.
 -
     !python {model: ir.values }: |
-        # d is a list of triple (id, name, value)
+        # d is a list of triplets (id, name, value)
+        # Old API
         d = self.get(cr, uid, 'default', False, ['unexisting_model'])
-        assert d[0][1] == 'my_test_field', "Can't retrieve the created default value."
-        assert d[0][2] == 'global value', "Can't retrieve the created default value."
+        assert len(d) == 1, "Only one single value should be retrieved for this model"
+        assert d[0][1] == 'my_test_field', "Can't retrieve the created default value. (1)"
+        assert d[0][2] == 'global value', "Can't retrieve the created default value. (2)"
+
+        # New API, Conditional version
+        d = self.get_defaults(cr, uid, 'other_unexisting_model')
+        assert len(d) == 0, "No value should be retrieved, the condition is not met"
+        d = self.get_defaults(cr, uid, 'other_unexisting_model', condition="foo=eggs")
+        assert len(d) == 0, 'Condition is not met either, no defaults should be returned'
+        d = self.get_defaults(cr, uid, 'other_unexisting_model', condition="foo=bar")
+        assert len(d) == 1, "Only one single value should be retrieved"
+        assert d[0][1] == 'my_other_test_field', "Can't retrieve the created default value. (5)"
+        assert d[0][2] == 'conditional value', "Can't retrieve the created default value. (6)"
 -
     Do it again but for a specific user.
 -