From 39fd2cd528f377c4f1e58a38812774bdfcc13e5f Mon Sep 17 00:00:00 2001 From: navyamobileqa11 Date: Fri, 20 Mar 2026 10:33:22 -0400 Subject: [PATCH] Add files via upload --- test_pet.py | 90 +++++++++++++++++++++++++-------------------------- test_store.py | 44 ++++++++++++++++--------- 2 files changed, 73 insertions(+), 61 deletions(-) diff --git a/test_pet.py b/test_pet.py index e2156781..1e186505 100644 --- a/test_pet.py +++ b/test_pet.py @@ -1,46 +1,46 @@ -from jsonschema import validate -import pytest -import schemas -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" - - 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")]) -def test_find_by_status_200(status): - test_endpoint = "/pets/findByStatus" - params = { - "status": 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... +from jsonschema import validate +import pytest +import schemas +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" + + 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")]) +def test_find_by_status_200(status): + test_endpoint = "/pets/findByStatus" + params = { + "status": 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 diff --git a/test_store.py b/test_store.py index 186bd792..3473b05e 100644 --- a/test_store.py +++ b/test_store.py @@ -1,16 +1,28 @@ -from jsonschema import validate -import pytest -import schemas -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 +from jsonschema import validate +import pytest +import schemas +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" +''' +import requests + +def test_patch_order_by_id(): + url = "https://petstore.swagger.io/v2/pet" + + payload = { + "id": 1, + "name": "doggie", + "status": "sold" + } + + response = requests.put(url, json=payload) + + assert_that(response.status_code, is_(200)) \ No newline at end of file