Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Nov 22, 2023
1 parent c1d5a2d commit 959455c
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from app import crud
from app.api import app, get_db
from app.db import Base
from app.schemas import LocationCreate, PriceCreate, UserBase
from app.schemas import LocationCreate, PriceCreate, ProductCreate, UserBase

# database setup
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -40,6 +40,7 @@ def override_get_db():
client = TestClient(app)

USER = UserBase(user_id="user1", token="user1__Utoken")
PRODUCT = ProductCreate(code="8001505005707")
LOCATION = LocationCreate(osm_id=3344841823, osm_type="NODE")
PRICE_1 = PriceCreate(
product_code="1111111111111",
Expand All @@ -57,6 +58,12 @@ def user(db=override_get_db()):
return db_user


@pytest.fixture(scope="module")
def product(db=override_get_db()):
db_product = crud.create_product(next(db), PRODUCT)
return db_product


@pytest.fixture(scope="module")
def location(db=override_get_db()):
db_location = crud.create_location(next(db), LOCATION)
Expand Down Expand Up @@ -148,6 +155,15 @@ def test_get_proofs(user):
assert response.status_code == 200


def test_get_product(product):
# product exists
response = client.get(f"/products/{product.id}")
assert response.status_code == 200
# product does not exist
response = client.get(f"/products/{product.id+1}")
assert response.status_code == 404


def test_get_location(location):
# location exists
response = client.get(f"/locations/{location.id}")
Expand Down

0 comments on commit 959455c

Please sign in to comment.