3 import openerp.tests.common as common
5 class test_ir_values(common.TransactionCase):
8 # Create some default value for some (non-existing) model, for all users.
10 ir_values = self.registry('ir.values')
12 ir_values.set(self.cr, self.uid, 'default', False, 'my_test_field',
13 ['unexisting_model'], 'global value')
15 ir_values.set_default(self.cr, self.uid, 'other_unexisting_model',
16 'my_other_test_field', 'conditional value', condition='foo=bar')
21 ir_values = self.registry('ir.values')
22 # d is a list of triplets (id, name, value)
24 d = ir_values.get(self.cr, self.uid, 'default', False, ['unexisting_model'])
25 assert len(d) == 1, "Only one single value should be retrieved for this model"
26 assert d[0][1] == 'my_test_field', "Can't retrieve the created default value. (1)"
27 assert d[0][2] == 'global value', "Can't retrieve the created default value. (2)"
29 # New API, Conditional version
30 d = ir_values.get_defaults(self.cr, self.uid, 'other_unexisting_model')
31 assert len(d) == 0, "No value should be retrieved, the condition is not met"
32 d = ir_values.get_defaults(self.cr, self.uid, 'other_unexisting_model', condition="foo=eggs")
33 assert len(d) == 0, 'Condition is not met either, no defaults should be returned'
34 d = ir_values.get_defaults(self.cr, self.uid, 'other_unexisting_model', condition="foo=bar")
35 assert len(d) == 1, "Only one single value should be retrieved"
36 assert d[0][1] == 'my_other_test_field', "Can't retrieve the created default value. (5)"
37 assert d[0][2] == 'conditional value', "Can't retrieve the created default value. (6)"
39 # Do it again but for a specific user.
41 ir_values = self.registry('ir.values')
42 ir_values.set(self.cr, self.uid, 'default', False, 'my_test_field',['unexisting_model'], 'specific value', preserve_user=True)
44 # Retrieve it and check it is the one for the current user.
45 ir_values = self.registry('ir.values')
46 d = ir_values.get(self.cr, self.uid, 'default', False, ['unexisting_model'])
47 assert len(d) == 1, "Only one default must be returned per field"
48 assert d[0][1] == 'my_test_field', "Can't retrieve the created default value."
49 assert d[0][2] == 'specific value', "Can't retrieve the created default value."
51 # Create some action bindings for a non-existing model.
53 ir_values = self.registry('ir.values')
54 ir_values.set(self.cr, self.uid, 'action', 'tree_but_open', 'OnDblClick Action', ['unexisting_model'], 'ir.actions.act_window,10', isobject=True)
55 ir_values.set(self.cr, self.uid, 'action', 'tree_but_open', 'OnDblClick Action 2', ['unexisting_model'], 'ir.actions.act_window,11', isobject=True)
56 ir_values.set(self.cr, self.uid, 'action', 'client_action_multi', 'Side Wizard', ['unexisting_model'], 'ir.actions.act_window,12', isobject=True)
57 report_ids = self.registry('ir.actions.report.xml').search(self.cr, self.uid, [], {})
58 reports = self.registry('ir.actions.report.xml').browse(self.cr, self.uid, report_ids, {})
59 report_id = [report.id for report in reports if not report.groups_id][0] # assume at least one
60 ir_values.set(self.cr, self.uid, 'action', 'client_print_multi', 'Nice Report', ['unexisting_model'], 'ir.actions.report.xml,%s'%report_id, isobject=True)
61 ir_values.set(self.cr, self.uid, 'action', 'client_action_relate', 'Related Stuff', ['unexisting_model'], 'ir.actions.act_window,14', isobject=True)
63 # Replace one action binding to set a new name.
65 ir_values = self.registry('ir.values')
66 ir_values.set(self.cr, self.uid, 'action', 'tree_but_open', 'OnDblClick Action New', ['unexisting_model'], 'ir.actions.act_window,10', isobject=True)
68 # Retrieve the action bindings and check they're correct
70 ir_values = self.registry('ir.values')
71 actions = ir_values.get(self.cr, self.uid, 'action', 'tree_but_open', ['unexisting_model'])
72 assert len(actions) == 2, "Mismatching number of bound actions"
74 assert len(actions[0]) == 3, "Malformed action definition"
75 assert actions[0][1] == 'OnDblClick Action 2', 'Bound action does not match definition'
76 assert isinstance(actions[0][2], dict) and actions[0][2]['id'] == 11, 'Bound action does not match definition'
77 #second action - this ones comes last because it was re-created with a different name
78 assert len(actions[1]) == 3, "Malformed action definition"
79 assert actions[1][1] == 'OnDblClick Action New', 'Re-Registering an action should replace it'
80 assert isinstance(actions[1][2], dict) and actions[1][2]['id'] == 10, 'Bound action does not match definition'
82 actions = ir_values.get(self.cr, self.uid, 'action', 'client_action_multi', ['unexisting_model'])
83 assert len(actions) == 1, "Mismatching number of bound actions"
84 assert len(actions[0]) == 3, "Malformed action definition"
85 assert actions[0][1] == 'Side Wizard', 'Bound action does not match definition'
86 assert isinstance(actions[0][2], dict) and actions[0][2]['id'] == 12, 'Bound action does not match definition'
88 actions = ir_values.get(self.cr, self.uid, 'action', 'client_print_multi', ['unexisting_model'])
89 assert len(actions) == 1, "Mismatching number of bound actions"
90 assert len(actions[0]) == 3, "Malformed action definition"
91 assert actions[0][1] == 'Nice Report', 'Bound action does not match definition'
92 assert isinstance(actions[0][2], dict) and actions[0][2]['id'] == report_id, 'Bound action does not match definition'
94 actions = ir_values.get(self.cr, self.uid, 'action', 'client_action_relate', ['unexisting_model'])
95 assert len(actions) == 1, "Mismatching number of bound actions"
96 assert len(actions[0]) == 3, "Malformed action definition"
97 assert actions[0][1] == 'Related Stuff', 'Bound action does not match definition'
98 assert isinstance(actions[0][2], dict) and actions[0][2]['id'] == 14, 'Bound action does not match definition'
101 if __name__ == '__main__':