Exemple #1
0
    def seed_application_users(self):
        try:
            admin_role = Role(
                role_type=RoleTypes.ADMIN,
                description="Admin role for belisce dev agency platform")
            admin_role.commit()

            client_role = Role(
                role_type=RoleTypes.CLIENT,
                description="Client role for belisce dev agency platform")
            client_role.commit()

            # Define application users
            admin_user = User(
                # TODO load from config
                email="*****@*****.**",
                confirmed=True,
                confirmed_date=datetime.utcnow())

            admin_user.set_password('password')
            admin_user.add_to_role(RoleTypes.ADMIN)
            admin_user.commit()

        except IntegrityError:
            log.info('Data is already present in database')
            pass
Exemple #2
0
def test_clients_can_only_get_own_data(app, client_access_token_header,
                                       client_user):
    # Given
    another_user = User(email='*****@*****.**',
                        name='Another test user')
    another_user.add_to_role(RoleTypes.CLIENT)
    another_user.commit()

    # When
    response = app.test_client().get(
        f'/api/user/{another_user.uuid}',
        headers=client_access_token_header,
    )
    response_body = loads(response.data)

    # Then
    assert response.status_code == 403
    assert 'error' in response_body
def test_user_login_unconfirmed(app):
    # Given
    user = User(email='*****@*****.**', name='test user')
    user.add_to_role(RoleTypes.CLIENT)
    user.set_password('password')
    user.commit()

    login_info = {'email': '*****@*****.**', 'password': '******'}

    # When
    response = app.test_client().post('/api/auth/login',
                                      data=dumps(login_info),
                                      content_type='application/json')
    response_body = loads(response.data)

    # Then
    assert response.status_code == 400
    assert response_body['error'] == 'user not confirmed'
def test_user_login_successful(app):
    # Given
    user = User(email='*****@*****.**', name='test user')
    user.add_to_role(RoleTypes.CLIENT)
    user.set_password('password')
    user.confirm_account()
    user.commit()

    login_info = {'email': '*****@*****.**', 'password': '******'}

    # When
    response = app.test_client().post('/api/auth/login',
                                      data=dumps(login_info),
                                      content_type='application/json')
    response_body = loads(response.data)

    # Then
    assert response.status_code == 200
    assert 'access_token' in response_body
    assert 'refresh_token' in response_body
Exemple #5
0
def client_user(seeded_database):
    client_user = User(email='*****@*****.**')
    client_user.add_to_role(RoleTypes.CLIENT)
    client_user.commit()
    return client_user
Exemple #6
0
def admin_user(seeded_database):
    admin_user = User(email='*****@*****.**')
    admin_user.add_to_role(RoleTypes.ADMIN)
    admin_user.commit()
    return admin_user