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.

76 lines
2.8 KiB

  1. # -*- coding: utf-8 -*-
  2. # (c) 2015 ACSONE SA/NV, Dhinesh D
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests import common
  5. class TestIrConfigParameter(common.TransactionCase):
  6. def setUp(self):
  7. super(TestIrConfigParameter, self).setUp()
  8. self.db = self.env.cr.dbname
  9. self.param_obj = self.env['ir.config_parameter']
  10. self.data_obj = self.env['ir.model.data']
  11. self.delay = self.env.ref(
  12. 'auth_session_timeout.inactive_session_time_out_delay')
  13. def test_check_session_param_delay(self):
  14. delay = self.param_obj._auth_timeout_get_parameter_delay()
  15. self.assertEqual(delay, int(self.delay.value))
  16. self.assertIsInstance(delay, int)
  17. def test_check_session_param_urls(self):
  18. urls = self.param_obj._auth_timeout_get_parameter_ignored_urls()
  19. self.assertIsInstance(urls, list)
  20. class TestIrConfigParameterCaching(common.TransactionCase):
  21. def setUp(self):
  22. super(TestIrConfigParameterCaching, self).setUp()
  23. self.db = self.env.cr.dbname
  24. self.param_obj = self.env['ir.config_parameter']
  25. self.get_param_called = False
  26. test = self
  27. def get_param(*args, **kwargs):
  28. test.get_param_called = True
  29. return orig_get_param(*args[1:], **kwargs)
  30. orig_get_param = self.param_obj.get_param
  31. self.param_obj._patch_method(
  32. 'get_param',
  33. get_param)
  34. def tearDown(self):
  35. super(TestIrConfigParameterCaching, self).tearDown()
  36. self.param_obj._revert_method('get_param')
  37. def test_auth_timeout_get_parameter_delay_cache(self):
  38. """It should cache the parameter call."""
  39. self.get_param_called = False
  40. self.param_obj._auth_timeout_get_parameter_delay()
  41. self.assertTrue(self.get_param_called)
  42. def test_auth_timeout_get_parameter_ignored_urls_cache(self):
  43. """It should cache the parameter call."""
  44. self.get_param_called = False
  45. self.param_obj._auth_timeout_get_parameter_ignored_urls()
  46. self.assertTrue(self.get_param_called)
  47. def test_check_param_writes_clear_delay_cache(self):
  48. self.param_obj._auth_timeout_get_parameter_delay()
  49. self.get_param_called = False
  50. self.param_obj.set_param('inactive_session_time_out_delay', 7201)
  51. self.param_obj._auth_timeout_get_parameter_delay()
  52. self.assertTrue(self.get_param_called)
  53. def test_check_param_writes_clear_ignore_url_cache(self):
  54. self.param_obj._auth_timeout_get_parameter_ignored_urls()
  55. self.get_param_called = False
  56. self.param_obj.set_param('inactive_session_time_out_ignored_url',
  57. 'example.com')
  58. self.param_obj._auth_timeout_get_parameter_ignored_urls()
  59. self.assertTrue(self.get_param_called)