@@ -0,0 +1,2657 @@
+# !/usr/bin/python%0A# -*- coding: utf-8 -*-%0Afrom project.tests.base import UtilsTestCase%0Aimport base64%0Aimport project.home.login_manager as lm%0A%0A%0Aclass LoginManagerUtilsTestCase(UtilsTestCase):%0A%0A    def setUp(self):%0A        super(LoginManagerUtilsTestCase, self).setUp()%0A        self.user = self.create_user(is_admin=True)%0A%0A    def test_load_user(self):%0A        %22%22%22%0A        Ensure load_user method is properly working%0A        %22%22%22%0A        # test: invalid user id arguments%0A        self.assertFalse(lm.load_user(None))%0A        self.assertFalse(lm.load_user(%22None%22))%0A        self.assertFalse(lm.load_user(%22%22))%0A        self.assertFalse(lm.load_user(%22?%22))%0A        # test: valid user id%0A        self.assertEqual(self.user, lm.load_user(self.user.id))%0A%0A    def test_load_user_from_request(self):%0A        %22%22%22%0A        Ensure load_user_from_request is working fine either for authentication by api_key and Basic%0A        %22%22%22%0A        # test: invalid arguments%0A        reqctx = self.app.test_request_context(%22?%22, headers=%5B%5D)%0A        self.assertIsNone(lm.load_user_from_request(reqctx.request))%0A        # test: invalid api key%0A        reqctx = self.app.test_request_context(%22?api_key=1234%22)%0A        self.assertIsNone(lm.load_user_from_request(reqctx.request))%0A        # test: valid api key%0A        reqctx = self.app.test_request_context(%22?api_key=%7B%7D%22.format(self.user.api_key))%0A        response = lm.load_user_from_request(reqctx.request)%0A        self.assertIsNotNone(response)%0A        self.assertEqual(response, self.user)%0A        # test: invalid auth Basic String%0A        reqctx = self.app.test_request_context(headers=%7B'Authorization': b%22lol?%22%7D)%0A        self.assertIsNone(lm.load_user_from_request(reqctx.request))%0A        # test: valid auth Basic but invalid base64 user:password%0A        reqctx = self.app.test_request_context(headers=%7B'Authorization': b%22Basic lol?%22%7D)%0A        self.assertIsNone(lm.load_user_from_request(reqctx.request))%0A        # test: valid auth Basic and valid base64 api_key%0A        api_key = base64.b64encode(bytes(self.user.api_key, 'utf8'))%0A        reqctx = self.app.test_request_context(headers=%7B'Authorization': b%22Basic %22 + api_key%7D)%0A        response = lm.load_user_from_request(reqctx.request)%0A        self.assertIsNotNone(response)%0A        self.assertEqual(response, self.user)%0A        # test: valid auth Basic and valid base64 userpassword%0A        userpass = base64.b64encode(b%22username:password%22)%0A        reqctx = self.app.test_request_context(headers=%7B'Authorization': b%22Basic %22 + userpass%7D)%0A        response = lm.load_user_from_request(reqctx.request)%0A        self.assertIsNotNone(response)%0A        self.assertEqual(response, self.user)%0A

Refactor location of tests for login_manager.py