Пример #1
0
def test_get_non_existing_client(testApp, token):
    response = testApp.get(
        "/users/5",
        headers={'Authorization': token().auth},
    )
    assert response.status_code == 400
    assert response.json() == {'detail': 'User does not exist'}
Пример #2
0
def test_get_user_list(testApp, token):
    response = testApp.get(
        "/users",
        headers={'Authorization': token().auth},
    )
    assert response.status_code == 200
    assert response.json() == {
        'page':
        0,
        'total':
        3,
        'limit':
        10,
        'items': [{
            'id': 1,
            'is_active': True,
            'role': 'admin',
            'username': '******'
        }, {
            'id': 2,
            'is_active': True,
            'role': 'user',
            'username': '******'
        }, {
            'id': 3,
            'is_active': True,
            'role': 'user',
            'username': '******'
        }],
    }
Пример #3
0
def test_valid_login(testApp, token):
    response = testApp.post("/auth/login",
                            json={
                                "username": '******',
                                "password": '******'
                            })
    assert response.status_code == 200
    assert response.json() == {'token': token('admin').raw}
Пример #4
0
def test_valid_token(token):
    authService = AuthenticationService(repository=userRepository)
    response = auth_jwt(token('admin').auth, authService)
    assert response == {
        'id': 1,
        'is_active': True,
        'role': 'admin',
        'username': '******'
    }
Пример #5
0
def test_update_non_existing_user(testApp, token):
    response = testApp.put("/users/5",
                           headers={'Authorization': token().auth},
                           json={
                               "username": "******",
                               "role": "user",
                               'is_active': False,
                               'password': '******'
                           })
    assert response.status_code == 400
    assert response.json() == {'detail': 'User does not exist'}
Пример #6
0
def test_update_user_with_invalid_fields(testApp, token):
    response = testApp.put("/users/3",
                           headers={'Authorization': token().auth},
                           json={
                               "username": "",
                               "role": "user",
                               'is_active': False,
                               'password': '******'
                           })
    assert response.status_code == 400
    assert response.json() == {'detail': "{'username': ['is Required']}"}
Пример #7
0
def test_get_user(testApp, token):
    response = testApp.get(
        "/users/1",
        headers={'Authorization': token().auth},
    )
    assert response.status_code == 200
    assert response.json() == {
        'id': 1,
        'is_active': True,
        'role': 'admin',
        'username': '******'
    }
Пример #8
0
def test_create_existing_user(testApp, token):
    response = testApp.post("/users",
                            headers={'Authorization': token().auth},
                            json={
                                "username": "******",
                                "password": "******",
                                "role": "user"
                            })
    assert response.status_code == 400
    assert response.json() == {
        'detail': "{'username': ['Username already exist']}"
    }
Пример #9
0
def test_create_user(testApp, token):
    response = testApp.post("/users",
                            headers={'Authorization': token().auth},
                            json={
                                "username": "******",
                                "password": "******",
                                "role": "user"
                            })
    assert response.status_code == 200
    assert response.json() == {
        'id': 3,
        'is_active': True,
        'role': 'user',
        'username': '******'
    }
Пример #10
0
def test_update_user(testApp, token):
    response = testApp.put("/users/3",
                           headers={'Authorization': token().auth},
                           json={
                               "username": "******",
                               "role": "user",
                               'is_active': False,
                               'password': '******'
                           })
    assert response.status_code == 200
    assert response.json() == {
        'id': 3,
        'is_active': False,
        'role': 'user',
        'username': '******'
    }
Пример #11
0
def test_get_user_list_with_user_no_valid_role(testApp, token):
    response = testApp.get(
        "/users",
        headers={'Authorization': token('user').auth},
    )
    assert response.status_code == 403
Пример #12
0
def test_delete_non_existing_user(testApp, token):
    response = testApp.delete("/users/3",
                              headers={'Authorization': token().auth})
    assert response.status_code == 400
    assert response.json() == {'detail': 'User does not exist'}
Пример #13
0
def test_delete_user(testApp, token):
    response = testApp.delete("/users/3",
                              headers={'Authorization': token().auth})
    assert response.status_code == 200
Пример #14
0
def test_invalid_token(token):
    authService = AuthenticationService(repository=userRepository)
    with raises(HTTPException) as error:
        auth_jwt(token('invalid').auth, authService)
    assert error.value.status_code == status.HTTP_403_FORBIDDEN