Beispiel #1
0
def test_create_user_by_superuser_any_group(server_api,
                                            superuser_token_headers):
    new_group = random_group()
    r = requests.post(f'{server_api}{config.API_V1_STR}/groups/',
                      headers=superuser_token_headers,
                      data=new_group)

    created_group = r.json()

    group_id = created_group['id']

    new_user = random_user(group_id)
    r = requests.post(f'{server_api}{config.API_V1_STR}/users/',
                      headers=superuser_token_headers,
                      data=new_user)

    expected_fields = [
        "id",
        "is_active",
        "created_at",
        "email",
        "first_name",
        "last_name",
        "group",
        "groups_admin",
        "is_superuser",
    ]

    created_user = r.json()

    for expected_field in expected_fields:
        assert expected_field in created_user

    assert r.status_code == 200
def test_assign_group_admin_by_group_admin(superuser_token_headers):
    server_api = get_server_api()
    _, group_admin_auth = random_group_admin(server_api,
                                             superuser_token_headers)

    new_group = random_group()
    r = requests.post(
        f"{server_api}{config.API_V1_STR}/groups/",
        headers=superuser_token_headers,
        data=new_group,
    )

    created_group = r.json()
    group_id = created_group["id"]

    new_user = random_user()
    r = requests.post(
        f"{server_api}{config.API_V1_STR}/users/",
        headers=superuser_token_headers,
        data=new_user,
    )

    created_user = r.json()
    user_id = created_user["id"]

    request_data = {"user_id": user_id}

    r = requests.post(
        f"{server_api}{config.API_V1_STR}/groups/{group_id}/admin_users/",
        headers=group_admin_auth,
        data=request_data,
    )

    assert r.status_code == 400
def test_assign_group_admin_by_group_admin(server_api,
                                           superuser_token_headers):
    _, group_admin_auth = random_group_admin(server_api,
                                             superuser_token_headers)

    new_group = random_group()
    r = requests.post(f'{server_api}{config.API_V1_STR}/groups/',
                      headers=superuser_token_headers,
                      data=new_group)

    created_group = r.json()
    group_id = created_group['id']

    new_user = random_user()
    r = requests.post(f'{server_api}{config.API_V1_STR}/users/',
                      headers=superuser_token_headers,
                      data=new_user)

    created_user = r.json()
    user_id = created_user['id']

    request_data = {"user_id": user_id}

    r = requests.post(
        f'{server_api}{config.API_V1_STR}/groups/{group_id}/admin_users/',
        headers=group_admin_auth,
        data=request_data)

    assert r.status_code == 400
def test_assign_group_admin_by_normal_user(superuser_token_headers):
    server_api = get_server_api()
    new_user = random_user()
    r = requests.post(
        f"{server_api}{config.API_V1_STR}/users/",
        headers=superuser_token_headers,
        data=new_user,
    )

    created_user = r.json()

    if r.status_code == 200:

        email, password = new_user["email"], new_user["password"]
        auth = user_authentication_headers(server_api, email, password)

        new_group = random_group()
        r = requests.post(
            f"{server_api}{config.API_V1_STR}/groups/",
            headers=superuser_token_headers,
            data=new_group,
        )

        created_group = r.json()
        group_id = created_group["id"]

        new_user = random_user()
        r = requests.post(
            f"{server_api}{config.API_V1_STR}/users/",
            headers=superuser_token_headers,
            data=new_user,
        )

        created_user = r.json()
        user_id = created_user["id"]

        request_data = {"user_id": user_id}

        r = requests.post(
            f"{server_api}{config.API_V1_STR}/groups/{group_id}/admin_users/",
            headers=auth,
            data=request_data,
        )

        assert r.status_code == 400
def test_create_group_by_superuser(server_api, superuser_token_headers):

    new_group = random_group()

    r = requests.post(
        f'{server_api}{config.API_V1_STR}/groups/',
        headers=superuser_token_headers,
        data=new_group)

    expected_fields = ['created_at', 'id', 'name', 'users', 'users_admin']
    created_group = r.json()

    for expected_field in expected_fields:
        assert expected_field in created_group

    assert r.status_code == 200

    assert created_group['users'] == []
    assert created_group['users_admin'] == []
    assert created_group['name'] == new_group['name']
def test_create_group_by_normal_user(server_api, superuser_token_headers):
    new_user = random_user()
    r = requests.post(
        f'{server_api}{config.API_V1_STR}/users/',
        headers=superuser_token_headers,
        data=new_user)

    created_user = r.json()

    if r.status_code == 200:

        email, password = new_user['email'], new_user['password']
        auth = user_authentication_headers(server_api, email, password)

        new_group = random_group()
        r = requests.post(
            f'{server_api}{config.API_V1_STR}/groups/',
            headers=auth,
            data=new_group)

        assert r.status_code == 400
Beispiel #7
0
def test_create_group_by_superuser(superuser_token_headers):
    server_api = get_server_api()
    new_group = random_group()

    r = requests.post(
        f"{server_api}{config.API_V1_STR}/groups/",
        headers=superuser_token_headers,
        data=new_group,
    )

    expected_fields = ["created_at", "id", "name", "users", "users_admin"]
    created_group = r.json()

    for expected_field in expected_fields:
        assert expected_field in created_group

    assert r.status_code == 200

    assert created_group["users"] == []
    assert created_group["users_admin"] == []
    assert created_group["name"] == new_group["name"]
def test_assign_group_admin_by_normal_user(server_api,
                                           superuser_token_headers):
    new_user = random_user()
    r = requests.post(f'{server_api}{config.API_V1_STR}/users/',
                      headers=superuser_token_headers,
                      data=new_user)

    created_user = r.json()

    if r.status_code == 200:

        email, password = new_user['email'], new_user['password']
        auth = user_authentication_headers(server_api, email, password)

        new_group = random_group()
        r = requests.post(f'{server_api}{config.API_V1_STR}/groups/',
                          headers=superuser_token_headers,
                          data=new_group)

        created_group = r.json()
        group_id = created_group['id']

        new_user = random_user()
        r = requests.post(f'{server_api}{config.API_V1_STR}/users/',
                          headers=superuser_token_headers,
                          data=new_user)

        created_user = r.json()
        user_id = created_user['id']

        request_data = {"user_id": user_id}

        r = requests.post(
            f'{server_api}{config.API_V1_STR}/groups/{group_id}/admin_users/',
            headers=auth,
            data=request_data)

        assert r.status_code == 400