Ejemplo n.º 1
0
def test_create_province(db: Session) -> None:
    created = insert_province(db)
    province_created = province_crud.get_by_id(db, created.id)
    assert created.id == province_created.id
    assert created.name == province_created.name
    assert created.region == province_created.region

    crud.remove(db, id=created.country_id)
    province_crud.remove(db, id=created.id)
Ejemplo n.º 2
0
def test_GET_existing_province(db: Session) -> None:
    created = insert_province(db)

    response = client.get(f'/api/v1/province/{created.id}')
    province_from_api = response.json()
    assert response.status_code == 200
    assert province_from_api['name'] == created.name
    crud.province.remove(db, id=created.id)
    crud.country.remove(db, id=created.country_id)
Ejemplo n.º 3
0
def test_delete_province(db: Session) -> None:
    created = insert_province(db)
    province_from_db = province_crud.get_by_id(db, created.id)
    assert province_from_db
    deleted = province_crud.remove(db, id=created.id)
    province_from_db = province_crud.get_by_id(db, created.id)
    assert province_from_db is None
    assert deleted.id == created.id

    crud.remove(db, id=created.country_id)
Ejemplo n.º 4
0
def test_list_all_provinces(db: Session) -> None:
    province_count = province_crud.count(db)
    provinces = province_crud.filter(db)
    assert len(provinces) == province_count

    created = insert_province(db)
    countries = province_crud.filter(db)
    assert len(countries) == province_count + 1

    crud.remove(db, id=created.country_id)
    province_crud.remove(db, id=created.id)
Ejemplo n.º 5
0
def test_PUT_existing_province(db: Session) -> None:
    created = insert_province(db)

    province_data = {'name': 'Changed'}

    response = client.put(f'/api/v1/province/{created.id}', json=province_data)
    province_from_api = response.json()
    assert response.status_code == 200
    assert province_from_api['name'] == 'Changed'
    crud.province.remove(db, id=created.id)
    crud.country.remove(db, id=created.country_id)
Ejemplo n.º 6
0
def test_GET_provinces(db: Session) -> None:
    province_count = crud.province.count(db)
    response = client.get('/api/v1/province/')
    assert response.status_code == 200
    assert len(response.json()) == province_count
    created = insert_province(db)

    response = client.get('/api/v1/province/')
    assert response.status_code == 200
    assert len(response.json()) == province_count + 1
    crud.country.remove(db, id=created.country_id)
    crud.province.remove(db, id=created.id)
Ejemplo n.º 7
0
def test_update_province(db: Session) -> None:
    created = insert_province(db)
    province_from_db = province_crud.get_by_id(db, created.id)
    province_update = ProvinceUpdate(name="Updated")
    updated_province = province_crud.update(db,
                                            db_object=province_from_db,
                                            object_to_update=province_update)
    province_from_db = province_crud.get_by_id(db, created.id)
    assert province_from_db.id == updated_province.id
    assert province_from_db.name == "Updated"

    crud.remove(db, id=created.country_id)
    province_crud.remove(db, id=created.id)
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)
Ejemplo n.º 9
0
def test_POST_existing_province_name(db: Session) -> None:
    created = insert_province(db)

    province_data = {
        'name': created.name,
        'country_id': created.country_id,
        'region': random_upper_string(),
    }
    response = client.post('/api/v1/province/', json=province_data)

    created_country = response.json()
    assert response.status_code == 400
    assert "_id" not in response

    crud.province.remove(db, id=created.id)
    crud.country.remove(db, id=created.country_id)