diff --git a/partner_relations/__init__.py b/partner_relations/__init__.py index 9da2ac3b6..057c357a1 100644 --- a/partner_relations/__init__.py +++ b/partner_relations/__init__.py @@ -19,3 +19,4 @@ # ############################################################################## from . import model +from . import tests diff --git a/partner_relations/__openerp__.py b/partner_relations/__openerp__.py index d4450f413..1997ff8de 100644 --- a/partner_relations/__openerp__.py +++ b/partner_relations/__openerp__.py @@ -21,7 +21,7 @@ { "name": "Partner relations", "version": "1.1", - "author": "Therp BV,Odoo Community Association (OCA)", + "author": "Therp BV,Camptocamp,Odoo Community Association (OCA)", "complexity": "normal", "category": "Customer Relationship Management", "depends": [ @@ -30,7 +30,8 @@ "data/demo.xml", ], "test": [ - "test/test.xml", + "test/test_allow.yml", + # "test/test_disallow.yml", ], "data": [ "view/res_partner_relation_all.xml", diff --git a/partner_relations/test/test.yml b/partner_relations/test/test.yml deleted file mode 100644 index fee8a3324..000000000 --- a/partner_relations/test/test.yml +++ /dev/null @@ -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 diff --git a/partner_relations/test/test_allow.yml b/partner_relations/test/test_allow.yml new file mode 100644 index 000000000..cbd89f803 --- /dev/null +++ b/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 diff --git a/partner_relations/tests/__init__.py b/partner_relations/tests/__init__.py new file mode 100644 index 000000000..0c45f0703 --- /dev/null +++ b/partner_relations/tests/__init__.py @@ -0,0 +1 @@ +from . import test_partner_relations diff --git a/partner_relations/tests/test_partner_relations.py b/partner_relations/tests/test_partner_relations.py new file mode 100644 index 000000000..37414c84f --- /dev/null +++ b/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 . + +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})