From 4d25d0cb91048472edc23a237b6e49672e975200 Mon Sep 17 00:00:00 2001 From: vishnuv11151-oss Date: Thu, 6 Nov 2025 14:48:00 -0500 Subject: [PATCH] Wrote the test cases for for both the test files --- schemas.py | 2 +- test_pet.py | 62 ++++++++++++++++++++++++++++++++------------------- test_store.py | 28 ++++++++++++++++++++++- 3 files changed, 67 insertions(+), 25 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..9312ee3 100644 --- a/test_pet.py +++ b/test_pet.py @@ -11,36 +11,52 @@ ''' 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) -''' -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")]) +# ''' +# 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"]) 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=params) - response = api_helpers.get_api_data(test_endpoint, params) - # TODO... + assert response.status_code == 200, f"Expected 200 but got {response.status_code}" + + pets = response.json() -''' -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 + assert isinstance(pets, list), "Expected response to be a list" + + for pet in pets: + validate(instance=pet, schema=schemas.pet) + assert pet["status"] == status + + +# ''' +# 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 +# ''' +@pytest.mark.parametrize("invalid_id", [10, 99, 999]) +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 404 but got {response.status_code}" + + + assert_that(response.text, contains_string("Pet with ID")) \ No newline at end of file diff --git a/test_store.py b/test_store.py index 186bd79..4175136 100644 --- a/test_store.py +++ b/test_store.py @@ -13,4 +13,30 @@ 4) Validate the response message "Order and pet status updated successfully" ''' def test_patch_order_by_id(): - pass + + + + new_order = {"pet_id": 0} + post_response = api_helpers.post_api_data("/store/order", new_order) + + + assert post_response.status_code == 201, f"Expected 201 but got {post_response.status_code}" + order_data = post_response.json() + order_id = order_data["id"] + + + update_payload = {"status": "sold"} + patch_endpoint = f"/store/order/{order_id}" + patch_response = api_helpers.patch_api_data(patch_endpoint, update_payload) + + + assert patch_response.status_code == 200, f"Expected 200 but got {patch_response.status_code}" + response_json = patch_response.json() + + assert "message" in response_json + assert_that(response_json["message"], contains_string("Order and pet status updated successfully")) + + + pet_response = api_helpers.get_api_data("/pets/0") + assert pet_response.status_code == 200 + assert pet_response.json()["status"] == "sold"