--
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
"""Company forms: listed in the company's order, and readable (never writable) by the GM."""
|
||||
|
||||
from tests.e2e.test_form_ownership import forms # noqa: F401 - creates the form tables
|
||||
|
||||
API = "/api/v1"
|
||||
|
||||
ORDER = [
|
||||
"standard_tour_plan",
|
||||
"tour_plan",
|
||||
"fare_chart",
|
||||
"sales_and_stock_statement",
|
||||
"sales_projection",
|
||||
"field_activity_report",
|
||||
"expense_statement",
|
||||
"area_covered",
|
||||
"weekly_report",
|
||||
"core_dr_call_conversion",
|
||||
]
|
||||
|
||||
|
||||
class TestFormsForTheGeneralManager:
|
||||
async def test_forms_are_listed_in_the_company_order(self, client, auth, org):
|
||||
for who in ("mr1", "gm", "admin"):
|
||||
tables = (await client.get(f"{API}/csv-data/tables", headers=auth[who])).json()
|
||||
assert [t["name"] for t in tables] == ORDER
|
||||
|
||||
async def test_gm_reads_every_mrs_rows_and_pdf(self, client, auth, org, forms): # noqa: F811
|
||||
added = await client.post(
|
||||
f"{API}/csv-data/tour_plan/rows", headers=auth["mr1"], json={"from_location": "Puri"}
|
||||
)
|
||||
assert added.status_code == 201, added.text
|
||||
rows = (await client.get(f"{API}/csv-data/tour_plan/rows", headers=auth["gm"])).json()
|
||||
assert [r["from_location"] for r in rows] == ["Puri"]
|
||||
owners = (await client.get(f"{API}/csv-data/owners", headers=auth["gm"])).json()
|
||||
assert {o["id"] for o in owners} == {str(org["mr1"].id), str(org["mr2"].id)}
|
||||
mine = await client.get(
|
||||
f"{API}/csv-data/tour_plan/rows?owner_id={org['mr1'].id}", headers=auth["gm"]
|
||||
)
|
||||
assert mine.status_code == 200 and len(mine.json()) == 1
|
||||
pdf = await client.get(f"{API}/csv-data/tour_plan/pdf", headers=auth["gm"])
|
||||
assert pdf.status_code == 200 and pdf.content.startswith(b"%PDF-")
|
||||
|
||||
async def test_gm_cannot_change_or_approve_a_form(self, client, auth, org, forms): # noqa: F811
|
||||
row = (
|
||||
await client.post(
|
||||
f"{API}/csv-data/tour_plan/rows", headers=auth["mr1"], json={"to_location": "Puri"}
|
||||
)
|
||||
).json()
|
||||
add = await client.post(
|
||||
f"{API}/csv-data/tour_plan/rows?owner_id={org['mr1'].id}",
|
||||
headers=auth["gm"],
|
||||
json={"to_location": "Cuttack"},
|
||||
)
|
||||
assert add.status_code == 403
|
||||
edit = await client.patch(
|
||||
f"{API}/csv-data/tour_plan/rows/{row['id']}", headers=auth["gm"], json={"pob": "1"}
|
||||
)
|
||||
assert edit.status_code == 403
|
||||
delete = await client.delete(
|
||||
f"{API}/csv-data/tour_plan/rows/{row['id']}", headers=auth["gm"]
|
||||
)
|
||||
assert delete.status_code == 403
|
||||
approve = await client.post(
|
||||
f"{API}/csv-data/tour_plan/approval/approve?owner_id={org['mr1'].id}",
|
||||
headers=auth["gm"],
|
||||
)
|
||||
assert approve.status_code == 403
|
||||
Reference in New Issue
Block a user