tests: remove db modifications from individual tests
All db seeding now down in conftest
This commit is contained in:
parent
8b89595531
commit
778f1dbece
8 changed files with 160 additions and 394 deletions
|
|
@ -7,27 +7,15 @@ Delete endpoints are currently skipped because the testing system cannot use bod
|
|||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
from src.organisation.models import Organisation as Org, OrgUsers
|
||||
from src.user.models import User
|
||||
from src.iam.models import Group
|
||||
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.auth,
|
||||
pytest.mark.preapproval,
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def set_org_partial(db_session):
|
||||
org_model = db_session.get(Org, 1)
|
||||
org_model.status = "partial"
|
||||
db_session.flush()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_org_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.get("/org?org_id=1")
|
||||
resp = await default_client.get("/org?org_id=3")
|
||||
assert resp.status_code != 422
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
|
@ -37,7 +25,7 @@ async def test_patch_org_questionnaire_auth_approval(default_client: AsyncClient
|
|||
resp = await default_client.patch(
|
||||
"/org/questionnaire",
|
||||
json={
|
||||
"organisation_id": 1,
|
||||
"organisation_id": 3,
|
||||
"intake_questionnaire": {
|
||||
"question_one": "new answer one",
|
||||
"question_two": None,
|
||||
|
|
@ -53,7 +41,7 @@ async def test_patch_org_questionnaire_auth_approval(default_client: AsyncClient
|
|||
@pytest.mark.anyio
|
||||
async def test_patch_org_status_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.patch(
|
||||
"/org/status", json={"organisation_id": 1, "status": "submitted"}
|
||||
"/org/status", json={"organisation_id": 3, "status": "submitted"}
|
||||
)
|
||||
assert resp.status_code != 422
|
||||
assert resp.status_code == 200
|
||||
|
|
@ -61,48 +49,24 @@ async def test_patch_org_status_auth_approval(default_client: AsyncClient):
|
|||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_org_users_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.get("/org/users?org_id=1")
|
||||
resp = await default_client.get("/org/users?org_id=3")
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_post_org_user_auth_approval(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()
|
||||
|
||||
async def test_post_org_user_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.post(
|
||||
"/org/user", json={"organisation_id": 1, "user_id": 2}
|
||||
"/org/user", json={"organisation_id": 3, "user_id": 2}
|
||||
)
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_patch_org_root_user_auth_approval(
|
||||
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()
|
||||
db_session.add(OrgUsers(org_id=1, user_id=2))
|
||||
db_session.flush()
|
||||
|
||||
async def test_patch_org_root_user_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.patch(
|
||||
"/org/root_user", json={"organisation_id": 1, "user_id": 2}
|
||||
"/org/root_user", json={"organisation_id": 3, "user_id": 2}
|
||||
)
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
|
@ -110,14 +74,14 @@ async def test_patch_org_root_user_auth_approval(
|
|||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_org_groups_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.get("/org/groups?org_id=1")
|
||||
resp = await default_client.get("/org/groups?org_id=3")
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_org_contact_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.get("/org/contact?org_id=1&contact_type=billing")
|
||||
resp = await default_client.get("/org/contact?org_id=3&contact_type=billing")
|
||||
assert resp.status_code != 422
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
|
@ -127,7 +91,7 @@ async def test_patch_org_contact_auth_approval(default_client: AsyncClient):
|
|||
resp = await default_client.patch(
|
||||
"/org/contact",
|
||||
json={
|
||||
"organisation_id": 1,
|
||||
"organisation_id": 3,
|
||||
"contact_type": "billing",
|
||||
"email": "user@example.com",
|
||||
},
|
||||
|
|
@ -138,21 +102,21 @@ async def test_patch_org_contact_auth_approval(default_client: AsyncClient):
|
|||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_service_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.get("/service?org_id=1")
|
||||
resp = await default_client.get("/service?org_id=3")
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_iam_group_permissions_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.get("/iam/group/permissions?org_id=1&group_id=1")
|
||||
resp = await default_client.get("/iam/group/permissions?org_id=3&group_id=1")
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_iam_group_users_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.get("/iam/group/users?org_id=1&group_id=1")
|
||||
resp = await default_client.get("/iam/group/users?org_id=3&group_id=1")
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
||||
|
|
@ -160,42 +124,26 @@ async def test_get_iam_group_users_auth_approval(default_client: AsyncClient):
|
|||
@pytest.mark.anyio
|
||||
async def test_post_iam_group_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.post(
|
||||
"/iam/group", json={"name": "New Group", "organisation_id": 1}
|
||||
"/iam/group", json={"name": "New Group", "organisation_id": 3}
|
||||
)
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_put_iam_group_permission_auth_approval(
|
||||
default_client: AsyncClient, db_session
|
||||
):
|
||||
db_session.add(Group(name="Test Group Two", org_id=1))
|
||||
db_session.flush()
|
||||
async def test_put_iam_group_permission_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.put(
|
||||
"/iam/group/permission",
|
||||
json={"permission_id": 1, "group_id": 2, "organisation_id": 1},
|
||||
json={"permission_id": 1, "group_id": 2, "organisation_id": 3},
|
||||
)
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_put_iam_group_user_auth_approval(
|
||||
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()
|
||||
|
||||
async def test_put_iam_group_user_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.put(
|
||||
"/iam/group/user", json={"user_id": 2, "group_id": 1, "organisation_id": 1}
|
||||
"/iam/group/user", json={"user_id": 2, "group_id": 1, "organisation_id": 3}
|
||||
)
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
|
@ -203,7 +151,7 @@ async def test_put_iam_group_user_auth_approval(
|
|||
|
||||
@pytest.mark.anyio
|
||||
async def test_get_iam_permissions_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.get("/iam/permissions?org_id=1")
|
||||
resp = await default_client.get("/iam/permissions?org_id=3")
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
||||
|
|
@ -211,7 +159,7 @@ async def test_get_iam_permissions_auth_approval(default_client: AsyncClient):
|
|||
@pytest.mark.anyio
|
||||
async def test_post_iam_permissions_search_auth_approval(default_client: AsyncClient):
|
||||
resp = await default_client.post(
|
||||
"/iam/permissions/search", json={"organisation_id": 1, "action": "read"}
|
||||
"/iam/permissions/search", json={"organisation_id": 3, "action": "read"}
|
||||
)
|
||||
assert resp.status_code != 422
|
||||
assert "has not been approved." in resp.json()["detail"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue