From eab43d4e8f4747094d8087e0cf5a112427663abb Mon Sep 17 00:00:00 2001 From: sridharsundru730-dotcom Date: Mon, 17 Nov 2025 16:59:47 -0500 Subject: [PATCH 1/2] test cases for the given senorio --- schemas.py | 2 +- test_pet.py | 22 ++++++++++++++++++---- test_store.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/schemas.py b/schemas.py index 946cb6c..760be60 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 e215678..6bf0df9 100644 --- a/test_pet.py +++ b/test_pet.py @@ -26,7 +26,8 @@ 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,6 +35,15 @@ def test_find_by_status_200(status): } response = api_helpers.get_api_data(test_endpoint, params) + # Added assertion for response code + assert response.status_code == 200 + # added assertion each item in response + data = response.json() + assert isinstance(data, list) + for pet in data: + assert pet.get("status") == status + validate(instance=pet, schema=schemas.pet) + # TODO... ''' @@ -41,6 +51,10 @@ def test_find_by_status_200(status): 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", [-1, 999999, "abcd"]) +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 + diff --git a/test_store.py b/test_store.py index 186bd79..2ddbc65 100644 --- a/test_store.py +++ b/test_store.py @@ -12,5 +12,49 @@ 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_payload(): + return { + "petId": 12345699999999, + "quantity": 1, + "shipDate": "2025-01-05T12:00:00Z", + "status": "placed", + "complete": False + } + +def test_patch_order_by_id(new_order_payload): + + # 1. Create an order first (pre-condition) + create_resp = api_helpers.post_api_data("/store/order", new_order_payload) + assert create_resp.status_code == 200 + + created_order = create_resp.json() + order_id = created_order["id"] + pet_id = created_order["petId"] + + # 2. Prepare PATCH payload + patch_payload = { + "status": "approved" + } + + # 3. Execute PATCH request + patch_resp = api_helpers.patch_api_data(f"/store/order/{order_id}", patch_payload) + + # --- Validate response status --- + assert_that(patch_resp.status_code, is_(200)) + + patch_json = patch_resp.json() + + # --- Optional: Schema validation --- + validate(instance=patch_json, schema=schemas.OrderPatchResponseSchema) + + # --- Validate response fields --- + assert patch_json["orderId"] == order_id + assert patch_json["petId"] == pet_id + assert patch_json["status"] == "approved" + + # --- Validate success message --- + assert_that( + patch_json["message"], + contains_string("Order and pet status updated successfully") + ) From b45a3f11cbfa88a5d26da805fe55c305c6bc1055 Mon Sep 17 00:00:00 2001 From: sridharsundru730-dotcom Date: Mon, 17 Nov 2025 23:15:24 -0500 Subject: [PATCH 2/2] test cases for the given senorio --- test_pet.py | 3 --- test_store.py | 32 +++++++++----------------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/test_pet.py b/test_pet.py index 6bf0df9..16b3bc1 100644 --- a/test_pet.py +++ b/test_pet.py @@ -13,9 +13,7 @@ def test_pet_schema(): test_endpoint = "/pets/1" response = api_helpers.get_api_data(test_endpoint) - assert response.status_code == 200 - # Validate the response schema against the defined schema in schemas.py validate(instance=response.json(), schema=schemas.pet) @@ -57,4 +55,3 @@ 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 - diff --git a/test_store.py b/test_store.py index 2ddbc65..3b23199 100644 --- a/test_store.py +++ b/test_store.py @@ -12,48 +12,34 @@ 3) Validate the response codes and values 4) Validate the response message "Order and pet status updated successfully" ''' + @pytest.fixture -def new_order_payload(): +def order_payload(): return { - "petId": 12345699999999, + "pet_id": 0, "quantity": 1, - "shipDate": "2025-01-05T12:00:00Z", - "status": "placed", + "status": "available", "complete": False } -def test_patch_order_by_id(new_order_payload): +def test_patch_order_by_id(order_payload): - # 1. Create an order first (pre-condition) - create_resp = api_helpers.post_api_data("/store/order", new_order_payload) - assert create_resp.status_code == 200 + create_resp = api_helpers.post_api_data("/store/order", order_payload) + assert create_resp.status_code == 201 created_order = create_resp.json() order_id = created_order["id"] - pet_id = created_order["petId"] + pet_id = created_order["pet_id"] # 2. Prepare PATCH payload patch_payload = { - "status": "approved" + "status": "available" } - # 3. Execute PATCH request patch_resp = api_helpers.patch_api_data(f"/store/order/{order_id}", patch_payload) - - # --- Validate response status --- assert_that(patch_resp.status_code, is_(200)) - patch_json = patch_resp.json() - # --- Optional: Schema validation --- - validate(instance=patch_json, schema=schemas.OrderPatchResponseSchema) - - # --- Validate response fields --- - assert patch_json["orderId"] == order_id - assert patch_json["petId"] == pet_id - assert patch_json["status"] == "approved" - - # --- Validate success message --- assert_that( patch_json["message"], contains_string("Order and pet status updated successfully")