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.

66 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 LasLabs Inc.
  3. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html
  4. from odoo.exceptions import AccessError
  5. from odoo.tests import TransactionCase
  6. class TestResUsers(TransactionCase):
  7. def setUp(self):
  8. super(TestResUsers, self).setUp()
  9. self.immutable = self.env.ref('user_immutable.group_immutable')
  10. self.user = self.env.ref('base.user_demo')
  11. self.user.write({'in_group_%s' % self.immutable.id: False})
  12. def test_can_add_immutable(self):
  13. """ It should verify that `Administrator` can add users to the
  14. immutable group by default
  15. """
  16. self.user.write({'in_group_%s' % self.immutable.id: True})
  17. self.assertTrue(self.user.has_group('user_immutable.group_immutable'))
  18. def test_non_immutable_cannot_add_immutable(self):
  19. """ It should verify that other users cannot add to the immutable
  20. group
  21. """
  22. with self.assertRaises(AccessError):
  23. self.user.sudo(self.user.id).write({
  24. 'in_group_%s' % self.immutable.id: True
  25. })
  26. def test_immutable_can_alter_immutable(self):
  27. """ It should verify that immutable users can alter users in the
  28. immutable group
  29. """
  30. self.user.write({'in_group_%s' % self.immutable.id: True})
  31. exp = 'Princess Peach'
  32. self.user.write({'name': exp})
  33. self.assertEquals(self.user.name, exp)
  34. def test_immutable_cannot_be_unlinked(self):
  35. """ It should make sure non `Immutable` members cannot unlink other
  36. `Immutable` Members
  37. """
  38. with self.assertRaises(AccessError):
  39. self.env.ref('base.user_root').sudo(
  40. self.user.id
  41. ).unlink()
  42. def test_immutable_can_be_unlinked_by_immutable(self):
  43. """ It should make sure `Immutable` members can unlink other
  44. `Immutable` Members
  45. """
  46. user = self.user.copy()
  47. user.write({'in_group_%s' % self.immutable.id: True})
  48. self.assertTrue(user.unlink())
  49. def test_check_immutable(self):
  50. """ It should raise `AccessError` when trying called by a user
  51. outside the `Immutable` group on an `Immutable` user
  52. """
  53. with self.assertRaises(AccessError):
  54. self.env.ref('base.user_root').sudo(
  55. self.user.id
  56. )._check_immutable()