import json TEST_NAME = "lessons:list" def run(context) -> None: base_path = f"/api/classes/{context.class_id}/lessons" status, _, _ = context.send_request("GET", base_path) context.expect(status == 401, f"expected 401, got {status}") status, body, _ = context.send_request( "GET", base_path, headers=context.make_auth( context.teacher_username, context.teacher_password, ), ) context.expect(status == 200, f"expected 200, got {status}") data = json.loads(body) lessons = data.get("уроки", []) context.expect(len(lessons) >= 2, "expected at least two lessons") def find_lesson(entry_id: int): for item in lessons: if int(item[context.K_IDENTIFIER]) == entry_id: return item return None first_entry = find_lesson(context.lesson_first_id) context.expect(first_entry is not None, "first lesson missing") context.expect( first_entry.get("название") == context.lesson_first_title, "first lesson title mismatch", ) 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) == 1, f"expected single lesson in filter, got {len(filtered)}", ) context.expect( int(filtered[0][context.K_IDENTIFIER]) == context.lesson_first_id, "filter returned unexpected lesson", ) student_headers = context.make_auth( context.student_two_username, context.student_two_password, ) status, body, _ = context.send_request( "GET", base_path, headers=student_headers, ) context.expect(status == 200, f"expected 200 for student, got {status}") student_view = json.loads(body).get("уроки", []) context.expect( any( int(item[context.K_IDENTIFIER]) == context.lesson_second_id for item in student_view ), "student view missing lesson", )