Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Bug_Report.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Bugs Encountered and Solutions
First_Bug: In schemas.py, the “name” field was set as an integer
First_Solution: API actually returns it as a string. I updated the schema to match the API.

Second_Bug: Schema validation errors due to missing required fields and incorrect field types
Second_Solution: Updated order schema to:
Make status field optional
Handle UUID strings for order IDs
Allow additional properties

Third_Bug: Different response formats (HTML vs JSON) for invalid pet IDs (-1, 999999, 0.5)
Third_Solution: Added better error handling in tests to support both content types

Fourth_Bug: Unable to verify order updates due to missing GET endpoint for /store/order/{order_id}
Fourth_Solution: Implemented alternative validation by checking pet status instead


Fifth_Bug: In-memory data causing test interference when updating pet statuses
Fifth_Solution: Implemented fixture create_order to ensure fresh test data for each run

Sixth_Bug: PATCH requests failing due to missing required fields
Sixth_Solution: Include pet_id in PATCH payload to maintain data integrity
23 changes: 22 additions & 1 deletion schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "integer"
},
"name": {
"type": "integer"
"type": "string"
},
"type": {
"type": "string",
Expand All @@ -18,3 +18,24 @@
},
}
}

order = {
"type": "object",
"required": ["pet_id"],
"properties": {
"id": {
"type": "string"
},
"pet_id": {
"type": "integer"
},
"status": {
"type": "string",
"enum": ["placed", "approved", "delivered", "cancelled", "sold"]
},
"complete": {
"type": "boolean"
}
},
"additionalProperties": True
}
32 changes: 26 additions & 6 deletions test_pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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)

'''
Expand All @@ -26,21 +26,41 @@ 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 = {
"status": status
}

response = api_helpers.get_api_data(test_endpoint, params)
# TODO...
assert response.status_code == 200


pets = response.json()
for pet in pets:

validate(instance=pet, schema=schemas.pet)

assert_that(pet.get("status"), is_(status))

'''
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
@pytest.mark.parametrize("pet_id", [-1, 999999, 0.5])
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

try:
response_data = response.json()
if isinstance(response_data, dict):
error_msg = response_data.get("message", "")
assert "Pet not found" in error_msg or f"Pet with ID {pet_id}" in error_msg
except ValueError:

pass
38 changes: 36 additions & 2 deletions test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
@pytest.fixture
def create_order():
order_payload = {
"pet_id": 0,
"complete": False
}

response = api_helpers.post_api_data("/store/order", order_payload)
if response.status_code != 201:
pytest.fail(f"Failed to create order. Status: {response.status_code}, Response: {response.text}, Headers: {response.headers}")

order = response.json()
assert isinstance(order, dict), f"Expected dict response, got {type(order)}"
assert "id" in order, f"Order response missing 'id' field: {order}"
assert "pet_id" in order, f"Order response missing 'pet_id' field: {order}"

validate(instance=order, schema=schemas.order)
yield order

def test_patch_order_by_id(create_order):
order = create_order
assert "id" in order, "Order fixture did not return required 'id' field"
order_id = order["id"]

patch_payload = {
"status": "sold",
"pet_id": order["pet_id"]
}
response = api_helpers.patch_api_data(f"/store/order/{order_id}", patch_payload)

assert response.status_code == 200
assert_that(response.json().get("message"), is_("Order and pet status updated successfully"))

pet_response = api_helpers.get_api_data(f"/pets/{order['pet_id']}")
assert pet_response.status_code == 200
assert_that(pet_response.json().get("status"), is_("sold"))