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.

37 lines
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp.tests.common import TransactionCase
  5. from openerp.exceptions import AccessError
  6. class TestAccessCheck(TransactionCase):
  7. def setUp(self, *args, **kwargs):
  8. super(TestAccessCheck, self).setUp(*args, **kwargs)
  9. self.user_a = self.env['res.users'].create({
  10. 'name': u'User A',
  11. 'login': u'user_a',
  12. })
  13. self.user_b = self.env['res.users'].create({
  14. 'name': u'User B',
  15. 'login': u'user_b',
  16. })
  17. def test_same_name_write(self):
  18. """Write only same name is allowed. Bug use case"""
  19. partner = self.user_b.partner_id.sudo(user=self.user_a.id)
  20. partner.write({'name': u'User B'})
  21. def test_other_name_write(self):
  22. """Write other name is not allowed. Normal case"""
  23. with self.assertRaises(AccessError):
  24. partner = self.user_b.partner_id.sudo(user=self.user_a.id)
  25. partner.write({'name': u'User C'})
  26. def test_other_fields_write(self):
  27. """Write other fields is not allowed. Normal case"""
  28. with self.assertRaises(AccessError):
  29. partner = self.user_b.partner_id.sudo(user=self.user_a.id)
  30. partner.write({'email': u't@e.com'})