Browse Source
Module auth_session_timeout: Pluggability (#887)
Module auth_session_timeout: Pluggability (#887)
* Module auth_session_timeout: --------------------------- * Refactor to allow other modules to inherit and augment or override the following: ** Session expiry time (deadline) calculation ** Ignored URLs ** Final session expiry (with possibility to late-abort) * Re-ordered functionality to remove unnecessary work, as this code is called very often. * Do not expire a session if delay gets set to zero (or unset / false) * WIP * Fixed flake8 lint errors * Fixed flake8 lint errors * WIP * WIP * WIP * WIP * WIP * WIP * Module: auth-session-timeout: Refactor ResUser tests to use `unittest.mock` patching * Module: auth_session_timeout: Fixed flake8 lint errors * Module: auth_session_timeout: Fixed flake8 lint errorspull/979/head
jmorgannz
7 years ago
committed by
Dave Lasley
7 changed files with 191 additions and 27 deletions
-
1auth_session_timeout/README.rst
-
3auth_session_timeout/__openerp__.py
-
15auth_session_timeout/models/ir_config_parameter.py
-
98auth_session_timeout/models/res_users.py
-
1auth_session_timeout/tests/__init__.py
-
57auth_session_timeout/tests/test_ir_config_parameter.py
-
43auth_session_timeout/tests/test_res_user.py
@ -0,0 +1,43 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
import mock |
||||
|
from os import strerror |
||||
|
from errno import ENOENT |
||||
|
|
||||
|
from openerp.tests import common |
||||
|
|
||||
|
|
||||
|
_packagepath = 'openerp.addons.auth_session_timeout' |
||||
|
|
||||
|
|
||||
|
class ResUsers(common.TransactionCase): |
||||
|
def setUp(self): |
||||
|
super(ResUsers, self).setUp() |
||||
|
self.resusers_obj = self.env['res.users'] |
||||
|
|
||||
|
@mock.patch(_packagepath + '.models.res_users.request') |
||||
|
@mock.patch(_packagepath + '.models.res_users.root') |
||||
|
@mock.patch(_packagepath + '.models.res_users.getmtime') |
||||
|
def test_on_timeout_session_loggedout(self, mock_getmtime, |
||||
|
mock_root, mock_request): |
||||
|
mock_getmtime.return_value = 0 |
||||
|
mock_request.session.uid = self.env.uid |
||||
|
mock_request.session.dbname = self.env.cr.dbname |
||||
|
mock_request.session.sid = 123 |
||||
|
mock_request.session.logout = mock.Mock() |
||||
|
self.resusers_obj._auth_timeout_check() |
||||
|
self.assertTrue(mock_request.session.logout.called) |
||||
|
|
||||
|
@mock.patch(_packagepath + '.models.res_users.request') |
||||
|
@mock.patch(_packagepath + '.models.res_users.root') |
||||
|
@mock.patch(_packagepath + '.models.res_users.getmtime') |
||||
|
@mock.patch(_packagepath + '.models.res_users.utime') |
||||
|
def test_sessionfile_io_exceptions_managed(self, mock_utime, mock_getmtime, |
||||
|
mock_root, mock_request): |
||||
|
mock_getmtime.side_effect = OSError( |
||||
|
ENOENT, strerror(ENOENT), 'non-existent-filename') |
||||
|
mock_request.session.uid = self.env.uid |
||||
|
mock_request.session.dbname = self.env.cr.dbname |
||||
|
mock_request.session.sid = 123 |
||||
|
self.resusers_obj._auth_timeout_check() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue