def test_get_timeslot_existing(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None: timeslot = create_random_timeslot(db) r = client.get(f"{settings.API_V1_STR}/timeslots/{timeslot.id}", headers=superuser_token_headers) assert r.status_code == 200 fetched_timeslot = r.json() assert fetched_timeslot compare_api_and_db_query_results(api_result=fetched_timeslot, db_dict=to_json(timeslot))
def test_update_timeslot(db: Session) -> None: timeslot = create_random_timeslot(db) assert timeslot end_time = (datetime.now() + timedelta(minutes=30)).time() updated_timeslot = crud.timeslot.update( db, db_obj=timeslot, obj_in=TimeSlotUpdate(end_time=end_time)) assert updated_timeslot.end_time == end_time
def test_get_all_timeslots(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None: timeslot = create_random_timeslot(db) r = client.get(f"{settings.API_V1_STR}/timeslots/", headers=superuser_token_headers) assert r.status_code == 200 results = r.json() assert results compare_api_and_db_query_results(api_result=results[-1], db_dict=to_json(timeslot))
def test_timeslot_by_school(db: Session) -> None: timeslot = create_random_timeslot(db) assert timeslot.id assert timeslot.school_id fetched_timeslot = crud.timeslot.get_by_school( db, school_id=timeslot.school_id)[0] assert fetched_timeslot assert fetched_timeslot.id == timeslot.id
def test_create_timeslot(db: Session) -> None: start_time = datetime.now().time() end_time = (datetime.now() + timedelta(hours=1)).time() school_id = create_random_school(db).id timeslot = create_random_timeslot(db, start_time=start_time, end_time=end_time, school_id=school_id) assert timeslot assert timeslot.start_time == start_time assert timeslot.end_time == end_time
def test_create_timeslot_existing(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None: timeslot = create_random_timeslot(db) assert timeslot.start_time assert timeslot.end_time assert timeslot.school_id data = { "start_time": timeslot.start_time.isoformat(), "end_time": timeslot.end_time.isoformat(), "school_id": timeslot.school_id, } r = client.post(f"{settings.API_V1_STR}/timeslots/", headers=superuser_token_headers, json=data) assert r.status_code == 409
def test_timeslot_by_details(db: Session) -> None: timeslot = create_random_timeslot(db) assert timeslot.id assert timeslot.start_time assert timeslot.end_time assert timeslot.school_id fetched_timeslot = crud.timeslot.get_by_details( db, start_time=timeslot.start_time, end_time=timeslot.end_time, school_id=timeslot.school_id, ) assert fetched_timeslot assert fetched_timeslot.id == timeslot.id
def test_update_timeslot(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None: timeslot = create_random_timeslot(db) start_time = datetime.now().time() end_time = (datetime.now() + timedelta(hours=1)).time() school_id = create_random_school(db).id data = { "start_time": start_time.isoformat(), "end_time": end_time.isoformat(), "school_id": school_id, } r = client.put(f"{settings.API_V1_STR}/timeslots/{timeslot.id}", headers=superuser_token_headers, json=data) fetched_timeslot = r.json() db.refresh(timeslot) assert fetched_timeslot compare_api_and_db_query_results(api_result=fetched_timeslot, db_dict=to_json(timeslot))
def test_delete_timeslot(client: TestClient, superuser_token_headers: dict[str, str], db: Session) -> None: timeslot = create_random_timeslot(db) r = client.delete(f"{settings.API_V1_STR}/timeslots/{timeslot.id}", headers=superuser_token_headers) assert r.status_code == 200 deleted_timeslot = crud.timeslot.get(db, id=timeslot.id) assert deleted_timeslot is None