Example #1
0
    def test_get_user_id_without_sessionid(self):
        sessionid = '321'
        user_id = 123

        request = mock.MagicMock(
            COOKIES={}
        )
        user_db.create_session_data(sessionid, {'user_id': user_id})
        auth_user_id = auth.get_user_id(request)

        self.assertEqual(auth_user_id, None)
Example #2
0
    def test_get_user_id_wrong_sessionid(self):
        sessionid = '321'
        sessionid_in_db = '322'
        user_id = 123

        request = mock.MagicMock(
            COOKIES={auth.SESSION_KEY: sessionid}
        )
        user_db.create_session_data(sessionid_in_db, {'user_id': user_id})
        auth_user_id = auth.get_user_id(request)

        self.assertEqual(auth_user_id, None)
Example #3
0
    def test_set_session_data(self):
        username = '******'
        password = '******'
        user_id = user_db.create_user(username, password)
        session_id = str(utils.get_random_string(50))
        data = {'user_id' : user_id}

        user_db.create_session_data(session_id, data)

        session = user_db.get_session(session_id)

        self.assertEqual(session.data, data)
Example #4
0
    def test_logout_user(self):
        sessionid = '321'
        user_id = 123
        request = mock.MagicMock(COOKIES={auth.SESSION_KEY : sessionid})
        user_db.create_session_data(sessionid, {'user_id': user_id})
        response = mock.MagicMock()

        auth.logout_user(request, response)

        session_data = user_db.get_session(sessionid)

        self.assertEqual(session_data, None)
        response.delete_cookie.assert_called_with(
            key=auth.SESSION_KEY
        )
Example #5
0
    def test_del_session(self):
        user_id1 = factories.create_user()
        user_id2 = factories.create_user()
        session_id = str(utils.get_random_string(50))
        session_id2 = str(utils.get_random_string(50))
        data = {'user_id': user_id1}
        data2 = {'user_id': user_id2}
        user_db.create_session_data(session_id, data)
        user_db.create_session_data(session_id2, data2)

        user_db.del_session(session_id)

        deleted_row = user_db.get_session(session_id)
        session2 = user_db.get_session(session_id2)

        self.assertEqual(deleted_row, None)
        self.assertEqual(session2.data, data2)
Example #6
0
def authorize_user(response, user_id):
    sessionid = _generate_sessionid()
    user_db.create_session_data(sessionid, {'user_id': user_id})
    response.set_cookie(key=SESSION_KEY, value=sessionid, max_age=None)
    return response