1 # -*- coding: utf-8 -*-
2 from openerp.tests import common
4 class test_inherits(common.TransactionCase):
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 daughter = self.env['test.inherit.daughter']
15 self.assertIn('field_in_mother', mother._fields)
16 self.assertIn('field_in_mother', daughter._fields)
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 "Bar" as
22 mother = self.env['test.inherit.mother']
23 field = mother._fields['name']
24 self.assertTrue(field.required)
26 self.assertEqual(field.default(mother), "Bar")
27 self.assertEqual(mother.default_get(['name']), {'name': "Bar"})
28 self.assertEqual(mother._defaults.get('name'), "Bar")
30 # the field daughter.template_id should inherit
31 # model_name='test.inherit.mother', string='Template', required=True
32 daughter = self.env['test.inherit.daughter']
33 field = daughter._fields['template_id']
34 self.assertEqual(field.comodel_name, 'test.inherit.mother')
35 self.assertEqual(field.string, "Template")
36 self.assertTrue(field.required)
38 def test_depends_extension(self):
39 """ check that @depends on overridden compute methods extends dependencies """
40 mother = self.env['test.inherit.mother']
41 field = mother._fields['surname']
43 # the field dependencies are added
44 self.assertItemsEqual(field.depends, ['name', 'field_in_mother'])
46 def test_selection_extension(self):
47 """ check that attribute selection_add=... extends selection on fields. """
48 mother = self.env['test.inherit.mother']
50 # the extra values are added, both in the field and the column
51 self.assertEqual(mother._fields['state'].selection,
52 [('a', 'A'), ('b', 'B'), ('c', 'C'), ('d', 'D')])
53 self.assertEqual(mother._columns['state'].selection,
54 [('a', 'A'), ('b', 'B'), ('c', 'C'), ('d', 'D')])
57 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: