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
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 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 Down
34 changes: 29 additions & 5 deletions test_pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -26,21 +32,39 @@ 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...
# 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
@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"))
26 changes: 25 additions & 1 deletion test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))