diff --git a/schemas.py b/schemas.py index 946cb6cc..5e3987ca 100644 --- a/schemas.py +++ b/schemas.py @@ -6,7 +6,7 @@ "type": "integer" }, "name": { - "type": "integer" + "type": "string" }, "type": { "type": "string", @@ -18,3 +18,20 @@ }, } } + +order = { + "type": "object", + "required": ["pet_id", "id"], + "properties": { + "id": { + "type": "string" + }, + "pet_id": { + "type": "integer" + }, + "status": { + "type": "string", + "enum": ["available", "sold", "pending"] + } + } +} diff --git a/test_pet.py b/test_pet.py index e2156781..6689110b 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", "pending", "sold"]) def test_find_by_status_200(status): test_endpoint = "/pets/findByStatus" params = { @@ -34,13 +34,27 @@ def test_find_by_status_200(status): } response = api_helpers.get_api_data(test_endpoint, params) - # TODO... + + assert response.status_code == 200 + pets_list = response.json() + + for pet_item in pets_list: + assert pet_item.get("status") == status + validate(instance=pet_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(): - # TODO... - pass \ No newline at end of file +@pytest.mark.parametrize("pet_id", [-1, 999, 9999]) +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 + if "application/json" in response.headers.get("Content-Type", ""): + error_msg = response.json().get('message', '') + assert 'not found' in error_msg.lower() + else: + assert 'Not Found' in response.text \ No newline at end of file diff --git a/test_store.py b/test_store.py index 186bd792..2ad9f159 100644 --- a/test_store.py +++ b/test_store.py @@ -12,5 +12,39 @@ 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 +import uuid + +@pytest.fixture +def new_order(): + # Create a unique pet to ensure it's 'available' + pet_id = int(str(uuid.uuid4().int)[:8]) + pet_data = { + "id": pet_id, + "name": "fixture_pet", + "type": "cat", + "status": "available" + } + api_helpers.post_api_data("/pets", pet_data) + + # Place an order for this new pet + order_data = {"pet_id": pet_id} + response = api_helpers.post_api_data("/store/order", order_data) + + return response.json() + +def test_patch_order_by_id(new_order): + order_id = new_order.get("id") + + # Validate the order uses the Order schema created in schemas.py + validate(instance=new_order, schema=schemas.order) + + # Update the order status using PATCH + patch_payload = {"status": "sold"} + response = api_helpers.patch_api_data(f"/store/order/{order_id}", patch_payload) + + # 3) Validate the response codes and values + assert response.status_code == 200 + + # 4) Validate the response message + resp_json = response.json() + assert resp_json.get("message") == "Order and pet status updated successfully"