server-ux/easy_switch_user/tests/test_controller.py
2021-03-23 20:38:33 +01:00

31 lines
859 B
Python

# 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