Пример #1
0
 def test_passwords_hashed(self):
     """
     Passwords are hashed before being saved to the database.
     """
     self.app.post('/signup',
                   content_type='application/json',
                   data=json.dumps(USER_DATA))
     user = load_user_from_id(user_id=USER_DATA['email'])
     self.assertTrue(
         bcrypt.check_password_hash(user.password_hash,
                                    USER_DATA['password']))
 def test_passwords_hashed(self):
     """
     Passwords are hashed before being saved to the database.
     """
     self.app.post(
         '/signup',
         content_type='application/json',
         data=json.dumps(USER_DATA))
     user = load_user_from_id(user_id=USER_DATA['email'])
     self.assertTrue(bcrypt.check_password_hash(user.password_hash,
                                                USER_DATA['password']))
Пример #3
0
 def test_user_exists(self):
     """
     If a user exists with the email given as the user ID to
     ``load_user_from_id``, that user is returned.
     """
     self.app.post('/signup',
                   content_type='application/json',
                   data=json.dumps(USER_DATA))
     self.assertEqual(
         load_user_from_id(user_id=USER_DATA['email']).email,
         USER_DATA['email'],
     )
 def test_user_exists(self):
     """
     If a user exists with the email given as the user ID to
     ``load_user_from_id``, that user is returned.
     """
     self.app.post(
         '/signup',
         content_type='application/json',
         data=json.dumps(USER_DATA))
     self.assertEqual(
         load_user_from_id(user_id=USER_DATA['email']).email,
         USER_DATA['email'],
     )
Пример #5
0
    def test_delete_user(self):
        """
        A ``DELETE`` request to delete a user returns an OK status code and the
        email of the deleted user. The user no longer exists.
        """
        self.app.post('/signup',
                      content_type='application/json',
                      data=json.dumps(USER_DATA))

        response = self.app.delete(
            '/users/{email}'.format(email=USER_DATA['email']),
            content_type='application/json')

        self.assertEqual(response.headers['Content-Type'], 'application/json')
        self.assertEqual(response.status_code, codes.OK)
        self.assertEqual(json.loads(response.data.decode('utf8')),
                         {'email': USER_DATA['email']})

        self.assertIsNone(load_user_from_id(user_id=USER_DATA['email']))
Пример #6
0
    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)
Пример #7
0
    def test_remember_me_cookie_set(self):
        """
        A "Remember Me" token is in the response header of a successful login
        with the value of ``User.get_auth_token`` for the logged in user.
        """
        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(token, user.get_auth_token())
    def test_delete_user(self):
        """
        A ``DELETE`` request to delete a user returns an OK status code and the
        email of the deleted user. The user no longer exists.
        """
        self.app.post(
            '/signup',
            content_type='application/json',
            data=json.dumps(USER_DATA))

        response = self.app.delete(
            '/users/{email}'.format(email=USER_DATA['email']),
            content_type='application/json')

        self.assertEqual(response.headers['Content-Type'], 'application/json')
        self.assertEqual(response.status_code, codes.OK)
        self.assertEqual(
            json.loads(response.data.decode('utf8')),
            {'email': USER_DATA['email']})

        self.assertIsNone(load_user_from_id(user_id=USER_DATA['email']))
    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_remember_me_cookie_set(self):
        """
        A "Remember Me" token is in the response header of a successful login
        with the value of ``User.get_auth_token`` for the logged in user.
        """
        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(token, user.get_auth_token())
 def test_user_does_not_exist(self):
     """
     If no user exists with the email given as the user ID to
     ``load_user_from_id``, ``None`` is returned.
     """
     self.assertIsNone(load_user_from_id(user_id='email'))
Пример #12
0
 def test_user_does_not_exist(self):
     """
     If no user exists with the email given as the user ID to
     ``load_user_from_id``, ``None`` is returned.
     """
     self.assertIsNone(load_user_from_id(user_id='email'))