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.

87 lines
2.8 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 .common import Common, MAX_DB_USER_PARAM
  6. class TestIrConfigParameter(Common):
  7. def _get_param(self):
  8. return self.env['ir.config_parameter'].search([
  9. ('key', '=', MAX_DB_USER_PARAM),
  10. ])
  11. def test_can_set(self):
  12. """
  13. It should test that users in the Threshold Manager group can
  14. update the parameter
  15. """
  16. mdl = self.env['ir.config_parameter']
  17. u = self._create_test_user()
  18. self._add_user_to_group(u)
  19. exp = '20'
  20. mdl.sudo(u.id).set_param(MAX_DB_USER_PARAM, exp)
  21. self.assertEquals(mdl.get_param(MAX_DB_USER_PARAM), exp)
  22. def test_cannot_set(self):
  23. """
  24. It should test that users NOT in the Threshold Manager group
  25. cannot alter the parameter
  26. """
  27. u = self._create_test_user()
  28. with self.assertRaises(AccessError):
  29. self.env['ir.config_parameter'].sudo(u.id).set_param(
  30. MAX_DB_USER_PARAM, 20
  31. )
  32. def test_can_unlink(self):
  33. """
  34. It should test that users in the Threshold Manager group can
  35. unlink the Threshold Param
  36. """
  37. u = self._create_test_user()
  38. self._add_user_to_group(u)
  39. param = self._get_param()
  40. self.assertTrue(param.sudo(u.id).unlink())
  41. def test_cannot_unlink(self):
  42. """
  43. It should test that users outside the Threshold Manager group
  44. cannot unlink the Threshold Param
  45. """
  46. u = self._create_test_user()
  47. param = self._get_param()
  48. system_group = self.env.ref('base.group_system')
  49. u.write({'in_group_%s' % system_group.id: True})
  50. with self.assertRaises(AccessError):
  51. param.sudo(u.id).unlink()
  52. def test_can_write(self):
  53. """
  54. It should test that users in the Threshold Manager group can
  55. write the Threshold Param
  56. """
  57. u = self._create_test_user()
  58. self._add_user_to_group(u)
  59. param = self._get_param()
  60. res = '10'
  61. param.sudo(u.id).write({'value': res})
  62. self.assertEquals(param.value, res)
  63. def test_cannot_write(self):
  64. """
  65. It should test that users outside the Threshold Manager group
  66. cannot write the Threshold Param
  67. """
  68. u = self._create_test_user()
  69. system_group = self.env.ref('base.group_system')
  70. access_group = self.env.ref('base.group_erp_manager')
  71. u.write({
  72. 'in_group_%s' % system_group.id: True,
  73. 'in_group_%s' % access_group.id: True,
  74. })
  75. param = self._get_param()
  76. with self.assertRaises(AccessError):
  77. param.sudo(u.id).write({'value': '10'})