示例#1
0
def test_create_duplicate_item(db: Session) -> RoundModel:
    # creates one car and one track in table
    car = create_random_car(db)
    track = create_random_track(db)
    name = random_lower_string()
    description = random_lower_string()
    reason = "Test"
    ref_date = "2020-08-01"
    track_id = track.id
    car_id = car.id

    item_in = RoundCreate(name=name,
                          description=description,
                          reason=reason,
                          ref_date=ref_date,
                          track_id=track_id,
                          car_id=car_id)

    item = create(db_session=db, obj_in=item_in)
    assert item.name == name
    assert item.description == description
    assert item.reason == reason
    assert item.track_id == track_id
    assert item.car_id == car_id
    assert item.id is not None
    with pytest.raises(ExistenceException):
        create(db_session=db, obj_in=item_in)
示例#2
0
def test_update(db: Session) -> RoundModel:
    # creates one car and one track in table
    car = create_random_car(db)
    track = create_random_track(db)

    name = random_lower_string()
    description = random_lower_string()
    reason = "Test"
    ref_date = "2020-08-01"
    track_id = track.id
    car_id = car.id

    item_in = RoundCreate(name=name,
                          description=description,
                          reason=reason,
                          ref_date=ref_date,
                          track_id=track_id,
                          car_id=car_id)

    item = create(db_session=db, obj_in=item_in)

    item_update = RoundUpdate(name=random_lower_string(),
                              description=random_lower_string(),
                              reason=reason,
                              ref_date=ref_date,
                              track_id=track_id,
                              car_id=car_id)
    updated_round = update(db_session=db, round_id=item.id, obj_in=item_update)

    assert updated_round.name == item_update.name
    assert updated_round.description == item_update.description
示例#3
0
def test_read_one(db: Session) -> RoundModel:
    # creates one car and one track in table
    car = create_random_car(db)
    track = create_random_track(db)
    name = random_lower_string()
    description = random_lower_string()
    reason = "Test"
    ref_date = "2020-08-01"
    track_id = track.id
    car_id = car.id

    item_in = RoundCreate(name=name,
                          description=description,
                          reason=reason,
                          ref_date=ref_date,
                          track_id=track_id,
                          car_id=car_id)

    item = create(db_session=db, obj_in=item_in)
    item_id = item.id
    read_item = read_one(db_session=db, round_id=item_id)
    assert read_item.name == name
    assert read_item.description == description
    assert read_item.reason == reason
    assert read_item.track_id == track_id
    assert read_item.car_id == car_id
示例#4
0
def create_round(*, db: Session = Depends(get_db), round_in: RoundCreate):
    """
    Inserts a round into the Round table, given the request body.
    """
    try:
        created_round = create(db_session=db, obj_in=round_in)
    except ExistenceException as err:
        raise HTTPException(status_code=303, detail=err.message)
    return created_round
示例#5
0
def create_random_round(db: Session) -> RoundModel:
    # creates one car and one track in table
    car = create_random_car(db)
    track = create_random_track(db)
    name = random_lower_string()
    description = random_lower_string()
    reason = "Test"
    ref_date = "2020-08-01"
    track_id = track.id
    car_id = car.id

    item_in = RoundCreate(name=name, description=description, reason=reason,
                          ref_date=ref_date, track_id=track_id, car_id=car_id)

    item = create(db_session=db, obj_in=item_in)
    return item
示例#6
0
def test_read_by_reason(db: Session) -> RoundModel:
    # creates one car and one track in table
    car = create_random_car(db)
    track = create_random_track(db)
    name = random_lower_string()
    description = random_lower_string()
    reason = "Competition"
    ref_date = "2020-08-10"
    track_id = track.id
    car_id = car.id

    item_in = RoundCreate(name=name,
                          description=description,
                          reason=reason,
                          ref_date=ref_date,
                          track_id=track_id,
                          car_id=car_id)

    item = create(db_session=db, obj_in=item_in)
    item_reason = item.reason
    read_item = read_by_reason(db_session=db, round_reason=item_reason)
    assert type(read_item) == list