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
62 changes: 39 additions & 23 deletions test_pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,52 @@
'''
def test_pet_schema():
test_endpoint = "/pets/1"

response = api_helpers.get_api_data(test_endpoint)

assert response.status_code == 200

# Validate the response schema against the defined schema in schemas.py
validate(instance=response.json(), schema=schemas.pet)

'''
TODO: Finish this test by...
1) Extending the parameterization to include all available statuses
2) Validate the appropriate response code
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")])
# '''
# TODO: Finish this test by...
# 1) Extending the parameterization to include all available statuses
# 2) Validate the appropriate response code
# 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"])
def test_find_by_status_200(status):
test_endpoint = "/pets/findByStatus"
params = {
"status": status
}
params = {"status": status}

response = api_helpers.get_api_data(test_endpoint, params=params)

response = api_helpers.get_api_data(test_endpoint, params)
# TODO...
assert response.status_code == 200, f"Expected 200 but got {response.status_code}"

pets = response.json()

'''
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
assert isinstance(pets, list), "Expected response to be a list"

for pet in pets:
validate(instance=pet, schema=schemas.pet)
assert pet["status"] == 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
# '''
@pytest.mark.parametrize("invalid_id", [10, 99, 999])
def test_get_by_id_404(invalid_id):


test_endpoint = f"/pets/{invalid_id}"
response = api_helpers.get_api_data(test_endpoint)


assert response.status_code == 404, f"Expected 404 but got {response.status_code}"


assert_that(response.text, contains_string("Pet with ID"))
28 changes: 27 additions & 1 deletion test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,30 @@
4) Validate the response message "Order and pet status updated successfully"
'''
def test_patch_order_by_id():
pass



new_order = {"pet_id": 0}
post_response = api_helpers.post_api_data("/store/order", new_order)


assert post_response.status_code == 201, f"Expected 201 but got {post_response.status_code}"
order_data = post_response.json()
order_id = order_data["id"]


update_payload = {"status": "sold"}
patch_endpoint = f"/store/order/{order_id}"
patch_response = api_helpers.patch_api_data(patch_endpoint, update_payload)


assert patch_response.status_code == 200, f"Expected 200 but got {patch_response.status_code}"
response_json = patch_response.json()

assert "message" in response_json
assert_that(response_json["message"], contains_string("Order and pet status updated successfully"))


pet_response = api_helpers.get_api_data("/pets/0")
assert pet_response.status_code == 200
assert pet_response.json()["status"] == "sold"