From 1439fcc40e942998845524420364b3047756934e Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 17 Feb 2015 16:45:20 +0100 Subject: [PATCH] [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. --- openerp/addons/test_inherit/models.py | 3 +-- .../addons/test_inherit/tests/test_inherit.py | 14 ++++++++++---- openerp/addons/test_new_api/ir.model.access.csv | 1 - openerp/addons/test_new_api/models.py | 6 ------ .../test_new_api/tests/test_new_fields.py | 17 ----------------- 5 files changed, 11 insertions(+), 30 deletions(-) diff --git a/openerp/addons/test_inherit/models.py b/openerp/addons/test_inherit/models.py index 422d59fd323..466318e22f5 100644 --- a/openerp/addons/test_inherit/models.py +++ b/openerp/addons/test_inherit/models.py @@ -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') diff --git a/openerp/addons/test_inherit/tests/test_inherit.py b/openerp/addons/test_inherit/tests/test_inherit.py index 6909882b2c6..8867629be61 100644 --- a/openerp/addons/test_inherit/tests/test_inherit.py +++ b/openerp/addons/test_inherit/tests/test_inherit.py @@ -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'] diff --git a/openerp/addons/test_new_api/ir.model.access.csv b/openerp/addons/test_new_api/ir.model.access.csv index d43088d808b..5b62045ae08 100644 --- a/openerp/addons/test_new_api/ir.model.access.csv +++ b/openerp/addons/test_new_api/ir.model.access.csv @@ -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 diff --git a/openerp/addons/test_new_api/models.py b/openerp/addons/test_new_api/models.py index 9866c8b6fd4..55611f6029d 100644 --- a/openerp/addons/test_new_api/models.py +++ b/openerp/addons/test_new_api/models.py @@ -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' diff --git a/openerp/addons/test_new_api/tests/test_new_fields.py b/openerp/addons/test_new_api/tests/test_new_fields.py index 6ffeb9b9153..8a32e5412a9 100644 --- a/openerp/addons/test_new_api/tests/test_new_fields.py +++ b/openerp/addons/test_new_api/tests/test_new_fields.py @@ -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)