You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.0 KiB

9 years ago
  1. # -*- coding: utf-8 -*-
  2. # Author: Charbel Jacquin
  3. # Copyright 2015 Camptocamp SA
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. from openerp.tests import common
  18. from openerp.exceptions import ValidationError
  19. class TestPartnerRelation(common.TransactionCase):
  20. def setUp(self):
  21. super(TestPartnerRelation, self).setUp()
  22. self.partner_model = self.env['res.partner']
  23. self.relation_type_model = self.env['res.partner.relation.type']
  24. self.relation_model = self.env['res.partner.relation']
  25. self.partner_1 = self.partner_model.create({
  26. 'name': 'Test User 1',
  27. 'is_company': False
  28. })
  29. self.partner_2 = self.partner_model.create({
  30. 'name': 'Test User 2',
  31. 'is_company': False
  32. })
  33. self.relation_allow = self.relation_type_model.create({
  34. 'name': 'allow',
  35. 'name_inverse': 'allow_inverse',
  36. 'contact_type_left': 'p',
  37. 'contact_type_right': 'p',
  38. 'allow_self': True
  39. })
  40. self.relation_disallow = self.relation_type_model.create({
  41. 'name': 'disallow',
  42. 'name_inverse': 'disallow_inverse',
  43. 'contact_type_left': 'p',
  44. 'contact_type_right': 'p',
  45. 'allow_self': False
  46. })
  47. self.relation_default = self.relation_type_model.create({
  48. 'name': 'default',
  49. 'name_inverse': 'default_inverse',
  50. 'contact_type_left': 'p',
  51. 'contact_type_right': 'p',
  52. })
  53. def test_self_allowed(self):
  54. self.relation_model.create({'type_id': self.relation_allow.id,
  55. 'left_partner_id': self.partner_1.id,
  56. 'right_partner_id': self.partner_1.id})
  57. def test_self_disallowed(self):
  58. with self.assertRaises(ValidationError):
  59. self.relation_model.create({'type_id': self.relation_disallow.id,
  60. 'left_partner_id': self.partner_1.id,
  61. 'right_partner_id': self.partner_1.id})
  62. def test_self_default(self):
  63. with self.assertRaises(ValidationError):
  64. self.relation_model.create({'type_id': self.relation_default.id,
  65. 'left_partner_id': self.partner_1.id,
  66. 'right_partner_id': self.partner_1.id})