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.

30 lines
850 B

  1. # Copyright 2018 Onestein
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import http
  4. from odoo.tests.common import TransactionCase
  5. from odoo.addons.easy_switch_user.controllers.main import SwitchController
  6. class FakeRequest(object):
  7. def __init__(self, env):
  8. self.db = env.cr.dbname
  9. self.session = FakeSession()
  10. class FakeSession(object):
  11. def authenticate(self, db, login, password):
  12. return False
  13. class TestController(TransactionCase):
  14. def setUp(self):
  15. super(TestController, self).setUp()
  16. self.ctrl = SwitchController()
  17. def test_switch(self):
  18. old_request = http.request
  19. http.request = FakeRequest(self.env)
  20. with self.assertRaises(Exception):
  21. self.ctrl.switch('unknown_user', '1234567890')
  22. http.request = old_request