--
This commit is contained in:
@@ -137,18 +137,40 @@ class TestStep3And5Masters:
|
||||
resp = await client.get(f"{API}/doctors", headers=auth["mr2"])
|
||||
assert resp.json() == []
|
||||
|
||||
async def test_mr_cannot_create_a_doctor(self, client, auth, org):
|
||||
"""A3/Q3 — not permitted in the MVP."""
|
||||
async def test_mr_creates_doctor_and_chemist_in_own_hq(self, client, auth, org):
|
||||
"""The MR's new doctor and chemist are assigned to them, so they show up at once."""
|
||||
hq1 = str(org["hq1"].id)
|
||||
doctor = await client.post(
|
||||
f"{API}/doctors",
|
||||
headers=auth["mr1"],
|
||||
json={"headquarters_id": hq1, "name": "Dr Selfmade", "clinic_address": "Nowhere"},
|
||||
)
|
||||
assert doctor.status_code == 201
|
||||
chemist = await client.post(
|
||||
f"{API}/chemists",
|
||||
headers=auth["mr1"],
|
||||
json={"headquarters_id": hq1, "name": "Selfmade Pharmacy", "shop_address": "Nowhere"},
|
||||
)
|
||||
assert chemist.status_code == 201
|
||||
|
||||
doctors = (await client.get(f"{API}/doctors", headers=auth["mr1"])).json()
|
||||
assert doctor.json()["id"] in {d["id"] for d in doctors}
|
||||
chemists = (await client.get(f"{API}/chemists", headers=auth["mr1"])).json()
|
||||
assert chemist.json()["id"] in {c["id"] for c in chemists}
|
||||
|
||||
async def test_mr_cannot_create_outside_own_hq_or_a_product(self, client, auth, org):
|
||||
resp = await client.post(
|
||||
f"{API}/doctors",
|
||||
headers=auth["mr1"],
|
||||
json={
|
||||
"headquarters_id": str(org["hq1"].id),
|
||||
"name": "Dr Selfmade",
|
||||
"headquarters_id": str(org["hq2"].id),
|
||||
"name": "Dr Elsewhere",
|
||||
"clinic_address": "Nowhere",
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 403
|
||||
resp = await client.post(f"{API}/products", headers=auth["mr1"], json={"name": "Pill"})
|
||||
assert resp.status_code == 403
|
||||
|
||||
|
||||
class TestStep4Login:
|
||||
@@ -193,9 +215,10 @@ class TestStep4Login:
|
||||
|
||||
|
||||
class TestFullApprovalFlow:
|
||||
async def test_thirteen_step_flow(self, client, auth, org):
|
||||
async def test_thirteen_step_flow(self, client, auth, org, approved_plan):
|
||||
doctors, chemists = await _create_masters(client, auth, org)
|
||||
today = date.today().isoformat()
|
||||
await approved_plan()
|
||||
|
||||
# --- Step 5: MR creates a DCR ---------------------------------
|
||||
resp = await client.post(
|
||||
@@ -391,8 +414,9 @@ class TestFullApprovalFlow:
|
||||
|
||||
|
||||
class TestNegativeScope:
|
||||
async def _submitted_report(self, client, auth, org):
|
||||
async def _submitted_report(self, client, auth, org, approved_plan):
|
||||
doctors, _ = await _create_masters(client, auth, org, n_doctors=2, n_chemists=1)
|
||||
await approved_plan()
|
||||
resp = await client.post(
|
||||
f"{API}/dcr", headers=auth["mr1"], json={"report_date": date.today().isoformat()}
|
||||
)
|
||||
@@ -409,8 +433,8 @@ class TestNegativeScope:
|
||||
await client.post(f"{API}/dcr/{dcr_id}/submit", headers=auth["mr1"])
|
||||
return dcr_id
|
||||
|
||||
async def test_x1_second_mr_cannot_see_the_first_mrs_report(self, client, auth, org):
|
||||
dcr_id = await self._submitted_report(client, auth, org)
|
||||
async def test_x1_second_mr_cannot_see_the_first_mrs_report(self, client, auth, org, approved_plan):
|
||||
dcr_id = await self._submitted_report(client, auth, org, approved_plan)
|
||||
|
||||
resp = await client.get(f"{API}/dcr/{dcr_id}", headers=auth["mr2"])
|
||||
assert resp.status_code == 403, resp.text
|
||||
@@ -420,8 +444,8 @@ class TestNegativeScope:
|
||||
listing = await client.get(f"{API}/dcr", headers=auth["mr2"])
|
||||
assert listing.json() == []
|
||||
|
||||
async def test_x2_area_manager_of_another_hq_cannot_see_it(self, client, auth, org):
|
||||
dcr_id = await self._submitted_report(client, auth, org)
|
||||
async def test_x2_area_manager_of_another_hq_cannot_see_it(self, client, auth, org, approved_plan):
|
||||
dcr_id = await self._submitted_report(client, auth, org, approved_plan)
|
||||
|
||||
resp = await client.get(f"{API}/dcr/{dcr_id}", headers=auth["am2"])
|
||||
assert resp.status_code == 403, resp.text
|
||||
@@ -435,9 +459,9 @@ class TestNegativeScope:
|
||||
listing = await client.get(f"{API}/dcr?status=PENDING_AM", headers=auth["am2"])
|
||||
assert listing.json() == []
|
||||
|
||||
async def test_x3_admin_cannot_approve(self, client, auth, org):
|
||||
async def test_x3_admin_cannot_approve(self, client, auth, org, approved_plan):
|
||||
"""SEC-2 — the single most important governance rule in the design."""
|
||||
dcr_id = await self._submitted_report(client, auth, org)
|
||||
dcr_id = await self._submitted_report(client, auth, org, approved_plan)
|
||||
|
||||
resp = await client.post(f"{API}/dcr/{dcr_id}/approve", headers=auth["admin"], json={})
|
||||
assert resp.status_code == 403, resp.text
|
||||
@@ -489,7 +513,8 @@ class TestValidationRules:
|
||||
assert resp.status_code == 422
|
||||
assert "back-dating" in resp.json()["error"]["message"]
|
||||
|
||||
async def test_v4_cannot_submit_without_a_doctor_call(self, client, auth, org):
|
||||
async def test_v4_cannot_submit_without_a_doctor_call(self, client, auth, org, approved_plan):
|
||||
await approved_plan()
|
||||
resp = await client.post(
|
||||
f"{API}/dcr", headers=auth["mr1"], json={"report_date": date.today().isoformat()}
|
||||
)
|
||||
@@ -499,8 +524,9 @@ class TestValidationRules:
|
||||
assert submit.status_code == 422
|
||||
assert "at least one doctor call" in submit.json()["error"]["message"]
|
||||
|
||||
async def test_v6_unassigned_doctor_rejected(self, client, auth, org):
|
||||
async def test_v6_unassigned_doctor_rejected(self, client, auth, org, approved_plan):
|
||||
"""A doctor from another HQ, not assigned to this MR."""
|
||||
await approved_plan()
|
||||
other = await client.post(
|
||||
f"{API}/doctors",
|
||||
headers=auth["admin"],
|
||||
@@ -527,8 +553,9 @@ class TestValidationRules:
|
||||
assert call.status_code == 422
|
||||
assert "not assigned" in call.json()["error"]["message"]
|
||||
|
||||
async def test_v7_conversion_status_only_for_core_doctors(self, client, auth, org):
|
||||
async def test_v7_conversion_status_only_for_core_doctors(self, client, auth, org, approved_plan):
|
||||
doctors, _ = await _create_masters(client, auth, org, n_doctors=5, n_chemists=1)
|
||||
await approved_plan()
|
||||
non_core = next(d for d in doctors if not d["is_core_doctor"])
|
||||
|
||||
resp = await client.post(
|
||||
@@ -549,8 +576,9 @@ class TestValidationRules:
|
||||
assert call.status_code == 422
|
||||
assert "core doctor" in call.json()["error"]["message"]
|
||||
|
||||
async def test_cannot_edit_while_pending_with_the_manager(self, client, auth, org):
|
||||
async def test_cannot_edit_while_pending_with_the_manager(self, client, auth, org, approved_plan):
|
||||
doctors, _ = await _create_masters(client, auth, org, n_doctors=2, n_chemists=1)
|
||||
await approved_plan()
|
||||
resp = await client.post(
|
||||
f"{API}/dcr", headers=auth["mr1"], json={"report_date": date.today().isoformat()}
|
||||
)
|
||||
@@ -572,8 +600,9 @@ class TestValidationRules:
|
||||
assert edit.status_code == 409
|
||||
assert edit.json()["error"]["code"] == "REPORT_LOCKED"
|
||||
|
||||
async def test_pdf_unavailable_before_approval(self, client, auth, org):
|
||||
async def test_pdf_unavailable_before_approval(self, client, auth, org, approved_plan):
|
||||
doctors, _ = await _create_masters(client, auth, org, n_doctors=2, n_chemists=1)
|
||||
await approved_plan()
|
||||
resp = await client.post(
|
||||
f"{API}/dcr", headers=auth["mr1"], json={"report_date": date.today().isoformat()}
|
||||
)
|
||||
@@ -585,8 +614,9 @@ class TestValidationRules:
|
||||
|
||||
|
||||
class TestStatusCounts:
|
||||
async def test_counts_replace_the_dashboard(self, client, auth, org):
|
||||
async def test_counts_replace_the_dashboard(self, client, auth, org, approved_plan):
|
||||
doctors, _ = await _create_masters(client, auth, org, n_doctors=2, n_chemists=1)
|
||||
await approved_plan()
|
||||
resp = await client.post(
|
||||
f"{API}/dcr", headers=auth["mr1"], json={"report_date": date.today().isoformat()}
|
||||
)
|
||||
@@ -595,4 +625,4 @@ class TestStatusCounts:
|
||||
counts = await client.get(f"{API}/dcr/counts", headers=auth["mr1"])
|
||||
assert counts.status_code == 200
|
||||
assert counts.json()["DRAFT"] == 1
|
||||
assert counts.json()["APPROVED"] == 0
|
||||
assert counts.json()["APPROVED"] == 1 # the day plan the report follows
|
||||
|
||||
Reference in New Issue
Block a user