diff --git a/app.py b/app.py index 1925371f..7525f40c 100644 --- a/app.py +++ b/app.py @@ -98,7 +98,7 @@ def get(self): """Find pets by status""" status = request.args.get('status') if status not in PET_STATUS: - api.abort(400, 'Invalid pet status {status}') + api.abort(400, f"Invalid pet status {status}") if status: filtered_pets = [pet for pet in pets if pet['status'] == status] return filtered_pets diff --git a/schemas.py b/schemas.py index 946cb6cc..760be600 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 e2156781..9d20eb6f 100644 --- a/test_pet.py +++ b/test_pet.py @@ -18,6 +18,12 @@ def test_pet_schema(): # Validate the response schema against the defined schema in schemas.py validate(instance=response.json(), schema=schemas.pet) + # Verify the response contains expected data + data = response.json() + assert data['id'] == 1 + assert data['name'] == 'ranger' + assert data['type'] == 'dog' + assert data['status'] == 'pending' ''' TODO: Finish this test by... @@ -26,7 +32,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"]) def test_find_by_status_200(status): test_endpoint = "/pets/findByStatus" params = { @@ -34,13 +40,31 @@ def test_find_by_status_200(status): } response = api_helpers.get_api_data(test_endpoint, params) - # TODO... + # Validate the response code + assert response.status_code == 200 + + # Get response data + pets_list = response.json() + + # Validate that all returned pets have the expected status + for pet in pets_list: + assert pet['status'] == status, f"Expected status '{status}' but got '{pet['status']}'" + # Validate the schema for each object in the response + validate(instance=pet, 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", [999, -1, 1000000]) +def test_get_by_id_404(pet_id): + test_endpoint = f"/pets/{pet_id}" + + response = api_helpers.get_api_data(test_endpoint) + + # Validate the 404 response code + assert response.status_code == 404 + + # Validate the error message contains appropriate text + assert_that(response.text, contains_string(f"Pet with ID {pet_id} not found")) \ No newline at end of file diff --git a/test_store.py b/test_store.py index 186bd792..a7442acf 100644 --- a/test_store.py +++ b/test_store.py @@ -13,4 +13,28 @@ 4) Validate the response message "Order and pet status updated successfully" ''' def test_patch_order_by_id(): - pass + # First, create an order + order_data = { + "pet_id": 0 + } + + create_response = api_helpers.post_api_data("/store/order", order_data) + assert create_response.status_code == 201, f"Failed to create order: {create_response.text}" + + order = create_response.json() + order_id = order['id'] + + # Now test the PATCH request + update_data = { + "status": "sold" + } + + patch_response = api_helpers.patch_api_data(f"/store/order/{order_id}", update_data) + + # Validate the response code + assert patch_response.status_code == 200 + + # Validate the response message + response_data = patch_response.json() + assert response_data['message'] == "Order and pet status updated successfully" + assert_that(response_data['message'], contains_string("Order and pet status updated successfully"))