forked from sr2/cloud-api
minor: rename test client
client -> default_client To allow for different clients. Primarily to allow different overrides for auth testing.
This commit is contained in:
parent
a907506ec1
commit
9d9ca0b907
7 changed files with 140 additions and 140 deletions
|
|
@ -5,13 +5,13 @@ import pytest
|
|||
from httpx import AsyncClient
|
||||
|
||||
from src.user.models import User
|
||||
from .conftest import client, db_session
|
||||
from .conftest import default_client, db_session
|
||||
|
||||
from src.iam.models import Group
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_post_act_on_resource_endpoint_success(client: AsyncClient):
|
||||
async def test_post_act_on_resource_endpoint_success(default_client: AsyncClient):
|
||||
body = {
|
||||
"service": "Test Service",
|
||||
"organisation": "Test Org",
|
||||
|
|
@ -21,7 +21,7 @@ async def test_post_act_on_resource_endpoint_success(client: AsyncClient):
|
|||
"Authorization": "Bearer not_checked_when_auth_is_disabled",
|
||||
"X-API-Key": "123456789"
|
||||
}
|
||||
resp = await client.post("/iam/can_act_on_resource?action=read", json=body, headers=headers)
|
||||
resp = await default_client.post("/iam/can_act_on_resource?action=read", json=body, headers=headers)
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -41,7 +41,7 @@ async def test_post_act_on_resource_endpoint_success(client: AsyncClient):
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_post_act_on_resource_endpoint_failure(client: AsyncClient, service, org, resource, action,
|
||||
async def test_post_act_on_resource_endpoint_failure(default_client: AsyncClient, service, org, resource, action,
|
||||
expected_status: int):
|
||||
body = {
|
||||
"service": service,
|
||||
|
|
@ -52,14 +52,14 @@ async def test_post_act_on_resource_endpoint_failure(client: AsyncClient, servic
|
|||
"Authorization": "Bearer not_checked_when_auth_is_disabled",
|
||||
"X-API-Key": "123456789"
|
||||
}
|
||||
resp = await client.post(f"/iam/can_act_on_resource?action={action}", json=body, headers=headers)
|
||||
resp = await default_client.post(f"/iam/can_act_on_resource?action={action}", json=body, headers=headers)
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_group_permissions_success(client: AsyncClient):
|
||||
resp = await client.get("/iam/group/permissions?org_id=1&group_id=1")
|
||||
async def test_get_group_permissions_success(default_client: AsyncClient):
|
||||
resp = await default_client.get("/iam/group/permissions?org_id=1&group_id=1")
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -88,15 +88,15 @@ async def test_get_group_permissions_success(client: AsyncClient):
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_get_group_permissions_failure(client: AsyncClient, query: str, expected_status: int):
|
||||
resp = await client.get(f"/iam/group/permissions?{query}")
|
||||
async def test_get_group_permissions_failure(default_client: AsyncClient, query: str, expected_status: int):
|
||||
resp = await default_client.get(f"/iam/group/permissions?{query}")
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_group_users_success(client: AsyncClient):
|
||||
resp = await client.get("/iam/group/users?org_id=1&group_id=1")
|
||||
async def test_get_group_users_success(default_client: AsyncClient):
|
||||
resp = await default_client.get("/iam/group/users?org_id=1&group_id=1")
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -126,15 +126,15 @@ async def test_get_group_users_success(client: AsyncClient):
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_get_group_users_failure(client: AsyncClient, query: str, expected_status: int):
|
||||
resp = await client.get(f"/iam/group/users?{query}")
|
||||
async def test_get_group_users_failure(default_client: AsyncClient, query: str, expected_status: int):
|
||||
resp = await default_client.get(f"/iam/group/users?{query}")
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_post_group_success(client: AsyncClient):
|
||||
resp = await client.post("/iam/group", json={"name": "New Group", "organisation_id": 1})
|
||||
async def test_post_group_success(default_client: AsyncClient):
|
||||
resp = await default_client.post("/iam/group", json={"name": "New Group", "organisation_id": 1})
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -161,17 +161,17 @@ async def test_post_group_success(client: AsyncClient):
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_post_group_failure(client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await client.post("/iam/group", json=body)
|
||||
async def test_post_group_failure(default_client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await default_client.post("/iam/group", json=body)
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_put_group_perm_success(client: AsyncClient, db_session):
|
||||
async def test_put_group_perm_success(default_client: AsyncClient, db_session):
|
||||
db_session.add(Group(name="Test Group Two", org_id=1))
|
||||
db_session.flush()
|
||||
resp = await client.put("/iam/group/permission", json={"permission_id": 1, "group_id": 2, "organisation_id": 1})
|
||||
resp = await default_client.put("/iam/group/permission", json={"permission_id": 1, "group_id": 2, "organisation_id": 1})
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -217,18 +217,18 @@ async def test_put_group_perm_success(client: AsyncClient, db_session):
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_put_group_perm_failure(client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await client.put("/iam/group/permission", json=body)
|
||||
async def test_put_group_perm_failure(default_client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await default_client.put("/iam/group/permission", json=body)
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_put_group_user_success(client: AsyncClient, db_session):
|
||||
async def test_put_group_user_success(default_client: AsyncClient, db_session):
|
||||
db_session.add(User(email="user@test.org", first_name="User", last_name="Test", oidc_id="abcd-efgh-ijkl-1234"))
|
||||
db_session.flush()
|
||||
|
||||
resp = await client.put("/iam/group/user", json={"user_id": 2, "group_id": 1, "organisation_id": 1})
|
||||
resp = await default_client.put("/iam/group/user", json={"user_id": 2, "group_id": 1, "organisation_id": 1})
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -275,15 +275,15 @@ async def test_put_group_user_success(client: AsyncClient, db_session):
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_put_group_user_failure(client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await client.put("/iam/group/user", json=body)
|
||||
async def test_put_group_user_failure(default_client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await default_client.put("/iam/group/user", json=body)
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_permissions_success(client: AsyncClient):
|
||||
resp = await client.get("/iam/permissions?org_id=1")
|
||||
async def test_get_permissions_success(default_client: AsyncClient):
|
||||
resp = await default_client.get("/iam/permissions?org_id=1")
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -305,15 +305,15 @@ async def test_get_permissions_success(client: AsyncClient):
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_get_permissions_failure(client: AsyncClient, query: str, expected_status: int):
|
||||
resp = await client.get(f"/iam/permissions?{query}")
|
||||
async def test_get_permissions_failure(default_client: AsyncClient, query: str, expected_status: int):
|
||||
resp = await default_client.get(f"/iam/permissions?{query}")
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_post_perm_success(client: AsyncClient, db_session):
|
||||
resp = await client.post("/iam/permission", json={"service_id": 1, "resource": "test_resource", "action": "create"})
|
||||
async def test_post_perm_success(default_client: AsyncClient, db_session):
|
||||
resp = await default_client.post("/iam/permission", json={"service_id": 1, "resource": "test_resource", "action": "create"})
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -351,8 +351,8 @@ async def test_post_perm_success(client: AsyncClient, db_session):
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_post_perm_failure(client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await client.post("/iam/permission", json=body)
|
||||
async def test_post_perm_failure(default_client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await default_client.post("/iam/permission", json=body)
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
|
||||
|
|
@ -371,8 +371,8 @@ async def test_post_perm_failure(client: AsyncClient, body: dict[str, str], expe
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_post_perm_search_success(client: AsyncClient, db_session, body):
|
||||
resp = await client.post("/iam/permissions/search", json=body)
|
||||
async def test_post_perm_search_success(default_client: AsyncClient, db_session, body):
|
||||
resp = await default_client.post("/iam/permissions/search", json=body)
|
||||
data = resp.json()
|
||||
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -408,7 +408,7 @@ async def test_post_perm_search_success(client: AsyncClient, db_session, body):
|
|||
],
|
||||
)
|
||||
@pytest.mark.anyio
|
||||
async def test_post_perm_search_failure(client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await client.post("/iam/permissions/search", json=body)
|
||||
async def test_post_perm_search_failure(default_client: AsyncClient, body: dict[str, str], expected_status: int):
|
||||
resp = await default_client.post("/iam/permissions/search", json=body)
|
||||
|
||||
assert resp.status_code == expected_status
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue