Exemplo n.º 1
0
    def test_user_activation_with_invalid_token_fails(self, client):
        """ Testing User activation with invalid token """

        token = generate_user_token(5)
        response = client.get(f'{API_BASE_URL}/auth/activate/{token}')

        assert response.status_code == 400
        assert response.json['status'] == 'error'
        assert response.json[
            'message'] == 'Account activation token is invalid'
Exemplo n.º 2
0
    def test_user_activation_succeeds(self, client, new_user):
        """ Testing User activation """

        new_user.save()
        token = generate_user_token(new_user.id)
        response = client.get(f'{API_BASE_URL}/auth/activate/{token}')

        assert response.status_code == 200
        assert response.json['status'] == 'success'
        assert response.json['message'] == 'User successfully activated'
Exemplo n.º 3
0
    def test_user_activation_already_activated_fails(self, client,
                                                     new_activated_user):
        """ Testing User activation already activated """

        new_activated_user.save()
        token = generate_user_token(new_activated_user.id)

        response = client.get(f'{API_BASE_URL}/auth/activate/{token}')

        assert response.status_code == 400
        assert response.json['status'] == 'error'
        assert response.json['message'] == 'User account already activated'
Exemplo n.º 4
0
    def test_user_activation_with_expired_token_fails(self, client, new_user):
        """ Testing User activation with expired token """

        new_user.save()
        token = generate_user_token(new_user.id, expires_sec=0)
        time.sleep(1)
        response = client.get(f'{API_BASE_URL}/auth/activate/{token}')

        assert response.status_code == 400
        assert response.json['status'] == 'error'
        assert response.json[
            'message'] == 'Account activation token is invalid'
Exemplo n.º 5
0
    def test_user_login_with_incorrect_password_fails(self, client, init_db):
        """ Testing user login with incorrect password """

        user_data = json.dumps(INCORRECT_USER_LOGIN_WITH_INCORRECT_PASSWORD)
        token = generate_user_token(1)
        response = client.get(f'{API_BASE_URL}/auth/activate/{token}')
        response2 = client.post(f'{API_BASE_URL}/auth/login',
                                data=user_data,
                                content_type=CONTENT_TYPE)
        print(response2.json)

        message = 'Incorrect username or password'

        assert response2.status_code == 404
        assert response2.json['status'] == 'error'
        assert response2.json['message'] == message
    def test_reset_password_succeeds(self, client, init_db,
                                     new_activated_user):
        """ Testing reset password """

        new_activated_user.save()
        user_data = json.dumps(RESET_PASSWORD_NEW_PASSWORD)
        token = generate_user_token(new_activated_user.id)

        response = client.patch(f'{API_BASE_URL}/auth/reset-password/{token}',
                                data=user_data,
                                content_type=CONTENT_TYPE)
        message = 'User password successfully changed'

        assert response.status_code == 200
        assert response.json['status'] == 'success'
        assert response.json['message'] == message
    def test_reset_password_with_invalid_token_fails(self, client, init_db,
                                                     new_activated_user):
        """ Testing reset password with invalid token """

        new_activated_user.save()
        user_data = json.dumps(RESET_PASSWORD_NEW_PASSWORD)
        token = generate_user_token(new_activated_user.id, expires_sec=0)
        time.sleep(1)

        response = client.patch(f'{API_BASE_URL}/auth/reset-password/{token}',
                                data=user_data,
                                content_type=CONTENT_TYPE)
        message = 'Password reset token is invalid'

        assert response.status_code == 400
        assert response.json['status'] == 'error'
        assert response.json['message'] == message
Exemplo n.º 8
0
    def test_user_login_succeeds(self, client, init_db):
        """ Testing user login """

        user_data = json.dumps(CORRECT_USER_LOGIN)
        token = generate_user_token(1)
        response = client.get(f'{API_BASE_URL}/auth/activate/{token}')
        response2 = client.post(f'{API_BASE_URL}/auth/login',
                                data=user_data,
                                content_type=CONTENT_TYPE)

        message = 'User successfully logged in'

        assert response2.status_code == 200
        assert response2.json['status'] == 'success'
        assert response2.json['message'] == message
        assert 'token' in response2.json['data']
        assert 'user' in response2.json['data']
        assert response2.json['data']['user']['email'] == CORRECT_USER_LOGIN[
            'email']