Server backup 2026-11-07 of uncommitted work in projects/pharma-web-celtic
Snapshot of the working tree on srv1071960 (branch main), taken during server cleanup. .env files, node_modules, builds, logs and media were excluded.
This commit is contained in:
@@ -77,7 +77,7 @@ async def _create_masters(client, auth, org, n_doctors=15, n_chemists=5):
|
||||
class TestStep1And2Setup:
|
||||
async def test_admin_creates_user_and_org_mapping(self, client, auth, org):
|
||||
"""Step 1-2: users exist with correct roles, and the MR's profile resolves
|
||||
both its headquarters and its DERIVED reporting Area Manager."""
|
||||
both its headquarters and its DERIVED reporting Area Business Manager."""
|
||||
resp = await client.get(f"{API}/users/me/profile", headers=auth["mr1"])
|
||||
assert resp.status_code == 200, resp.text
|
||||
profile = resp.json()
|
||||
@@ -120,6 +120,15 @@ class TestStep1And2Setup:
|
||||
|
||||
|
||||
class TestStep3And5Masters:
|
||||
async def test_admin_and_agm_see_doctor_mr_assignment(self, client, auth, org):
|
||||
doctors, _ = await _create_masters(client, auth, org, n_doctors=1, n_chemists=0)
|
||||
|
||||
for who in ("admin", "gm"):
|
||||
resp = await client.get(f"{API}/doctors", headers=auth[who])
|
||||
assert resp.status_code == 200, resp.text
|
||||
row = next(item for item in resp.json() if item["id"] == doctors[0]["id"])
|
||||
assert row["assigned_mr_name"] == org["mr1"].full_name
|
||||
|
||||
async def test_mr_sees_exactly_the_assigned_doctors(self, client, auth, org):
|
||||
"""Step 3 + Step 5 (S5): 15 doctors created and assigned → MR sees 15."""
|
||||
await _create_masters(client, auth, org)
|
||||
@@ -288,11 +297,11 @@ class TestFullApprovalFlow:
|
||||
# --- Step 8: MR submits ---------------------------------------
|
||||
resp = await client.post(f"{API}/dcr/{dcr_id}/submit", headers=auth["mr1"])
|
||||
assert resp.status_code == 200, resp.text
|
||||
assert resp.json()["status"] == DCRStatus.PENDING_AM.value
|
||||
assert resp.json()["status"] == DCRStatus.PENDING_ABM.value
|
||||
assert resp.json()["submitted_at"] is not None
|
||||
|
||||
# --- Step 9a: AM returns it -----------------------------------
|
||||
queue = await client.get(f"{API}/dcr?status=PENDING_AM", headers=auth["am1"])
|
||||
# --- Step 9a: ABM returns it -----------------------------------
|
||||
queue = await client.get(f"{API}/dcr?status=PENDING_ABM", headers=auth["am1"])
|
||||
assert [r["id"] for r in queue.json()] == [dcr_id]
|
||||
|
||||
# A reason is mandatory (V8).
|
||||
@@ -309,7 +318,7 @@ class TestFullApprovalFlow:
|
||||
assert resp.status_code == 200, resp.text
|
||||
returned = resp.json()
|
||||
assert returned["status"] == DCRStatus.RETURNED.value
|
||||
assert returned["returned_by_role"] == "AM"
|
||||
assert returned["returned_by_role"] == "ABM"
|
||||
assert "chemist visits" in returned["return_reason"]
|
||||
|
||||
# The MR can edit again once returned.
|
||||
@@ -322,12 +331,12 @@ class TestFullApprovalFlow:
|
||||
|
||||
# --- Step 9b: MR resubmits ------------------------------------
|
||||
resp = await client.post(f"{API}/dcr/{dcr_id}/submit", headers=auth["mr1"])
|
||||
assert resp.json()["status"] == DCRStatus.PENDING_AM.value
|
||||
assert resp.json()["status"] == DCRStatus.PENDING_ABM.value
|
||||
# Resubmission clears the previous return.
|
||||
assert resp.json()["return_reason"] is None
|
||||
|
||||
# --- Step 10: the Area Manager gives the final approval -------
|
||||
# There is no General Manager stage, and the GM cannot approve.
|
||||
# --- Step 10: the Area Business Manager gives the final approval -------
|
||||
# There is no AGM stage, and the AGM cannot approve.
|
||||
gm_try = await client.post(f"{API}/dcr/{dcr_id}/approve", headers=auth["gm"], json={})
|
||||
assert gm_try.status_code == 403, gm_try.text
|
||||
gone = await client.post(f"{API}/dcr/{dcr_id}/forward", headers=auth["am1"], json={})
|
||||
@@ -371,7 +380,7 @@ class TestFullApprovalFlow:
|
||||
for role in ("gm", "admin"):
|
||||
again = await client.post(f"{API}/dcr/{dcr_id}/approve", headers=auth[role], json={})
|
||||
assert again.status_code in (403, 409)
|
||||
# The approving AM repeating the click changes nothing (idempotent), and is not an error.
|
||||
# The approving ABM repeating the click changes nothing (idempotent), and is not an error.
|
||||
repeat = await client.post(f"{API}/dcr/{dcr_id}/approve", headers=auth["am1"], json={})
|
||||
assert repeat.status_code == 200 and repeat.json()["approved_at"] == approved["approved_at"]
|
||||
# ...but an approved report can still not be returned or reopened by anybody.
|
||||
@@ -379,7 +388,7 @@ class TestFullApprovalFlow:
|
||||
back = await client.post(f"{API}/dcr/{dcr_id}/return", headers=auth[role], json={"reason": "reopen it please"})
|
||||
assert back.status_code in (403, 409), role
|
||||
|
||||
# --- Step 12: MR, AM and GM each download the PDF -------------
|
||||
# --- Step 12: MR, ABM and AGM each download the PDF -------------
|
||||
for role in ("mr1", "am1", "gm"):
|
||||
pdf = await client.get(f"{API}/dcr/{dcr_id}/pdf", headers=auth[role])
|
||||
assert pdf.status_code == 200, f"{role}: {pdf.text}"
|
||||
@@ -399,11 +408,11 @@ class TestFullApprovalFlow:
|
||||
|
||||
entries = history.json()
|
||||
assert entries[2]["actor_name"] == "Suresh Behera"
|
||||
assert entries[2]["actor_role"] == "AM"
|
||||
assert entries[2]["actor_role"] == "ABM"
|
||||
assert "chemist visits" in entries[2]["comment"]
|
||||
# The final entry is the Area Manager's approval.
|
||||
# The final entry is the Area Business Manager's approval.
|
||||
assert entries[-1]["actor_name"] == "Suresh Behera"
|
||||
assert entries[-1]["actor_role"] == "AM"
|
||||
assert entries[-1]["actor_role"] == "ABM"
|
||||
assert entries[-1]["comment"] == "Approved for the month."
|
||||
assert all(e["at"] for e in entries)
|
||||
|
||||
@@ -456,7 +465,7 @@ class TestNegativeScope:
|
||||
await client.post(f"{API}/dcr/{dcr_id}/{action}", headers=auth["am2"], json=body)
|
||||
).status_code == 403
|
||||
|
||||
listing = await client.get(f"{API}/dcr?status=PENDING_AM", headers=auth["am2"])
|
||||
listing = await client.get(f"{API}/dcr?status=PENDING_ABM", headers=auth["am2"])
|
||||
assert listing.json() == []
|
||||
|
||||
async def test_x3_admin_cannot_approve(self, client, auth, org, approved_plan):
|
||||
@@ -470,6 +479,9 @@ class TestNegativeScope:
|
||||
assert (
|
||||
await client.get(f"{API}/dcr/{dcr_id}", headers=auth["admin"])
|
||||
).status_code == 200
|
||||
listing = await client.get(f"{API}/dcr", headers=auth["admin"])
|
||||
assert listing.status_code == 200, listing.text
|
||||
assert dcr_id in {report["id"] for report in listing.json()}
|
||||
|
||||
async def test_admin_cannot_create_a_report(self, client, auth):
|
||||
resp = await client.post(
|
||||
|
||||
Reference in New Issue
Block a user