From 10b66bf16088107ef5975dec365327308af61929 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 9 Jan 2026 01:05:59 -0500 Subject: [PATCH 1/2] Ally Assessment --- schemas.py | 2 +- test_pet.py | 45 +++++++++++++++++++++------------------------ test_store.py | 23 ++++++++++++++--------- 3 files changed, 36 insertions(+), 34 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..7c0b7bb 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" @@ -16,17 +12,9 @@ def test_pet_schema(): 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")]) +@pytest.mark.parametrize("status", [("available"), ("pending"), ("sold")]) def test_find_by_status_200(status): test_endpoint = "/pets/findByStatus" params = { @@ -34,13 +22,22 @@ 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 + + # Validate response code is 200 + assert response.status_code == 200 + + pets = response.json() + + for pet in pets: + assert pet["status"] == status + + validate(instance=pet, schema=schemas.pet) + +@pytest.mark.parametrize("pet_id", [(999), (-1), (3)]) +def test_get_by_id_404(pet_id): + test_endpoint = f"/pets/{pet_id}" + + response = api_helpers.get_api_data(test_endpoint) + + # Verify a 404 status code + assert response.status_code == 404 \ No newline at end of file diff --git a/test_store.py b/test_store.py index 186bd79..ed1078f 100644 --- a/test_store.py +++ b/test_store.py @@ -4,13 +4,18 @@ import api_helpers 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 + order_data = {"pet_id": 2} + create_response = api_helpers.post_api_data("/store/order", order_data) + + assert create_response.status_code == 201 + + order_id = create_response.json()["id"] + + update_data = {"status": "sold"} + patch_response = api_helpers.patch_api_data(f"/store/order/{order_id}", update_data) + + assert patch_response.status_code == 200 + + # Verify response message + assert patch_response.json()["message"] == "Order and pet status updated successfully" \ No newline at end of file From 88284f46bb6cfcc68641a9b61318fdb7067b3231 Mon Sep 17 00:00:00 2001 From: Ahmed Date: Sun, 11 Jan 2026 22:30:06 -0500 Subject: [PATCH 2/2] Complete API testing assignment - Fixed schema validation bug (name should be string) - Completed all 3 test_pet.py tests - Created PATCH test for test_store.py - Added pytest fixture and order schema (optional tasks) - All 8 tests passing --- schemas.py | 13 +++++++++++++ test_pet.py | 1 - test_store.py | 10 ++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/schemas.py b/schemas.py index 760be60..b3293a6 100644 --- a/schemas.py +++ b/schemas.py @@ -18,3 +18,16 @@ }, } } + +order = { + "type": "object", + "required": ["id", "pet_id"], + "properties": { + "id": { + "type": "string" + }, + "pet_id": { + "type": "integer" + } + } +} \ No newline at end of file diff --git a/test_pet.py b/test_pet.py index 7c0b7bb..5b0105e 100644 --- a/test_pet.py +++ b/test_pet.py @@ -30,7 +30,6 @@ def test_find_by_status_200(status): for pet in pets: assert pet["status"] == status - validate(instance=pet, schema=schemas.pet) @pytest.mark.parametrize("pet_id", [(999), (-1), (3)]) diff --git a/test_store.py b/test_store.py index ed1078f..cfaef98 100644 --- a/test_store.py +++ b/test_store.py @@ -4,13 +4,19 @@ import api_helpers from hamcrest import assert_that, contains_string, is_ -def test_patch_order_by_id(): +@pytest.fixture +def created_order(): order_data = {"pet_id": 2} create_response = api_helpers.post_api_data("/store/order", order_data) assert create_response.status_code == 201 - order_id = create_response.json()["id"] + validate(instance=create_response.json(), schema=schemas.order) + + return create_response + +def test_patch_order_by_id(created_order): + order_id = created_order.json()["id"] update_data = {"status": "sold"} patch_response = api_helpers.patch_api_data(f"/store/order/{order_id}", update_data)