From cc7d01e8349347b4d4afb655c0385357a80aece5 Mon Sep 17 00:00:00 2001 From: anilrajselenium Date: Wed, 18 Mar 2026 09:31:59 -0400 Subject: [PATCH 1/2] Complete pet/store API tests and schema fixes --- schemas.py | 11 +++++++-- test_pet.py | 28 +++++++++++++++------ test_store.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 95 insertions(+), 12 deletions(-) diff --git a/schemas.py b/schemas.py index 946cb6cc..d620fce8 100644 --- a/schemas.py +++ b/schemas.py @@ -6,8 +6,8 @@ "type": "integer" }, "name": { - "type": "integer" - }, + "type": "string" + }, # fix: was integer "type": { "type": "string", "enum": ["cat", "dog", "fish"] @@ -18,3 +18,10 @@ }, } } +order_patch_success = { + "type": "object", + "required": ["message"], + "properties": { + "message": {"type": "string"} + } +} \ No newline at end of file diff --git a/test_pet.py b/test_pet.py index e2156781..de714cfd 100644 --- a/test_pet.py +++ b/test_pet.py @@ -26,21 +26,33 @@ def test_pet_schema(): 3) Validate the 'status' property in the response is equal to the expected status 4) Validate the schema for each object in the response ''' -@pytest.mark.parametrize("status", [("available")]) + +@pytest.mark.parametrize("status", ["available", "sold", "pending"]) def test_find_by_status_200(status): test_endpoint = "/pets/findByStatus" - params = { - "status": status - } + params = {"status": status} response = api_helpers.get_api_data(test_endpoint, params) - # TODO... + assert response.status_code == 200 + body = response.json() + assert isinstance(body, list) + + for pet in body: + assert_that(pet["status"], is_(status)) + validate(instance=pet, schema=schemas.pet) ''' TODO: Finish this test by... 1) Testing and validating the appropriate 404 response for /pets/{pet_id} 2) Parameterizing the test for any edge cases ''' -def test_get_by_id_404(): - # TODO... - pass \ No newline at end of file + +@pytest.mark.parametrize("pet_id", [3, 999, 2147483647]) +def test_get_by_id_404(pet_id): + test_endpoint = f"/pets/{pet_id}" + + response = api_helpers.get_api_data(test_endpoint) + + assert response.status_code == 404 + body = response.json() + assert_that(body["message"], contains_string("not found")) \ No newline at end of file diff --git a/test_store.py b/test_store.py index 186bd792..6b2a690a 100644 --- a/test_store.py +++ b/test_store.py @@ -12,5 +12,69 @@ 3) Validate the response codes and values 4) Validate the response message "Order and pet status updated successfully" ''' -def test_patch_order_by_id(): - pass +@pytest.fixture +def created_order(): + # 1) Get all pets and compute a unique ID + all_pets_response = api_helpers.get_api_data("/pets/") + assert all_pets_response.status_code == 200 + all_pets = all_pets_response.json() + + next_id = max([p["id"] for p in all_pets], default=-1) + 1 + + # 2) Create a fresh AVAILABLE pet for this test run + new_pet = { + "id": next_id, + "name": f"qa_pet_{next_id}", + "type": "dog", + "status": "available" + } + + create_pet_response = api_helpers.post_api_data("/pets/", new_pet) + assert create_pet_response.status_code == 201 + + # 3) Create order for that fresh pet + create_order_response = api_helpers.post_api_data("/store/order", {"pet_id": next_id}) + assert create_order_response.status_code == 201 + + order = create_order_response.json() + assert "id" in order + assert order["pet_id"] == next_id + + return {"order_id": order["id"], "pet_id": next_id} +@pytest.mark.parametrize("new_status", ["pending", "sold", "available"]) +def test_patch_order_by_id(created_order, new_status): + order_id = created_order["order_id"] + pet_id = created_order["pet_id"] + + # PATCH /store/order/{order_id} + patch_response = api_helpers.patch_api_data( + f"/store/order/{order_id}", + {"status": new_status} + ) + + # Validate response code + message + assert patch_response.status_code == 200 + patch_body = patch_response.json() + assert_that( + patch_body["message"], + is_("Order and pet status updated successfully") + ) + + # Validate values by checking the linked pet status is updated + pet_response = api_helpers.get_api_data(f"/pets/{pet_id}") + assert pet_response.status_code == 200 + + pet_body = pet_response.json() + assert_that(pet_body["status"], is_(new_status)) + validate(instance=pet_body, schema=schemas.pet) +def test_patch_order_by_id_404(): + patch_response = api_helpers.patch_api_data( + "/store/order/not-a-real-order-id", + {"status": "sold"} + ) + + patch_body = patch_response.json() + + assert patch_response.status_code == 404 + assert_that(patch_body["message"], contains_string("Order not found")) + validate(instance=patch_body, schema=schemas.order_patch_success) \ No newline at end of file From 05d664a908d27ace14198ad2bb7ab320d6091562 Mon Sep 17 00:00:00 2001 From: anilrajselenium Date: Tue, 24 Mar 2026 18:45:38 -0400 Subject: [PATCH 2/2] Complete task 3 changes --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 1925371f..36e2a0fd 100644 --- a/app.py +++ b/app.py @@ -6,7 +6,7 @@ api = Api(app, version='1.0', title='Petstore API', description='A simple Petstore API') -# Enums +# Enumscls PET_STATUS = ['available', 'sold', 'pending'] PET_TYPE = ['cat', 'dog', 'fish']