Browse Source

add unittest based test cases complementing the yaml one

pull/145/head
Charbel Jacquin 9 years ago
parent
commit
eb7ce14146
  1. 1
      partner_relations/__init__.py
  2. 5
      partner_relations/__openerp__.py
  3. 33
      partner_relations/test/test.yml
  4. 22
      partner_relations/test/test_allow.yml
  5. 1
      partner_relations/tests/__init__.py
  6. 80
      partner_relations/tests/test_partner_relations.py

1
partner_relations/__init__.py

@ -19,3 +19,4 @@
# #
############################################################################## ##############################################################################
from . import model from . import model
from . import tests

5
partner_relations/__openerp__.py

@ -21,7 +21,7 @@
{ {
"name": "Partner relations", "name": "Partner relations",
"version": "1.1", "version": "1.1",
"author": "Therp BV,Odoo Community Association (OCA)",
"author": "Therp BV,Camptocamp,Odoo Community Association (OCA)",
"complexity": "normal", "complexity": "normal",
"category": "Customer Relationship Management", "category": "Customer Relationship Management",
"depends": [ "depends": [
@ -30,7 +30,8 @@
"data/demo.xml", "data/demo.xml",
], ],
"test": [ "test": [
"test/test.xml",
"test/test_allow.yml",
# "test/test_disallow.yml",
], ],
"data": [ "data": [
"view/res_partner_relation_all.xml", "view/res_partner_relation_all.xml",

33
partner_relations/test/test.yml

@ -1,33 +0,0 @@
-
I create a relation type allowing partners to be in
both sides of the relation.
-
!record {model: res.partner.relation.type, id: allow_self}:
name: 'Relation A'
name_inverse: 'Inverse Relation A'
contact_type_right: 'p'
contact_type_left: 'p'
allow_self: True
-
I create a relation type with default value for `allow_self`
both sides of the relation.
-
!record {model: res.partner.relation.type, id: allow_self}:
name: 'Relation B'
name_inverse: 'Inverse Relation B'
contact_type_right: 'p'
contact_type_left: 'p'
-
I create relation instance admin -- Relation A --> admin
-
!record {model: res.partner.relation, id: test_allow}:
left_partner_id: base.admin
right_partner_id: base.admin
type_id: test_allow
-
I create relation instance admin -- Relation B --> admin
-
!record {model: res.partner.relation, id: test_disallow}:
left_partner_id: base.admin
right_partner_id: base.admin
type_id: test_disallow

22
partner_relations/test/test_allow.yml

@ -0,0 +1,22 @@
-
I create a relation allowing the same partner at both ends.
-
!record {model: res.partner.relation.type, id: partner_relations.allow_self}:
name: 'Relation Allow'
name_inverse: 'Inverse Relation Allow'
contact_type_right: 'p'
contact_type_left: 'p'
allow_self: True
-
I create a partner U for testing purposes
-
!record {model: res.partner, id: partner_relations.test_U}:
name: 'unittests.U'
image: ''
-
I create relation instance U -- (allow) --> U
-
!record {model: res.partner.relation, id: partner_relations.test_allow}:
left_partner_id: partner_relations.test_U
right_partner_id: partner_relations.test_U
type_id: partner_relations.allow_self

1
partner_relations/tests/__init__.py

@ -0,0 +1 @@
from . import test_partner_relations

80
partner_relations/tests/test_partner_relations.py

@ -0,0 +1,80 @@
# Author: Charbel Jacquin
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from openerp.tests import common
from openerp.exceptions import ValidationError
class TestPartnerRelation(common.TransactionCase):
def setUp(self):
super(TestPartnerRelation, self).setUp()
self.partner_model = self.env['res.partner']
self.relation_type_model = self.env['res.partner.relation.type']
self.relation_model = self.env['res.partner.relation']
self.partner_1 = self.partner_model.create({
'name': 'Test User 1',
'is_company': False
})
self.partner_2 = self.partner_model.create({
'name': 'Test User 2',
'is_company': False
})
self.relation_allow = self.relation_type_model.create({
'name': 'allow',
'name_inverse': 'allow_inverse',
'contact_type_left': 'p',
'contact_type_right': 'p',
'allow_self': True
})
self.relation_disallow = self.relation_type_model.create({
'name': 'disallow',
'name_inverse': 'disallow_inverse',
'contact_type_left': 'p',
'contact_type_right': 'p',
'allow_self': False
})
self.relation_default = self.relation_type_model.create({
'name': 'default',
'name_inverse': 'default_inverse',
'contact_type_left': 'p',
'contact_type_right': 'p',
})
def test_self_allowed(self):
self.relation_model.create({'type_id': self.relation_allow.id,
'left_partner_id': self.partner_1.id,
'right_partner_id': self.partner_1.id})
def test_self_disallowed(self):
with self.assertRaises(ValidationError):
self.relation_model.create({'type_id': self.relation_disallow.id,
'left_partner_id': self.partner_1.id,
'right_partner_id': self.partner_1.id})
def test_self_default(self):
with self.assertRaises(ValidationError):
self.relation_model.create({'type_id': self.relation_default.id,
'left_partner_id': self.partner_1.id,
'right_partner_id': self.partner_1.id})
Loading…
Cancel
Save