From 4e309f0b47da01cc532b78788ee55a5f853e0e89 Mon Sep 17 00:00:00 2001 From: archana30qa-hash Date: Fri, 22 Aug 2025 17:00:19 -0400 Subject: [PATCH 1/3] Update schemas.py --- schemas.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/schemas.py b/schemas.py index 946cb6c..e6196e7 100644 --- a/schemas.py +++ b/schemas.py @@ -6,7 +6,7 @@ "type": "integer" }, "name": { - "type": "integer" + "type": "string" }, "type": { "type": "string", @@ -18,3 +18,19 @@ }, } } +#Added Order schema for validation +order = { + "type": "object", + "required": ["message"], + "properties": { + "id": { + "type": "string" + }, + "pet_id": { + "type": "integer" + }, + "message": { + "type": "string" + } + } +} From 45439017ab6212180804a3f00b35b669db6c1370 Mon Sep 17 00:00:00 2001 From: archana30qa-hash Date: Fri, 22 Aug 2025 17:10:12 -0400 Subject: [PATCH 2/3] Update test_pet.py --- test_pet.py | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/test_pet.py b/test_pet.py index e215678..b5545c8 100644 --- a/test_pet.py +++ b/test_pet.py @@ -4,11 +4,7 @@ import api_helpers from hamcrest import assert_that, contains_string, is_ -''' -TODO: Finish this test by... -1) Troubleshooting and fixing the test failure -The purpose of this test is to validate the response matches the expected schema defined in schemas.py -''' + def test_pet_schema(): test_endpoint = "/pets/1" @@ -19,14 +15,8 @@ def test_pet_schema(): # Validate the response schema against the defined schema in schemas.py validate(instance=response.json(), schema=schemas.pet) -''' -TODO: Finish this test by... -1) Extending the parameterization to include all available statuses -2) Validate the appropriate response code -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"]) #adjusted and added more statuses def test_find_by_status_200(status): test_endpoint = "/pets/findByStatus" params = { @@ -34,13 +24,29 @@ def test_find_by_status_200(status): } response = api_helpers.get_api_data(test_endpoint, params) - # TODO... - -''' -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 + #validates the response code + assert response.status_code == 200, f"Expected status code 200, got {response.status_code}" + + pets = response.json() + assert isinstance(pets, list), "Response is not a list of pets" + + for pet in pets: + assert pet.get("status") == status, f"Expected status {status}, got {pet.get('status')}" + validate(instance=pet, schema=schemas.pet) + +#checks for a 404 response +@pytest.mark.parametrize("invalid_id", [-1, 999999, "invalid_id"]) +def test_get_by_id_404(invalid_id): + test_endpoint = f"/pets/{invalid_id}" + + response = api_helpers.get_api_data(test_endpoint) + assert response.status_code == 404, f"Expected status code 404, got {response.status_code}" + + if response.headers.get("Content-Type", "").startswith("application/json"): + try: + error_data = response.json() + if error_data: + assert "message" in error_data, "Error response should contain 'message'" + assert_that(error_data["message"], contains_string("not found")) + except ValueError: + pass From f9e26f4a4c2d96bc1f8bcc33498fb09dbafafa6b Mon Sep 17 00:00:00 2001 From: archana30qa-hash Date: Fri, 22 Aug 2025 17:13:32 -0400 Subject: [PATCH 3/3] Update test_store.py --- test_store.py | 65 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/test_store.py b/test_store.py index 186bd79..44e59fd 100644 --- a/test_store.py +++ b/test_store.py @@ -2,15 +2,60 @@ import pytest import schemas import api_helpers +import random from hamcrest import assert_that, contains_string, is_ -''' -TODO: Finish this test by... -1) Creating a function to test the PATCH request /store/order/{order_id} -2) *Optional* Consider using @pytest.fixture to create unique test data for each run -2) *Optional* Consider creating an 'Order' model in schemas.py and validating it in the test -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 new_order(): + # Unique test data using random ID + pet_id = random.randint(1, 1000) + pet_data = { + "id": pet_id, + "name": "ranger", + "status": "available", + "type": "dog" + } + + pet_response = api_helpers.post_api_data("/pets", pet_data) + assert pet_response.status_code == 201, f"Failed to create pet, got {pet_response.status_code}" + + order_data = { + "pet_id": pet_id, + "quantity": 1, + "shipDate": "2025-08-06T00:00:00Z", + "status": "placed", + "complete": False + } + + order_response = api_helpers.post_api_data("/store/order", order_data) + assert order_response.status_code == 201, f"Failed to create order, got {order_response.status_code}" + + order_json = order_response.json() + assert "id" in order_json, "Order response did not contain 'id'" + + return order_json + + +def test_patch_order_by_id(new_order): + # Testing PATCH endpoint + order_id = new_order["id"] + test_endpoint = f"/store/order/{order_id}" + + patch_data = { + "status": "available" + } + + response = api_helpers.patch_api_data(test_endpoint, patch_data) + + # Validate response code + assert response.status_code == 200, f"Expected 200 OK, got {response.status_code}" + + response_data = response.json() + + # Validate with 'Order' schema (optional) + if hasattr(schemas, 'order'): + validate(instance=response_data, schema=schemas.order) + + # Validate success message + assert response_data.get("message") == "Order and pet status updated successfully", \ + f"Unexpected message: {response_data.get('message')}"