From 449840e5c78207ff5877ca56e48cbb81f8c0d3e3 Mon Sep 17 00:00:00 2001 From: Mahesh Yeluka Date: Wed, 25 Mar 2026 13:00:39 -0700 Subject: [PATCH] Update pet schema and implement pet and store tests --- schemas.py | 2 +- test_pet.py | 21 ++++++++++++++++----- test_store.py | 42 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 8 deletions(-) diff --git a/schemas.py b/schemas.py index 946cb6cc..760be600 100644 --- a/schemas.py +++ b/schemas.py @@ -6,7 +6,7 @@ "type": "integer" }, "name": { - "type": "integer" + "type": "string" }, "type": { "type": "string", diff --git a/test_pet.py b/test_pet.py index e2156781..0eddae23 100644 --- a/test_pet.py +++ b/test_pet.py @@ -26,7 +26,7 @@ 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", "pending", "sold"]) def test_find_by_status_200(status): test_endpoint = "/pets/findByStatus" params = { @@ -34,13 +34,24 @@ def test_find_by_status_200(status): } response = api_helpers.get_api_data(test_endpoint, params) - # TODO... + + assert response.status_code == 200 + pets = response.json() + + for pet in pets: + assert pet["status"] == 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", [9999,12345]) +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 + assert response.json()["message"], contains_string(f"Pet with ID {pet_id} not found") \ No newline at end of file diff --git a/test_store.py b/test_store.py index 186bd792..e56faa0f 100644 --- a/test_store.py +++ b/test_store.py @@ -12,5 +12,43 @@ 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_id(): + """Create a new order and return its order id.""" + # Find an available pet dynamically + available_pets_response = api_helpers.get_api_data("/pets/findByStatus", {"status": "available"}) + available_pets = available_pets_response.json() + + assert len(available_pets) > 0, "No available pets to create an order" + + # Create an order for the first available pet + create_order_payload = { + "pet_id": available_pets[0]['id'] + } + create_order_response = api_helpers.post_api_data("/store/order", create_order_payload) + assert create_order_response.status_code == 201 + created_order = create_order_response.json() + order_id = created_order['id'] + + yield order_id + + # Teardown: always reset status after test execution + api_helpers.patch_api_data(f"/store/order/{order_id}", {"status": "available"}) + + + +def test_patch_order_by_id(created_order_id): + order_id = created_order_id + + # PATCH the order with new status + patch_order_response = api_helpers.patch_api_data(f"/store/order/{order_id}", {"status": "sold"}) + + # Validate response code + assert patch_order_response.status_code == 200 + + # Validate the response message + patch_response_body = patch_order_response.json() + assert_that(patch_response_body['message'], is_("Order and pet status updated successfully")) +