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)
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
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
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
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