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.

43 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. import mock
  4. from os import strerror
  5. from errno import ENOENT
  6. from openerp.tests import common
  7. _packagepath = 'openerp.addons.auth_session_timeout'
  8. class ResUsers(common.TransactionCase):
  9. def setUp(self):
  10. super(ResUsers, self).setUp()
  11. self.resusers_obj = self.env['res.users']
  12. @mock.patch(_packagepath + '.models.res_users.request')
  13. @mock.patch(_packagepath + '.models.res_users.root')
  14. @mock.patch(_packagepath + '.models.res_users.getmtime')
  15. def test_on_timeout_session_loggedout(self, mock_getmtime,
  16. mock_root, mock_request):
  17. mock_getmtime.return_value = 0
  18. mock_request.session.uid = self.env.uid
  19. mock_request.session.dbname = self.env.cr.dbname
  20. mock_request.session.sid = 123
  21. mock_request.session.logout = mock.Mock()
  22. self.resusers_obj._auth_timeout_check()
  23. self.assertTrue(mock_request.session.logout.called)
  24. @mock.patch(_packagepath + '.models.res_users.request')
  25. @mock.patch(_packagepath + '.models.res_users.root')
  26. @mock.patch(_packagepath + '.models.res_users.getmtime')
  27. @mock.patch(_packagepath + '.models.res_users.utime')
  28. def test_sessionfile_io_exceptions_managed(self, mock_utime, mock_getmtime,
  29. mock_root, mock_request):
  30. mock_getmtime.side_effect = OSError(
  31. ENOENT, strerror(ENOENT), 'non-existent-filename')
  32. mock_request.session.uid = self.env.uid
  33. mock_request.session.dbname = self.env.cr.dbname
  34. mock_request.session.sid = 123
  35. self.resusers_obj._auth_timeout_check()