Files
srab/autotest/cases/case_20_lessons_teacher_delete.py
2025-11-26 21:32:41 +03:00

82 lines
2.3 KiB
Python

import json
TEST_NAME = "lessons:delete"
def run(context) -> None:
path = f"/api/classes/{context.class_id}/lessons/{context.lesson_first_id}"
status, _, _ = context.send_request("DELETE", path)
context.expect(status == 401, f"expected 401, got {status}")
status, _, _ = context.send_request(
"DELETE",
f"/api/classes/{context.class_id + 999}/lessons/"
f"{context.lesson_first_id}",
headers=context.make_auth(
context.teacher_username,
context.teacher_password,
),
)
context.expect(
status == 403,
f"expected 403 for foreign class, got {status}",
)
status, _, _ = context.send_request(
"DELETE",
path,
headers=context.make_auth(
context.teacher_username,
context.teacher_password,
),
)
context.expect(status == 204, f"expected 204, got {status}")
status, _, _ = context.send_request(
"DELETE",
path,
headers=context.make_auth(
context.teacher_username,
context.teacher_password,
),
)
context.expect(status == 404, f"expected 404 after delete, got {status}")
filter_path = (
f"/api/classes/{context.class_id}/lessons/date/"
f"{context.lesson_first_date}"
)
status, body, _ = context.send_request(
"GET",
filter_path,
headers=context.make_auth(
context.teacher_username,
context.teacher_password,
),
)
context.expect(status == 200, f"expected 200 for filter, got {status}")
filtered = json.loads(body).get("уроки", [])
context.expect(len(filtered) == 0, "filter should be empty after delete")
status, body, _ = context.send_request(
"GET",
f"/api/classes/{context.class_id}/lessons",
headers=context.make_auth(
context.teacher_username,
context.teacher_password,
),
)
context.expect(status == 200, f"expected 200 for list, got {status}")
remaining = json.loads(body).get("уроки", [])
context.expect(
any(
int(item[context.K_IDENTIFIER]) == context.lesson_second_id
for item in remaining
),
"second lesson missing after delete",
)
context.lesson_first_id = None