def test_fake_token(self): """ If a token does not belong to a user, ``None`` is returned. """ self.app.post( '/signup', content_type='application/json', data=json.dumps(USER_DATA)) with app.app_context(): self.assertIsNone(load_user_from_token(auth_token='fake'))
def test_load_user_from_token(self): """ A user is loaded if their token is provided to ``load_user_from_token``. """ self.app.post('/signup', content_type='application/json', data=json.dumps(USER_DATA)) response = self.app.post('/login', content_type='application/json', data=json.dumps(USER_DATA)) cookies = response.headers.getlist('Set-Cookie') items = [list(parse_cookie(cookie).items())[0] for cookie in cookies] headers_dict = {key: value for key, value in items} token = headers_dict['remember_token'] with app.app_context(): user = load_user_from_id(user_id=USER_DATA['email']) self.assertEqual(load_user_from_token(auth_token=token), user)
def test_load_user_from_token(self): """ A user is loaded if their token is provided to ``load_user_from_token``. """ self.app.post( '/signup', content_type='application/json', data=json.dumps(USER_DATA)) response = self.app.post( '/login', content_type='application/json', data=json.dumps(USER_DATA)) cookies = response.headers.getlist('Set-Cookie') items = [list(parse_cookie(cookie).items())[0] for cookie in cookies] headers_dict = {key: value for key, value in items} token = headers_dict['remember_token'] with app.app_context(): user = load_user_from_id(user_id=USER_DATA['email']) self.assertEqual(load_user_from_token(auth_token=token), user)
def test_fake_token(self): """ If a token does not belong to a user, ``None`` is returned. """ self.assertIsNone(load_user_from_token(auth_token='fake_token'))
def test_fake_token(self): """ If a token does not belong to a user, ``None`` is returned. """ self.assertIsNone(load_user_from_token(auth_token='fake_token'))