示例#1
0
def test_delete_lecture(client: TestClient, superuser_token_headers: dict[str,
                                                                          str],
                        db: Session) -> None:
    lecture = create_random_lecture(db)
    r = client.delete(f"{settings.API_V1_STR}/lectures/{lecture.id}",
                      headers=superuser_token_headers)
    assert r.status_code == 200
    deleted_lecture = crud.lecture.get(db, lecture.id)
    assert deleted_lecture is None
示例#2
0
def test_get_lecture_superuser(client: TestClient,
                               superuser_token_headers: dict[str, str],
                               db: Session) -> None:
    lecture = create_random_lecture(db)
    r = client.get(f"{settings.API_V1_STR}/lectures/{lecture.id}",
                   headers=superuser_token_headers)
    assert r.status_code == 200
    fetched_lecture = r.json()
    assert fetched_lecture
    compare_api_and_db_query_results(api_result=fetched_lecture,
                                     db_dict=to_json(lecture))
示例#3
0
def test_get_lecture_admin(client: TestClient, db: Session) -> None:
    lecture = create_random_lecture(db)
    perms = AdminPermissions(0)
    perms["school"] = True
    admin = create_random_user(db, "admin", permissions=perms.permissions)
    admin_user_token_headers = authentication_token_from_email(
        client=client, db=db, email=admin.email, user_type="admin")
    r = client.get(f"{settings.API_V1_STR}/lectures/{lecture.id}",
                   headers=admin_user_token_headers)
    assert r.status_code == 200
    fetched_lecture = r.json()
    assert fetched_lecture
    compare_api_and_db_query_results(api_result=fetched_lecture,
                                     db_dict=to_json(lecture))
示例#4
0
def test_create_lecture(db: Session) -> None:
    day = random.choice(calendar.day_name)
    time_slot_id = create_random_timeslot(db).id
    division_id = create_random_division(db).id
    type_ = random.choice(["theory", "practical", "tutorial"])
    room_number = random.choice(["A", "B", "C"]) + "".join(map(str, (random.sample(range(5), 3))))
    lecture = create_random_lecture(
        db, day=day, time_slot_id=time_slot_id, division_id=division_id, type_=type_, room_number=room_number
    )
    assert lecture
    assert lecture.time_slot_id == time_slot_id
    assert lecture.division_id == division_id
    assert lecture.type == type_
    assert lecture.room_number == room_number
示例#5
0
def test_create_lecture_existing(client: TestClient,
                                 superuser_token_headers: dict[str, str],
                                 db: Session) -> None:
    lecture = create_random_lecture(db)
    data = {
        "day": lecture.day,
        "time_slot_id": lecture.time_slot_id,
        "division_id": lecture.division_id,
        "type": lecture.type,
        "room_number": lecture.room_number,
    }
    r = client.post(f"{settings.API_V1_STR}/lectures/",
                    headers=superuser_token_headers,
                    json=data)
    assert r.status_code == 409
示例#6
0
def test_update_lecture(client: TestClient, superuser_token_headers: dict[str,
                                                                          str],
                        db: Session) -> None:
    lecture = create_random_lecture(db)
    new_timeslot = create_random_timeslot(db)
    data = {"time_slot_id": new_timeslot.id}
    r = client.put(f"{settings.API_V1_STR}/lectures/{lecture.id}",
                   headers=superuser_token_headers,
                   json=data)
    assert r.status_code == 200
    fetched_lecture = r.json()
    db.refresh(lecture)
    assert fetched_lecture
    compare_api_and_db_query_results(api_result=fetched_lecture,
                                     db_dict=to_json(lecture))
示例#7
0
def test_get_lecture_division_student(client: TestClient, db: Session) -> None:
    lecture = create_random_lecture(db)
    normal_user_token_headers = authentication_token_from_email(
        client=client,
        db=db,
        email=random_email(),
    )
    r = client.get(
        f"{settings.API_V1_STR}/lectures/division/{lecture.division_id}",
        headers=normal_user_token_headers)
    assert r.status_code == 200
    fetched_lecture = r.json()
    assert fetched_lecture
    assert len(fetched_lecture) > 0
    compare_api_and_db_query_results(api_result=fetched_lecture[0],
                                     db_dict=to_json(lecture))
示例#8
0
def test_lecture_by_details(db: Session) -> None:
    lecture = create_random_lecture(db)
    assert lecture.id
    assert lecture.time_slot_id
    assert lecture.division_id
    assert lecture.type
    assert lecture.room_number
    fetched_lecture = crud.lecture.get_by_details(
        db,
        day=lecture.day,
        time_slot_id=lecture.time_slot_id,
        division_id=lecture.division_id,
        type=lecture.type,
        room_number=lecture.room_number,
    )
    assert fetched_lecture
    assert fetched_lecture.id == lecture.id
示例#9
0
def test_update_lecture(db: Session) -> None:
    lecture = create_random_lecture(db)
    assert lecture
    type_ = random.choice(["theory", "practical", "tutorial"])
    updated_lecture = crud.lecture.update(db, db_obj=lecture, obj_in=LectureUpdate(type=type_))
    assert updated_lecture.type == type_