[IMP] test_new_api: move test on delegate=True to module test_inherit

Group together the tests on fields that deal with _inherit and _inherits, and
avoid warnings about the field that uses delegate=True.
This commit is contained in:
Raphael Collet 2015-02-17 16:45:20 +01:00
parent 45a37b22fd
commit 1439fcc40e
5 changed files with 11 additions and 30 deletions

View File

@ -25,10 +25,9 @@ class mother(models.Model):
# in the child object
class daughter(models.Model):
_name = 'test.inherit.daughter'
_inherits = {'test.inherit.mother': 'template_id'}
template_id = fields.Many2one('test.inherit.mother', 'Template',
required=True, ondelete='cascade')
delegate=True, required=True, ondelete='cascade')
field_in_daughter = fields.Char('Field1')

View File

@ -3,7 +3,13 @@ from openerp.tests import common
class test_inherits(common.TransactionCase):
def test_access_from_child_to_parent_model(self):
def test_00_inherits(self):
""" Check that a many2one field with delegate=True adds an entry in _inherits """
daughter = self.env['test.inherit.daughter']
self.assertEqual(daughter._inherits, {'test.inherit.mother': 'template_id'})
def test_10_access_from_child_to_parent_model(self):
""" check whether added field in model is accessible from children models (_inherits) """
# This test checks if the new added column of a parent model
# is accessible from the child model. This test has been written
@ -15,7 +21,7 @@ class test_inherits(common.TransactionCase):
self.assertIn('field_in_mother', mother._fields)
self.assertIn('field_in_mother', daughter._fields)
def test_field_extension(self):
def test_20_field_extension(self):
""" check the extension of a field in an inherited model """
mother = self.env['test.inherit.mother']
daughter = self.env['test.inherit.daughter']
@ -41,7 +47,7 @@ class test_inherits(common.TransactionCase):
self.assertEqual(field.string, "Template")
self.assertTrue(field.required)
def test_depends_extension(self):
def test_30_depends_extension(self):
""" check that @depends on overridden compute methods extends dependencies """
mother = self.env['test.inherit.mother']
field = mother._fields['surname']
@ -49,7 +55,7 @@ class test_inherits(common.TransactionCase):
# the field dependencies are added
self.assertItemsEqual(field.depends, ['name', 'field_in_mother'])
def test_selection_extension(self):
def test_40_selection_extension(self):
""" check that attribute selection_add=... extends selection on fields. """
mother = self.env['test.inherit.mother']

View File

@ -2,5 +2,4 @@
access_category,test_new_api_category,test_new_api.model_test_new_api_category,,1,1,1,1
access_discussion,test_new_api_discussion,test_new_api.model_test_new_api_discussion,,1,1,1,1
access_message,test_new_api_message,test_new_api.model_test_new_api_message,,1,1,1,1
access_talk,test_new_api_talk,test_new_api.model_test_new_api_talk,,1,1,1,1
access_mixed,test_new_api_mixed,test_new_api.model_test_new_api_mixed,,1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_category test_new_api_category test_new_api.model_test_new_api_category 1 1 1 1
3 access_discussion test_new_api_discussion test_new_api.model_test_new_api_discussion 1 1 1 1
4 access_message test_new_api_message test_new_api.model_test_new_api_message 1 1 1 1
access_talk test_new_api_talk test_new_api.model_test_new_api_talk 1 1 1 1
5 access_mixed test_new_api_mixed test_new_api.model_test_new_api_mixed 1 1 1 1

View File

@ -153,12 +153,6 @@ class Message(models.Model):
self.double_size = self.double_size + size
class Talk(models.Model):
_name = 'test_new_api.talk'
parent = fields.Many2one('test_new_api.discussion', delegate=True, required=True)
class MixedModel(models.Model):
_name = 'test_new_api.mixed'

View File

@ -375,20 +375,3 @@ class TestMagicFields(common.TransactionCase):
record = self.env['test_new_api.discussion'].create({'name': 'Booba'})
self.assertEqual(record.create_uid, self.env.user)
self.assertEqual(record.write_uid, self.env.user)
class TestInherits(common.TransactionCase):
def test_inherits(self):
""" Check that a many2one field with delegate=True adds an entry in _inherits """
Talk = self.env['test_new_api.talk']
self.assertEqual(Talk._inherits, {'test_new_api.discussion': 'parent'})
self.assertIn('name', Talk._fields)
self.assertEqual(Talk._fields['name'].related, ('parent', 'name'))
talk = Talk.create({'name': 'Foo'})
discussion = talk.parent
self.assertTrue(discussion)
self.assertEqual(talk._name, 'test_new_api.talk')
self.assertEqual(discussion._name, 'test_new_api.discussion')
self.assertEqual(talk.name, discussion.name)