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 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
18 changes: 13 additions & 5 deletions test_pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,29 @@ 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()
assert isinstance(pets, list), "Response should be list"
for pet in pets:
assert_that(pet['status'], is_(status))
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", [9999, -1, 99999, 3])
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
36 changes: 34 additions & 2 deletions test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@
import api_helpers
from hamcrest import assert_that, contains_string, is_

@pytest.fixture
def create_order():
"""Fixture to create a test order and return the order ID"""
# Find an available pet dynamically
response = api_helpers.get_api_data("/pets/findByStatus", {"status": "available"})
available_pets = response.json()

assert len(available_pets) > 0, "No available pets to create an order"

# Create an order for the first available pet
order_data = {
"pet_id": available_pets[0]['id']
}
response = api_helpers.post_api_data("/store/order", order_data)
assert response.status_code == 201
order = response.json()
return order['id']

'''
TODO: Finish this test by...
1) Creating a function to test the PATCH request /store/order/{order_id}
Expand All @@ -12,5 +30,19 @@
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.mark.parametrize("new_status", ["sold", "available", "pending"])
def test_patch_order_by_id(create_order, new_status):
order_id = create_order

# PATCH the order with new status
update_data = {
"status": new_status
}
response = api_helpers.patch_api_data(f"/store/order/{order_id}", update_data)

# Validate response code
assert response.status_code == 200

# Validate the response message
response_data = response.json()
assert_that(response_data['message'], is_("Order and pet status updated successfully"))