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.

80 lines
3.0 KiB

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