def test_delete_country(db: Session) -> None: country_create = create_random_country() created = crud.create(db, country_create) country_from_db = crud.get_by_id(db, created.id) assert country_from_db deleted = crud.remove(db, id=created.id) country_from_db = crud.get_by_id(db, created.id) assert country_from_db is None assert deleted.id == created.id
def test_update_country(db: Session) -> None: country_create = create_random_country() created = crud.create(db, country_create) country_from_db = crud.get_by_id(db, created.id) country_update = CountryUpdate(currency="USD") updated_country = crud.update(db, db_object=country_from_db, object_to_update=country_update) country_from_db = crud.get_by_id(db, created.id) assert country_from_db.id == updated_country.id assert country_from_db.currency == "USD" crud.remove(db, id=created.id)
def test_create_country(db: Session) -> None: country_create = create_random_country() created = crud.create(db, country_create) country_created = crud.get_by_id(db, created.id) assert created.id == country_created.id assert created.code == country_created.code assert created.language == country_created.language crud.remove(db, id=created.id)
def delete_country( *, db: Session = Depends(get_db), country_id: int, ) -> Any: country = crud.get_by_id(db=db, id=country_id) if not country: raise HTTPException(status_code=404, detail="Country not found") country = crud.remove(db=db, id=country_id) return country
async def get_country_by_id( *, db: Session = Depends(get_db), country_id: int, ) -> Any: country = crud.get_by_id(db, id=country_id) if not country: raise HTTPException(status_code=404, detail="The country doesn't exists") return country
def test_POST_new_country(db: Session) -> None: country_data = create_random_country_data() response = client.post('/api/v1/country/', json=country_data) assert response.status_code == 200 created_country = response.json() country_id = created_country.get("id") country_from_db = crud.get_by_id(db, country_id) assert country_from_db assert country_from_db.name == country_data['name'] crud.remove(db, id=country_id)
def update_country( *, db: Session = Depends(get_db), country_id: int, country_update: CountryUpdate, ) -> Any: country = crud.get_by_id(db, id=country_id) if not country: raise HTTPException( status_code=404, detail="The country doesn't exists", ) country = crud.update(db, db_object=country, object_to_update=country_update) return country