From bcbdaf940ea6177b60c387b6f2c33f4f8db0d377 Mon Sep 17 00:00:00 2001 From: JohnVonNeumann Date: Mon, 18 Mar 2024 18:18:25 +1100 Subject: [PATCH] UPDATE route_pf.py - fix bug where list_footprints not returning properly --- apis/version1/route_product_footprints.py | 2 +- .../test_product_footprints_route.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/apis/version1/route_product_footprints.py b/apis/version1/route_product_footprints.py index a4d780e..964d4a0 100644 --- a/apis/version1/route_product_footprints.py +++ b/apis/version1/route_product_footprints.py @@ -130,7 +130,7 @@ def list_footprints(db: Session = Depends(get_db), current_user: User = Depends( """ product_footprints = list_product_footprints(db=db) if not product_footprints or len(product_footprints) == 0: - raise NoSuchFootprintException + return {'data': []} return paginate(product_footprints, transformer=transformer) diff --git a/tests/test_routes/test_product_footprints_route.py b/tests/test_routes/test_product_footprints_route.py index 1a340a9..2ec8b4c 100644 --- a/tests/test_routes/test_product_footprints_route.py +++ b/tests/test_routes/test_product_footprints_route.py @@ -92,30 +92,29 @@ def test_read_product_footprint_not_found(client, auth_header): assert response.json()["detail"] == "The specified footprint does not exist" # Match your exception message -def test_read_product_footprints_no_seeding(client, auth_header): - response = client.get("/footprints/?limit=1", headers=auth_header) +def test_list_product_footprints_not_found(client, auth_header): + response = client.get("/footprints/", headers=auth_header) assert response.status_code == 200 - print(f"data = {response.json()['data']}") - assert len(response.json()["data"]) == 1 + assert len(response.json()["data"]) == 0 def test_read_product_footprints(client, auth_header, seed_database): - response = client.get("/footprints/?offset=1", headers=auth_header) + response = client.get("/footprints/", headers=auth_header) assert response.status_code == 200 - print(f"data = {response.json()['data']}") assert len(response.json()["data"]) == 5 assert response.json() assert response.json()["data"][1] assert response.json()["data"][4] + def test_read_product_footprints_with_offset(client, auth_header, seed_database): - response = client.get("/footprints/", headers=auth_header) + response = client.get("/footprints/?offset=3", headers=auth_header) assert response.status_code == 200 print(f"data = {response.json()['data']}") - assert len(response.json()["data"]) == 11 + assert len(response.json()["data"]) == 2 assert response.json() + assert response.json()["data"][0] assert response.json()["data"][1] - assert response.json()["data"][2] def test_read_product_footprints_with_limit(client, auth_header, seed_database):