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
25 changes: 20 additions & 5 deletions test_pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,36 @@ 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)
assert all(pet["status"] == status for pet in pets)

for pet in pets:
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", [3, 99, 999999])
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
json_body = response.json()
assert_that(json_body.get("message", ""), contains_string(f"Pet with ID {pet_id} not found"))
33 changes: 32 additions & 1 deletion test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import schemas
import api_helpers
from hamcrest import assert_that, contains_string, is_
import uuid

'''
TODO: Finish this test by...
Expand All @@ -13,4 +14,34 @@
4) Validate the response message "Order and pet status updated successfully"
'''
def test_patch_order_by_id():
pass
#Create a unique pet that is guaranteed to be available for Ordering
pet_id = (uuid.uuid4().int % 1000000) + 1000
pet_data = {
"id": pet_id,
"name": f"TestPet{pet_id}",
"type": "cat",
"status": "available"
}

create_pet_response = api_helpers.post_api_data("/pets", pet_data)
assert create_pet_response.status_code == 201

#place an order for the newly created pet
create_order_response = api_helpers.post_api_data("/store/order", {
"pet_id": pet_id
})
assert create_order_response.status_code == 201

order_id = create_order_response.json()["id"]

#Now update the order status to 'sold' using PATCH
patch_response = api_helpers.patch_api_data(f"/store/order/{order_id}", {
"status": "sold"
})
assert patch_response.status_code == 200
assert_that(patch_response.text, contains_string("Order and pet status updated successfully"))

#verify the related pet status is also updated to 'sold'
get_pet_response = api_helpers.get_api_data(f"/pets/{pet_id}")
assert get_pet_response.status_code == 200
assert_that(get_pet_response.json()["status"], is_("sold"))