def index(request): error = False if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] user = user_db.get_user(username=username) if user and user.check_password(password): response = redirect('/chat/') auth.authorize_user(response, user.id) return response else: error = True return render_to_response('users/index.html', {'error' : error})
def test_success_authorize_user(self, mocked_generate_sessionid): sessioon_id = '123123' user_id = 123 response = mock.MagicMock() mocked_generate_sessionid.return_value = sessioon_id auth.authorize_user(response, user_id) session = user_db.get_session(sessioon_id) self.assertEqual(session.data, {'user_id': user_id}) response.set_cookie.assert_called_with( key=auth.SESSION_KEY, value=sessioon_id, max_age=None, )