コード例 #1
0
def test_list_all_discounts(db: Session) -> None:
    discount_count = crud.discount.count(db)
    discounts = crud.discount.filter(db)
    assert len(discounts) == discount_count
    created = insert_discount(db)
    discounts = crud.discount.filter(db)
    assert len(discounts) == discount_count + 1
    delete_discount(db, created)
コード例 #2
0
def test_delete_discount(db: Session) -> None:
    created = insert_discount(db)

    discount_from_db = crud.discount.get_by_id(db, created.id)
    assert discount_from_db
    deleted = crud.discount.remove(db, id=created.id)
    discount_from_db = crud.discount.get_by_id(db, created.id)
    assert discount_from_db is None
    assert deleted.id == created.id
コード例 #3
0
def test_DELETE_existing_discount(db: Session) -> None:
    created = insert_discount(db)

    response = client.delete(f'/api/v1/discount/{created.id}')
    discount_from_api = response.json()
    assert response.status_code == 200
    assert created.retailer_id == discount_from_api['retailer_id']

    delete_discount(db, created)
コード例 #4
0
def test_update_discount(db: Session) -> None:
    created = insert_discount(db)
    discount_from_db = crud.discount.get_by_id(db, created.id)
    discount_update = DiscountUpdate(retailer_id=8)
    updated_discount = crud.discount.update(db,
                                            db_object=discount_from_db,
                                            object_to_update=discount_update)
    discount_from_db = crud.discount.get_by_id(db, created.id)
    assert discount_from_db.id == updated_discount.id
    assert discount_from_db.retailer_id == 8
    delete_discount(db, created)
コード例 #5
0
def test_PUT_existing_discount(db: Session) -> None:
    created = insert_discount(db)

    discount_data = {'retailer_id': 9}

    response = client.put(f'/api/v1/discount/{created.id}', json=discount_data)
    discount_from_api = response.json()
    assert response.status_code == 200
    assert discount_from_api['retailer_id'] == 9

    delete_discount(db, created)
コード例 #6
0
def test_GET_discount(db: Session) -> None:
    discount_count = crud.discount.count(db)
    response = client.get('/api/v1/discount/')
    assert response.status_code == 200
    assert len(response.json()) == discount_count
    created = insert_discount(db)

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

    delete_discount(db, created)
コード例 #7
0
def test_create_discount(db: Session) -> None:
    created = insert_discount(db)
    discount_created = crud.discount.get_by_id(db, created.id)
    assert created.id == discount_created.id
    assert created.discount == discount_created.discount
    delete_discount(db, created)