From 0d6f0011c19c34824bbdde25493feed8993d7fab Mon Sep 17 00:00:00 2001 From: Arpit Mohanty Date: Thu, 26 Mar 2026 01:17:52 -0400 Subject: [PATCH 1/4] added .venv to gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 751d372d..8d82b9e2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ test_scratch.py pet_scratch.py store_scratch.py report.html -style.css \ No newline at end of file +style.css + +# virtual env +.venv \ No newline at end of file From 0c71ddcad157068780abd33c6d267711c619fc23 Mon Sep 17 00:00:00 2001 From: Arpit Mohanty Date: Thu, 26 Mar 2026 04:05:58 -0400 Subject: [PATCH 2/4] added schema for Order --- schemas.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/schemas.py b/schemas.py index 946cb6cc..1a43351e 100644 --- a/schemas.py +++ b/schemas.py @@ -6,7 +6,7 @@ "type": "integer" }, "name": { - "type": "integer" + "type": "string" }, "type": { "type": "string", @@ -18,3 +18,21 @@ }, } } + + +order = { + "type": "object", + "required": ["id", "pet_id"], + "properties": { + "id": { + "type": "string" + }, + "pet_id": { + "type": "integer" + }, + "status": { + "type": "string", + "enum": ["available", "sold", "pending"] + }, + } +} \ No newline at end of file From df2940c6e1e35291f39600203a7b11210b07ec7b Mon Sep 17 00:00:00 2001 From: Arpit Mohanty Date: Thu, 26 Mar 2026 04:06:36 -0400 Subject: [PATCH 3/4] updated tests for the pet crud operations --- test_pet.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/test_pet.py b/test_pet.py index e2156781..896753cf 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"),("sold"), ("pending"), pytest.param(" ", marks=pytest.mark.xfail)]) def test_find_by_status_200(status): test_endpoint = "/pets/findByStatus" params = { @@ -35,12 +35,34 @@ def test_find_by_status_200(status): response = api_helpers.get_api_data(test_endpoint, params) # TODO... + # 2) Validate the appropriate response code + assert response.status_code == 200 + + # check if the response is a list object + assert isinstance(response.json(), list), "Response is not a list" + + # 3) Validate the 'status' property in the response is equal to the expected status + # 4) Validate the schema for each object in the response + for item in response.json(): + assert item['status'] == status + validate(instance=item,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(): +@pytest.mark.parametrize("pet_id", [ + 9999, # non-existent pet_id + # -1, # invalid negative pet_id, But I get a default html 404 when i try this. + 1000000000 # very large pet_id ,invalid for now + ]) +def test_get_by_id_404(pet_id): # TODO... - pass \ No newline at end of file + test_endpoint = f"/pets/{pet_id}" + + response = api_helpers.get_api_data(test_endpoint) + + assert response.status_code == 404 + assert response.json() is not None + assert f"Pet with ID {pet_id} not found" in response.json()["message"] \ No newline at end of file From 70450d072b7362c45cbae9a783c6e13064a38903 Mon Sep 17 00:00:00 2001 From: Arpit Mohanty Date: Thu, 26 Mar 2026 04:08:50 -0400 Subject: [PATCH 4/4] added context for order creattion, before updating it using parameterized values, also added cleanup/revert of order so as to have idempotent test runs --- test_store.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/test_store.py b/test_store.py index 186bd792..803258f3 100644 --- a/test_store.py +++ b/test_store.py @@ -12,5 +12,45 @@ 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 + +#using pytest fixture to create an order for available pet +@pytest.fixture +def create_order(): + # Create a new order for testing + order_data = { + "pet_id": 2 # Assuming pet with id 2 exists and is available + } + response = api_helpers.post_api_data('/store/order', order_data) + assert response.status_code == 201 + order = response.json() + yield order + + #revert/clean up + order_id = order['id'] + test_endpoint = f'/store/order/{order_id}' + update_data = { + "status": 'available' + } + response = api_helpers.patch_api_data(test_endpoint, update_data) + +@pytest.mark.parametrize("status", [("sold"),("pending")]) +def test_patch_order_by_id(create_order,status): + order = create_order + + # Validate the response schema against the defined schema in schemas.py + validate(instance=order, schema=schemas.order) + + order_id = order['id'] + + + test_endpoint = f'/store/order/{order_id}' + update_data = { + "status": status + } + response = api_helpers.patch_api_data(test_endpoint, update_data) + + assert response.status_code == 200 + response_data = response.json() + assert response_data["message"] == "Order and pet status updated successfully" + + \ No newline at end of file