server-ux/easy_switch_user/tests/test_controller.py

31 lines
859 B
Python
Raw Normal View History

2021-03-23 19:38:33 +00:00
# Copyright 2018 Onestein
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from flectra import http
from flectra.tests.common import TransactionCase
from flectra.addons.easy_switch_user.controllers.main import SwitchController
class FakeRequest(object):
def __init__(self, env):
self.db = env.cr.dbname
self.session = FakeSession()
class FakeSession(object):
def authenticate(self, db, login, password):
return False
class TestController(TransactionCase):
def setUp(self):
super(TestController, self).setUp()
self.ctrl = SwitchController()
def test_switch(self):
old_request = http.request
http.request = FakeRequest(self.env)
with self.assertRaises(Exception):
self.ctrl.switch('unknown_user', '1234567890')
http.request = old_request