[IMP] fields: make attribute 'default' callable
[odoo/odoo.git] / openerp / addons / test_inherit / tests / test_inherit.py
1 # -*- coding: utf-8 -*-
2 from openerp.tests import common
3
4 class test_inherits(common.TransactionCase):
5
6     def test_access_from_child_to_parent_model(self):
7         """ check whether added field in model is accessible from children models (_inherits) """
8         # This test checks if the new added column of a parent model
9         # is accessible from the child model. This test has been written
10         # to verify the purpose of the inheritance computing of the class
11         # in the openerp.osv.orm._build_model.
12         mother = self.env['test.inherit.mother']
13         daugther = self.env['test.inherit.daughter']
14
15         self.assertIn('field_in_mother', mother._fields)
16         self.assertIn('field_in_mother', daugther._fields)
17
18     def test_field_extension(self):
19         """ check the extension of a field in an inherited model """
20         # the field mother.name should inherit required=True, and have a default
21         # value
22         mother = self.env['test.inherit.mother']
23         field = mother._fields['name']
24         self.assertTrue(field.required)
25         self.assertEqual(field.default(mother), 'Unknown')
26
27         # the field daugther.template_id should inherit
28         # model_name='test.inherit.mother', string='Template', required=True
29         daugther = self.env['test.inherit.daughter']
30         field = daugther._fields['template_id']
31         self.assertEqual(field.comodel_name, 'test.inherit.mother')
32         self.assertEqual(field.string, "Template")
33         self.assertTrue(field.required)
34
35     def test_depends_extension(self):
36         """ check that @depends on overridden compute methods extends dependencies """
37         mother = self.env['test.inherit.mother']
38         field = mother._fields['surname']
39
40         # the field dependencies are added
41         self.assertItemsEqual(field.depends, ['name', 'field_in_mother'])
42
43     def test_selection_extension(self):
44         """ check that attribute selection_add=... extends selection on fields. """
45         mother = self.env['test.inherit.mother']
46
47         # the extra values are added, both in the field and the column
48         self.assertEqual(mother._fields['state'].selection,
49                          [('a', 'A'), ('b', 'B'), ('c', 'C'), ('d', 'D')])
50         self.assertEqual(mother._columns['state'].selection,
51                          [('a', 'A'), ('b', 'B'), ('c', 'C'), ('d', 'D')])
52
53
54 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: