def test_create_sector(db: Session) -> None: created = insert_sector(db) sector_created = crud.sector.get_by_id(db, created.id) assert created.id == sector_created.id assert created.name == sector_created.name delete_sector(db, created)
def test_GET_existing_sector(db: Session) -> None: created = insert_sector(db) response = client.get(f'/api/v1/sector/{created.id}') sector_from_api = response.json() assert response.status_code == 200 assert sector_from_api['name'] == created.name delete_sector(db, created)
def test_list_all_sectors(db: Session) -> None: sector_count = crud.sector.count(db) sectors = crud.sector.filter(db) assert len(sectors) == sector_count created = insert_sector(db) sectors = crud.sector.filter(db) assert len(sectors) == sector_count + 1 delete_sector(db, created)
def test_delete_sector(db: Session) -> None: created = insert_sector(db) sector_from_db = crud.sector.get_by_id(db, created.id) assert sector_from_db deleted = crud.sector.remove(db, id=created.id) sector_from_db = crud.sector.get_by_id(db, created.id) assert sector_from_db is None assert deleted.id == created.id delete_city_by_id(db, deleted.city_id)
def test_PUT_existing_sector(db: Session) -> None: created = insert_sector(db) sector_data = {'name': 'Changed'} response = client.put(f'/api/v1/sector/{created.id}', json=sector_data) sector_from_api = response.json() assert response.status_code == 200 assert sector_from_api['name'] == 'Changed' delete_sector(db, created)
def test_update_sector(db: Session) -> None: created = insert_sector(db) sector_from_db = crud.sector.get_by_id(db, created.id) sector_update = SectorUpdate(name="Updated") updated_sector = crud.sector.update(db, db_object=sector_from_db, object_to_update=sector_update) sector_from_db = crud.sector.get_by_id(db, created.id) assert sector_from_db.id == updated_sector.id assert sector_from_db.name == "Updated" delete_sector(db, created)
def test_GET_sectors(db: Session) -> None: sector_count = crud.sector.count(db) response = client.get('/api/v1/sector/') assert response.status_code == 200 assert len(response.json()) == sector_count created = insert_sector(db) response = client.get('/api/v1/sector/') assert response.status_code == 200 assert len(response.json()) == sector_count + 1 delete_sector(db, created)
def test_POST_existing_sector_name(db: Session) -> None: created = insert_sector(db) sector_data = { 'name': created.name, 'city_id': created.city_id, } response = client.post('/api/v1/sector/', json=sector_data) created_sector = response.json() assert response.status_code == 400 assert "_id" not in response delete_sector(db, created)