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
21 changes: 13 additions & 8 deletions test_pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
The purpose of this test is to validate the response matches the expected schema defined in schemas.py
'''
def test_pet_schema():
test_endpoint = "/pets/1"

response = api_helpers.get_api_data(test_endpoint)
response = api_helpers.get_api_data("/pets/1")

assert response.status_code == 200

Expand All @@ -26,21 +24,28 @@ 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", "pending", "sold"])
def test_find_by_status_200(status):
test_endpoint = "/pets/findByStatus"
params = {
"status": status
}

response = api_helpers.get_api_data(test_endpoint, params)
response = api_helpers.get_api_data("/pets/findByStatus", params={"status":status})
assert response.status_code == 200

for pet in response.json():
assert pet["status"] == status
validate(instance=pet, schema=schemas.pet)

# TODO...

'''
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, 9999, "abc"])
def test_get_by_id_404(pet_id):
response = api_helpers.get_api_data(f"/pets/{pet_id}")
assert response.status_code == 404
34 changes: 25 additions & 9 deletions test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@
import api_helpers
from hamcrest import assert_that, contains_string, is_

'''
TODO: Finish this test by...
1) Creating a function to test the PATCH request /store/order/{order_id}
2) *Optional* Consider using @pytest.fixture to create unique test data for each run
2) *Optional* Consider creating an 'Order' model in schemas.py and validating it in the test
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
# 1. (Optional) Create a new order to patch (create necessary test data)
order_data = {
"id": 12345,
"petId": 12,
"quantity": 1,
"status": "placed"
}
import json
create_res = api_helpers.post_api_data("/store/order", data=json.dumps(order_data))
assert create_res.status_code == 200

# 2. Send a PATCH request to update pet and order status
patch_data = {
"status": "delivered"
}
patch_res = api_helpers.patch_api_data(f"/store/order/{order_data['id']}", json=patch_data)
assert patch_res.status_code == 200

# 3. Verify response contains the required message
response_json = patch_res.json()
assert "message" in response_json
assert_that(response_json["message"], contains_string("Order and pet status updated successfully"))

# 4. (Optional) Validate order model schema if available
# validate(instance=response_json["order"], schema=schemas.order)