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.

82 lines
3.5 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (C) 2017 MuK IT GmbH
  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. #
  18. ###################################################################################
  19. import os
  20. import base64
  21. import logging
  22. from odoo import exceptions
  23. from odoo.tests import common
  24. _path = os.path.dirname(os.path.dirname(__file__))
  25. _logger = logging.getLogger(__name__)
  26. class AccessGroupsTestCase(common.TransactionCase):
  27. def setUp(self):
  28. super(AccessGroupsTestCase, self).setUp()
  29. self.user_id = self.ref('base.user_demo')
  30. self.group_id = self.ref('base.group_system')
  31. self.groups = self.env['muk_security.access_groups']
  32. self.group01 = self.groups.create({
  33. 'name': 'Group 01',
  34. 'explicit_users': [(6, 0, [self.user_id])]})
  35. self.group02 = self.groups.create({
  36. 'name': 'Group 02',
  37. 'groups': [(6, 0, [self.group_id])]})
  38. self.user = self.env['res.users'].browse(self.user_id)
  39. self.group = self.env['res.groups'].browse(self.group_id)
  40. def tearDown(self):
  41. super(AccessGroupsTestCase, self).tearDown()
  42. def test_access_groups_users(self):
  43. count = len(self.group02.users)
  44. self.group02.write({'explicit_users': [(6, 0, [self.user_id])]})
  45. self.assertTrue(len(self.group02.users) > count)
  46. def test_access_groups_groups(self):
  47. count = len(self.group01.users)
  48. self.group01.write({'groups': [(6, 0, [self.group_id])]})
  49. self.assertTrue(len(self.group01.users) > count)
  50. def test_access_groups_groups_group(self):
  51. count = len(self.group02.users)
  52. self.group.write({'users': [(4, self.user_id)]})
  53. self.assertTrue(len(self.group02.users) > count)
  54. def test_access_groups_groups_user(self):
  55. count = len(self.group02.users)
  56. self.user.write({'groups_id':[(4, self.group_id)]})
  57. self.assertTrue(len(self.group02.users) > count)
  58. def test_access_groups_parent(self):
  59. count = len(self.group02.users)
  60. self.group02.write({'parent_group': self.group01.id})
  61. self.assertTrue(len(self.group02.users) > count)
  62. def test_access_groups_parent_multi(self):
  63. group01 = self.groups.create({'name': 'MGroup 01'})
  64. group02 = self.groups.create({'name': 'MGroup 02', 'parent_group': group01.id})
  65. group03 = self.groups.create({'name': 'MGroup 03', 'parent_group': group02.id})
  66. init_count = len(group03.users)
  67. group02.write({'explicit_users': [(6, 0, [self.user_id])]})
  68. self.assertTrue(len(group03.users) > init_count)
  69. updated_count = len(group03.users)
  70. group01.write({'groups': [(6, 0, [self.group_id])]})
  71. self.assertTrue(len(group03.users) > updated_count)