tests: org tests standardised
This commit is contained in:
parent
ce6a574951
commit
71adc3fc6a
1 changed files with 210 additions and 144 deletions
|
|
@ -2,10 +2,12 @@
|
||||||
[DELETE] /org/ is not tested because the testing client cannot attach a body to a delete request.
|
[DELETE] /org/ is not tested because the testing client cannot attach a body to a delete request.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
|
|
||||||
from .conftest import generate_query_and_status
|
from .conftest import generate_query_and_status, standard_test
|
||||||
|
|
||||||
|
|
||||||
pytestmark = [
|
pytestmark = [
|
||||||
|
|
@ -13,28 +15,6 @@ pytestmark = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
|
||||||
async def test_get_org_success(default_client: AsyncClient):
|
|
||||||
resp = await default_client.get("/org?org_id=1")
|
|
||||||
data = resp.json()
|
|
||||||
|
|
||||||
assert resp.status_code == 200
|
|
||||||
|
|
||||||
org = data["organisations"][0]
|
|
||||||
|
|
||||||
assert isinstance(org, dict)
|
|
||||||
assert org["organisation_id"] == 1
|
|
||||||
assert org["name"] == "Org One"
|
|
||||||
assert org["status"] == "approved"
|
|
||||||
assert org["root_user_email"] == "admin@test.com"
|
|
||||||
assert "intake_questionnaire" in org
|
|
||||||
assert isinstance(org["intake_questionnaire"], dict)
|
|
||||||
|
|
||||||
assert org["billing_contact"]["email"] == "billing@orgone.com"
|
|
||||||
assert org["owner_contact"]["email"] == "owner@orgone.com"
|
|
||||||
assert org["security_contact"]["email"] == "security@orgone.com"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("query, expected_status", generate_query_and_status(["org_id"]))
|
@pytest.mark.parametrize("query, expected_status", generate_query_and_status(["org_id"]))
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_get_org_status_checks(
|
async def test_get_org_status_checks(
|
||||||
|
|
@ -45,16 +25,6 @@ async def test_get_org_status_checks(
|
||||||
assert resp.status_code == expected_status
|
assert resp.status_code == expected_status
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
|
||||||
async def test_post_org_success(default_client: AsyncClient):
|
|
||||||
resp = await default_client.post("/org", json={"name": "New Test Org"})
|
|
||||||
data = resp.json()
|
|
||||||
|
|
||||||
assert resp.status_code == 201
|
|
||||||
assert data["name"] == "New Test Org"
|
|
||||||
assert data["status"] == "partial"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"body, expected_status",
|
"body, expected_status",
|
||||||
[
|
[
|
||||||
|
|
@ -72,36 +42,6 @@ async def test_post_org_status_checks(
|
||||||
assert resp.status_code == expected_status
|
assert resp.status_code == expected_status
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
|
||||||
async def test_patch_org_questionnaire_partial_success(default_client: AsyncClient):
|
|
||||||
resp = await default_client.patch(
|
|
||||||
"/org/questionnaire",
|
|
||||||
json={
|
|
||||||
"organisation_id": 3,
|
|
||||||
"intake_questionnaire": {
|
|
||||||
"question_one": "new answer one",
|
|
||||||
"question_two": None,
|
|
||||||
"question_three": None,
|
|
||||||
},
|
|
||||||
"partial": True,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
data = resp.json()
|
|
||||||
|
|
||||||
assert resp.status_code == 200
|
|
||||||
assert data["name"] == "Org Three"
|
|
||||||
assert data["status"] == "partial"
|
|
||||||
assert "intake_questionnaire" in data
|
|
||||||
assert isinstance(data["intake_questionnaire"], dict)
|
|
||||||
metadata = data["intake_questionnaire"]["metadata"]
|
|
||||||
assert metadata["version"] == 0
|
|
||||||
assert metadata["submission_date"] is None
|
|
||||||
questions = data["intake_questionnaire"]["questions"]
|
|
||||||
assert questions["question_one"] == "new answer one"
|
|
||||||
assert questions["question_two"] == "answer two"
|
|
||||||
assert questions["question_three"] is None
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"body, expected_status",
|
"body, expected_status",
|
||||||
[
|
[
|
||||||
|
|
@ -205,27 +145,6 @@ async def test_patch_org_status_status_checks(
|
||||||
assert resp.status_code == expected_status
|
assert resp.status_code == expected_status
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
|
||||||
async def test_get_org_users_success(default_client: AsyncClient):
|
|
||||||
resp = await default_client.get("/org/users?org_id=1")
|
|
||||||
data = resp.json()
|
|
||||||
|
|
||||||
assert resp.status_code == 200
|
|
||||||
|
|
||||||
assert "users" in data
|
|
||||||
assert isinstance(data["users"], list)
|
|
||||||
assert len(data["users"]) == 2
|
|
||||||
|
|
||||||
user = data["users"][0]
|
|
||||||
assert isinstance(user, dict)
|
|
||||||
assert user["email"] == "admin@test.com"
|
|
||||||
assert user["id"] == 1
|
|
||||||
|
|
||||||
assert "organisation" in data
|
|
||||||
assert data["organisation"]["name"] == "Org One"
|
|
||||||
assert data["organisation"]["id"] == 1
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("query, expected_status", generate_query_and_status(["org_id"]))
|
@pytest.mark.parametrize("query, expected_status", generate_query_and_status(["org_id"]))
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_get_org_users_status_checks(
|
async def test_get_org_users_status_checks(
|
||||||
|
|
@ -236,24 +155,6 @@ async def test_get_org_users_status_checks(
|
||||||
assert resp.status_code == expected_status
|
assert resp.status_code == expected_status
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
|
||||||
async def test_post_org_user_success(default_client: AsyncClient):
|
|
||||||
resp = await default_client.post("/org/user", json={"organisation_id": 1, "user_id": 3})
|
|
||||||
|
|
||||||
assert resp.status_code == 200
|
|
||||||
|
|
||||||
data = resp.json()
|
|
||||||
|
|
||||||
assert "organisation" in data
|
|
||||||
assert isinstance(data["organisation"], dict)
|
|
||||||
assert data["organisation"]["id"] == 1
|
|
||||||
assert data["organisation"]["name"] == "Org One"
|
|
||||||
|
|
||||||
assert "users" in data
|
|
||||||
assert isinstance(data["users"], list)
|
|
||||||
assert len([user for user in data["users"] if user["email"] == "root@orgtwo.com"]) == 1
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"body, expected_status",
|
"body, expected_status",
|
||||||
[
|
[
|
||||||
|
|
@ -274,19 +175,6 @@ async def test_post_org_user_status_checks(
|
||||||
assert resp.status_code == expected_status
|
assert resp.status_code == expected_status
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
|
||||||
async def test_patch_org_root_user_success(default_client: AsyncClient):
|
|
||||||
resp = await default_client.patch(
|
|
||||||
"/org/root_user", json={"organisation_id": 1, "user_id": 2}
|
|
||||||
)
|
|
||||||
assert resp.status_code == 200
|
|
||||||
|
|
||||||
data = resp.json()
|
|
||||||
|
|
||||||
assert data["name"] == "Org One"
|
|
||||||
assert data["root_user_email"] == "user@orgone.com"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"body, expected_status",
|
"body, expected_status",
|
||||||
[
|
[
|
||||||
|
|
@ -319,26 +207,6 @@ async def test_patch_org_root_user_non_member(default_client: AsyncClient):
|
||||||
assert data["detail"] == "This user does not belong to your organisation."
|
assert data["detail"] == "This user does not belong to your organisation."
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
|
||||||
async def test_get_org_groups_success(default_client: AsyncClient):
|
|
||||||
resp = await default_client.get("/org/groups?org_id=1")
|
|
||||||
assert resp.status_code == 200
|
|
||||||
|
|
||||||
data = resp.json()
|
|
||||||
|
|
||||||
assert "organisation" in data
|
|
||||||
assert isinstance(data["organisation"], dict)
|
|
||||||
assert data["organisation"]["id"] == 1
|
|
||||||
assert data["organisation"]["name"] == "Org One"
|
|
||||||
|
|
||||||
assert "groups" in data
|
|
||||||
assert isinstance(data["groups"], list)
|
|
||||||
group = data["groups"][0]
|
|
||||||
assert isinstance(group, dict)
|
|
||||||
assert group["id"] == 1
|
|
||||||
assert group["name"] == "Org One Group"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("query, expected_status", generate_query_and_status(["org_id"]))
|
@pytest.mark.parametrize("query, expected_status", generate_query_and_status(["org_id"]))
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_get_org_groups_status_checks(
|
async def test_get_org_groups_status_checks(
|
||||||
|
|
@ -494,21 +362,219 @@ async def test_patch_org_contact_status_checks(
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_delete_org_success(default_client: AsyncClient):
|
async def test_get_org_standard(
|
||||||
resp = await default_client.delete("/org?org_id=1")
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "GET"
|
||||||
|
path = "/org"
|
||||||
|
auth_level = "Root User"
|
||||||
|
query = "?org_id=1"
|
||||||
|
body = {}
|
||||||
|
expected_data = {
|
||||||
|
"organisations": [
|
||||||
|
{
|
||||||
|
"organisation_id": 1,
|
||||||
|
"name": "Org One",
|
||||||
|
"status": "approved",
|
||||||
|
"root_user_email": "admin@test.com",
|
||||||
|
"intake_questionnaire": {
|
||||||
|
"metadata": {"version": 0, "submission_date": None},
|
||||||
|
"questions": {
|
||||||
|
"question_one": None,
|
||||||
|
"question_two": "answer two",
|
||||||
|
"question_three": None,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"billing_contact": {"id": 1, "email": "billing@orgone.com"},
|
||||||
|
"owner_contact": {"id": 2, "email": "owner@orgone.com"},
|
||||||
|
"security_contact": {"id": 3, "email": "security@orgone.com"},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
assert resp.status_code == 204
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_delete_org_users_success(default_client: AsyncClient):
|
async def test_post_org_standard(
|
||||||
resp = await default_client.delete("/org/user?org_id=1&user_id=2")
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "POST"
|
||||||
|
path = "/org"
|
||||||
|
auth_level = "User"
|
||||||
|
query = ""
|
||||||
|
body = {"name": "New Test Org"}
|
||||||
|
expected_data = {"id": 4, "name": "New Test Org", "status": "partial"}
|
||||||
|
|
||||||
assert resp.status_code == 204
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_delete_preapproval_org_success(default_client: AsyncClient):
|
async def test_patch_org_questionnaire_partial_standard(
|
||||||
resp = await default_client.delete("/org/self?org_id=3")
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "PATCH"
|
||||||
|
path = "/org/questionnaire"
|
||||||
|
auth_level = "Root User"
|
||||||
|
query = ""
|
||||||
|
body = {
|
||||||
|
"organisation_id": 3,
|
||||||
|
"intake_questionnaire": {
|
||||||
|
"question_one": "new answer one",
|
||||||
|
"question_two": None,
|
||||||
|
"question_three": None,
|
||||||
|
},
|
||||||
|
"partial": True,
|
||||||
|
}
|
||||||
|
expected_data = {
|
||||||
|
"id": 3,
|
||||||
|
"name": "Org Three",
|
||||||
|
"status": "partial",
|
||||||
|
"intake_questionnaire": {
|
||||||
|
"metadata": {"version": 0, "submission_date": None},
|
||||||
|
"questions": {
|
||||||
|
"question_one": "new answer one",
|
||||||
|
"question_two": "answer two",
|
||||||
|
"question_three": None,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
assert resp.status_code == 204
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_get_org_users_standard(
|
||||||
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "GET"
|
||||||
|
path = "/org/users"
|
||||||
|
auth_level = "Root User"
|
||||||
|
query = "?org_id=1"
|
||||||
|
body = {}
|
||||||
|
expected_data = {
|
||||||
|
"users": [
|
||||||
|
{"email": "admin@test.com", "id": 1},
|
||||||
|
{"email": "user@orgone.com", "id": 2},
|
||||||
|
],
|
||||||
|
"organisation": {"id": 1, "name": "Org One"},
|
||||||
|
}
|
||||||
|
|
||||||
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_post_org_user_standard(
|
||||||
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "POST"
|
||||||
|
path = "/org/user"
|
||||||
|
auth_level = "Super Admin"
|
||||||
|
query = ""
|
||||||
|
body = {"organisation_id": 1, "user_id": 3}
|
||||||
|
expected_data = {
|
||||||
|
"users": [
|
||||||
|
{"email": "admin@test.com", "id": 1},
|
||||||
|
{"email": "user@orgone.com", "id": 2},
|
||||||
|
{"email": "root@orgtwo.com", "id": 3},
|
||||||
|
],
|
||||||
|
"organisation": {"id": 1, "name": "Org One"},
|
||||||
|
}
|
||||||
|
|
||||||
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_patch_org_root_user_standard(
|
||||||
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "PATCH"
|
||||||
|
path = "/org/root_user"
|
||||||
|
auth_level = "Super Admin"
|
||||||
|
query = ""
|
||||||
|
body = {"organisation_id": 1, "user_id": 2}
|
||||||
|
expected_data = {"name": "Org One", "root_user_email": "user@orgone.com"}
|
||||||
|
|
||||||
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_get_org_groups_standard(
|
||||||
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "GET"
|
||||||
|
path = "/org/groups"
|
||||||
|
auth_level = "Root User"
|
||||||
|
query = "?org_id=1"
|
||||||
|
body = {}
|
||||||
|
expected_data = {
|
||||||
|
"groups": [
|
||||||
|
{"name": "Org One Group", "id": 1},
|
||||||
|
{"name": "Org One Group Two", "id": 3},
|
||||||
|
],
|
||||||
|
"organisation": {"id": 1, "name": "Org One"},
|
||||||
|
}
|
||||||
|
|
||||||
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_delete_org_standard(
|
||||||
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "DELETE"
|
||||||
|
path = "/org"
|
||||||
|
auth_level = "Super Admin"
|
||||||
|
query = "?org_id=1"
|
||||||
|
body = {}
|
||||||
|
expected_data = {}
|
||||||
|
|
||||||
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_delete_org_users_standard(
|
||||||
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "DELETE"
|
||||||
|
path = "/org/user"
|
||||||
|
auth_level = "Root User"
|
||||||
|
query = "?org_id=1&user_id=2"
|
||||||
|
body = {}
|
||||||
|
expected_data = {}
|
||||||
|
|
||||||
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.anyio
|
||||||
|
async def test_delete_preapproval_org_standard(
|
||||||
|
default_client: AsyncClient, route_data: dict[str, dict[str, Any]]
|
||||||
|
):
|
||||||
|
method = "DELETE"
|
||||||
|
path = "/org/self"
|
||||||
|
auth_level = "Root User"
|
||||||
|
query = "?org_id=3"
|
||||||
|
body = {}
|
||||||
|
expected_data = {}
|
||||||
|
|
||||||
|
await standard_test(
|
||||||
|
default_client, method, path, auth_level, query, body, expected_data, route_data
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue