from app.base.mode import EnrollmentsMode from ...factory import ( ExaminationScheduleFactory, ProjectSupervisorFactory, TemporaryAvailabilityFactory, YearGroupFactory, ) from ...utils import ( _test_case_client, _test_case_client_without_response, create_many_models, create_one_model, ) def test_list_enrollments_for_project_supervisor(test_app_with_context) -> None: with test_app_with_context.test_client() as client: year_group = create_one_model(YearGroupFactory) ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id) ps2 = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id) ex = create_one_model(ExaminationScheduleFactory, year_group_id=year_group.id) create_many_models( 7, TemporaryAvailabilityFactory, examination_schedule_id=ex.id, project_supervisor_id=ps2.id, ) amount = 5 create_many_models( amount, TemporaryAvailabilityFactory, examination_schedule_id=ex.id, project_supervisor_id=ps.id, ) url = f"/api/project_supervisor/{ex.id}/temporary-availabilities/?id={ps.id}" data = _test_case_client_without_response(client, url, None, 200, method="get") assert len(data.get("free_times")) == amount def test_list_enrollments_for_project_supervisor_if_examination_schedule_doesnt_exist( test_app_with_context, ) -> None: with test_app_with_context.test_client() as client: year_group = create_one_model(YearGroupFactory) ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id) url = f"/api/project_supervisor/3/temporary-availabilities/?id={ps.id}" _test_case_client( client, url, None, "Not found examination schedule!", 404, method="get", key="error", ) def test_list_enrollments_for_project_supervisor_if_project_supervisor_doesnt_exist( test_app_with_context, ) -> None: with test_app_with_context.test_client() as client: url = f"/api/project_supervisor/3/temporary-availabilities/?id=3" _test_case_client( client, url, None, "Not found project supervisor!", 404, method="get", key="error", ) def test_list_enrollments_for_project_supervisor_if_enrollments_is_not_open_yet( test_app_with_context, ) -> None: with test_app_with_context.test_client() as client: year_group = create_one_model(YearGroupFactory) ps = create_one_model(ProjectSupervisorFactory, year_group_id=year_group.id) ex = create_one_model( ExaminationScheduleFactory, year_group_id=year_group.id, open_enrollments=EnrollmentsMode.OPEN.value, ) create_many_models( 7, TemporaryAvailabilityFactory, examination_schedule_id=ex.id, project_supervisor_id=ps.id, ) url = f"/api/project_supervisor/{ex.id}/temporary-availabilities/?id={ps.id}" _test_case_client( client, url, None, "Enrollments has started or closed! You have been delayed!", 400, method="get", key="error", )