Charbel Jacquin
9 years ago
6 changed files with 107 additions and 35 deletions
-
1partner_relations/__init__.py
-
5partner_relations/__openerp__.py
-
33partner_relations/test/test.yml
-
22partner_relations/test/test_allow.yml
-
1partner_relations/tests/__init__.py
-
80partner_relations/tests/test_partner_relations.py
@ -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 |
@ -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 |
@ -0,0 +1 @@ |
|||
from . import test_partner_relations |
@ -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}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue