def test_list_all_retailers(db: Session) -> None:
    retailer_count = crud.retailer.count(db)
    retailers = crud.retailer.filter(db)
    assert len(retailers) == retailer_count
    created = insert_retailer(db)
    retailers = crud.retailer.filter(db)
    assert len(retailers) == retailer_count + 1
    delete_retailer(db, created)
Example #2
0
def test_GET_existing_retailer(db: Session) -> None:
    created = insert_retailer(db)

    response = client.get(f'/api/v1/retailer/{created.id}')
    retailer_from_api = response.json()
    assert response.status_code == 200
    assert retailer_from_api['name'] == created.name

    delete_retailer(db, created)
def test_delete_retailer(db: Session) -> None:
    created = insert_retailer(db)

    retailer_from_db = crud.retailer.get_by_id(db, created.id)
    assert retailer_from_db
    deleted = crud.retailer.remove(db, id=created.id)
    retailer_from_db = crud.retailer.get_by_id(db, created.id)
    assert retailer_from_db is None
    assert deleted.id == created.id
Example #4
0
def test_PUT_existing_retailer(db: Session) -> None:
    created = insert_retailer(db)

    retailer_data = {'name': 'Changed'}

    response = client.put(f'/api/v1/retailer/{created.id}', json=retailer_data)
    retailer_from_api = response.json()
    assert response.status_code == 200
    assert retailer_from_api['name'] == 'Changed'

    delete_retailer(db, created)
def test_update_retailer(db: Session) -> None:
    created = insert_retailer(db)
    retailer_from_db = crud.retailer.get_by_id(db, created.id)
    retailer_update = RetailerUpdate(name="Changed")
    updated_retailer = crud.retailer.update(db,
                                            db_object=retailer_from_db,
                                            object_to_update=retailer_update)
    retailer_from_db = crud.retailer.get_by_id(db, created.id)
    assert retailer_from_db.id == updated_retailer.id
    assert retailer_from_db.name == "Changed"
    delete_retailer(db, created)
Example #6
0
def test_GET_retailer(db: Session) -> None:
    retailer_count = crud.retailer.count(db)
    response = client.get('/api/v1/retailer/')
    assert response.status_code == 200
    assert len(response.json()) == retailer_count
    created = insert_retailer(db)

    response = client.get('/api/v1/retailer/')
    assert response.status_code == 200
    assert len(response.json()) == retailer_count + 1

    delete_retailer(db, created)
Example #7
0
def test_POST_existing_retailer_name(db: Session) -> None:
    created = insert_retailer(db)

    retailer_data = {
        'name': created.name,
        'description': random_upper_string(),
        'city_id': 1,
        'category_id': 1,
        'category_enabled': True,
    }
    response = client.post('/api/v1/retailer/', json=retailer_data)

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

    delete_retailer(db, created)
def test_create_retailer(db: Session) -> None:
    created = insert_retailer(db)
    retailer_created = crud.retailer.get_by_id(db, created.id)
    assert created.id == retailer_created.id
    assert created.description == retailer_created.description
    delete_retailer(db, created)