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.

85 lines
3.5 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-2019 MuK IT GmbH.
  4. #
  5. # This file is part of MuK Security
  6. # (see https://mukit.at).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ###################################################################################
  22. import os
  23. import base64
  24. import logging
  25. from odoo import exceptions
  26. from odoo.tests import common
  27. _path = os.path.dirname(os.path.dirname(__file__))
  28. _logger = logging.getLogger(__name__)
  29. class AccessGroupsTestCase(common.TransactionCase):
  30. def setUp(self):
  31. super(AccessGroupsTestCase, self).setUp()
  32. self.user_id = self.ref('base.user_demo')
  33. self.group_id = self.ref('base.group_system')
  34. self.groups = self.env['muk_security.access_groups']
  35. self.group01 = self.groups.create({
  36. 'name': 'Group 01',
  37. 'explicit_users': [(6, 0, [self.user_id])]})
  38. self.group02 = self.groups.create({
  39. 'name': 'Group 02',
  40. 'groups': [(6, 0, [self.group_id])]})
  41. self.user = self.env['res.users'].browse(self.user_id)
  42. self.group = self.env['res.groups'].browse(self.group_id)
  43. def tearDown(self):
  44. super(AccessGroupsTestCase, self).tearDown()
  45. def test_access_groups_users(self):
  46. count = len(self.group02.users)
  47. self.group02.write({'explicit_users': [(6, 0, [self.user_id])]})
  48. self.assertTrue(len(self.group02.users) > count)
  49. def test_access_groups_groups(self):
  50. count = len(self.group01.users)
  51. self.group01.write({'groups': [(6, 0, [self.group_id])]})
  52. self.assertTrue(len(self.group01.users) > count)
  53. def test_access_groups_groups_group(self):
  54. count = len(self.group02.users)
  55. self.group.write({'users': [(4, self.user_id)]})
  56. self.assertTrue(len(self.group02.users) > count)
  57. def test_access_groups_groups_user(self):
  58. count = len(self.group02.users)
  59. self.user.write({'groups_id':[(4, self.group_id)]})
  60. self.assertTrue(len(self.group02.users) > count)
  61. def test_access_groups_parent(self):
  62. count = len(self.group02.users)
  63. self.group02.write({'parent_group': self.group01.id})
  64. self.assertTrue(len(self.group02.users) > count)
  65. def test_access_groups_parent_multi(self):
  66. group01 = self.groups.create({'name': 'MGroup 01'})
  67. group02 = self.groups.create({'name': 'MGroup 02', 'parent_group': group01.id})
  68. group03 = self.groups.create({'name': 'MGroup 03', 'parent_group': group02.id})
  69. init_count = len(group03.users)
  70. group02.write({'explicit_users': [(6, 0, [self.user_id])]})
  71. self.assertTrue(len(group03.users) > init_count)
  72. updated_count = len(group03.users)
  73. group01.write({'groups': [(6, 0, [self.group_id])]})
  74. self.assertTrue(len(group03.users) > updated_count)