diff --git a/partner_firstname/tests/__init__.py b/partner_firstname/tests/__init__.py index 6ad0d4ec1..c2bee213c 100644 --- a/partner_firstname/tests/__init__.py +++ b/partner_firstname/tests/__init__.py @@ -37,4 +37,5 @@ from . import ( test_name, test_onchange, test_order, + test_access_check, ) diff --git a/partner_firstname/tests/test_access_check.py b/partner_firstname/tests/test_access_check.py new file mode 100644 index 000000000..ca390cc86 --- /dev/null +++ b/partner_firstname/tests/test_access_check.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import HttpCase, TransactionCase +from openerp.exceptions import AccessError + + +class TestAccessCheck(TransactionCase): + def setUp(self, *args, **kwargs): + super(TestAccessCheck, self).setUp(*args, **kwargs) + + self.user_a = self.env['res.users'].create({ + 'name': u'User A', + 'login': u'user_a', + }) + self.user_b = self.env['res.users'].create({ + 'name': u'User B', + 'login': u'user_b', + }) + + def test_same_name_write(self): + """Write only same name is allowed. Bug use case""" + partner = self.user_b.partner_id.sudo(user=self.user_a.id) + partner.write({'name': u'User B'}) + + def test_other_name_write(self): + """Write other name is not allowed. Normal case""" + with self.assertRaises(AccessError): + partner = self.user_b.partner_id.sudo(user=self.user_a.id) + partner.write({'name': u'User C'}) + + def test_other_fields_write(self): + """Write other fields is not allowed. Normal case""" + with self.assertRaises(AccessError): + partner = self.user_b.partner_id.sudo(user=self.user_a.id) + partner.write({'email': u't@e.com'})