def test_create_city(db: Session) -> None: created = insert_city(db) city_created = crud.city.get_by_id(db, created.id) assert created.id == city_created.id assert created.name == city_created.name delete_city(db, created)
def test_GET_existing_city(db: Session) -> None: created = insert_city(db) response = client.get(f'/api/v1/city/{created.id}') city_from_api = response.json() assert response.status_code == 200 assert city_from_api['name'] == created.name delete_city(db, created)
def test_list_all_cities(db: Session) -> None: city_count = crud.city.count(db) cities = crud.city.filter(db) assert len(cities) == city_count created = insert_city(db) cities = crud.city.filter(db) assert len(cities) == city_count + 1 delete_city(db, created)
def test_PUT_existing_city(db: Session) -> None: created = insert_city(db) city_data = {'name': 'Changed'} response = client.put(f'/api/v1/city/{created.id}', json=city_data) city_from_api = response.json() assert response.status_code == 200 assert city_from_api['name'] == 'Changed' delete_city(db, created)
def test_update_province(db: Session) -> None: created = insert_city(db) city_from_db = crud.city.get_by_id(db, created.id) city_update = CityUpdate(name="Updated") updated_city = crud.city.update(db, db_object=city_from_db, object_to_update=city_update) city_from_db = crud.city.get_by_id(db, created.id) assert city_from_db.id == updated_city.id assert city_from_db.name == "Updated" delete_city(db, created)
def test_GET_cities(db: Session) -> None: city_count = crud.city.count(db) response = client.get('/api/v1/city/') assert response.status_code == 200 assert len(response.json()) == city_count created = insert_city(db) response = client.get('/api/v1/city/') assert response.status_code == 200 assert len(response.json()) == city_count + 1 delete_city(db, created)
def test_POST_existing_city_name(db: Session) -> None: created = insert_city(db) city_data = { 'name': created.name, 'province_id': created.province_id, } response = client.post('/api/v1/city/', json=city_data) created_city = response.json() assert response.status_code == 400 assert "_id" not in response delete_city(db, created)
def test_POST_new_city(db: Session) -> None: created_province = insert_province(db) city_data = create_random_city_data(created_province.id) response = client.post('/api/v1/city/', json=city_data) assert response.status_code == 200 created_city = response.json() city_id = created_city.get("id") city_from_db = crud.city.get_by_id(db, city_id) assert city_from_db assert city_from_db.name == city_data['name'] delete_city(db, city_from_db)