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
23 changes: 22 additions & 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 All @@ -18,3 +18,24 @@
},
}
}

order = {
"type": "object",
"required": ["pet_id"],
"properties": {
"id": {
"type": "string"
},
"pet_id": {
"type": "integer"
},
"status": {
"type": "string",
"enum": ["pending", "sold", "available"]
},
"complete": {
"type": "boolean"
}
},
"additionalProperties": True
}
32 changes: 27 additions & 5 deletions test_pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,43 @@ 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 response code
assert response.status_code == 200

# Validate each pet's status and schema
for pet in response.json():
assert pet["status"] == status
validate(instance=pet, schema=schemas.pet)
assert_that(pet.get("status"), is_(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
'''
def test_get_by_id_404():
# TODO...
pass
@pytest.mark.parametrize("pet_id", [5])
def test_get_by_id_404(pet_id):
test_endpoint = f"/pets/{pet_id}"

response = api_helpers.get_api_data(test_endpoint)

# Validate response code
assert response.status_code == 404

# Validate error message
try:
response_body = response.json()
if(isinstance(response_body, dict)):
error_message = response_body.get("message", "")
assert "Pet not found" in error_message or f"Pet with ID {pet_id}" in error_message
except Exception:
pytest.fail(f"404: request failed to return valid JSON response")
45 changes: 43 additions & 2 deletions test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import pytest
import schemas
import api_helpers
import uuid
import random
from app import PET_TYPE
from hamcrest import assert_that, contains_string, is_

'''
Expand All @@ -12,5 +15,43 @@
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.fixture()
def create_pet():
endpoint = "/pets/"
params = {
"id" : uuid.uuid4().int,
"name" : str(uuid.uuid4())[:6],
"type": random.choice(PET_TYPE),
"status": "available"
}

response = api_helpers.post_api_data(endpoint, params)
pet = response.json()
return pet

@pytest.fixture
def create_order(create_pet):
# Create a new order to be used in the test
endpoint = "/store/order"
request_body = {
"pet_id": create_pet["id"],
}

response = api_helpers.post_api_data(endpoint, request_body)
validate(instance=response.json(), schema=schemas.order)
return response.json()


@pytest.mark.parametrize("status", ['available', 'sold'])
def test_patch_order_by_id(status, create_order):
endpoint = f"/store/order/{create_order["id"]}"
request_body = {
"status": status
}

response = api_helpers.patch_api_data(endpoint, request_body)
print(response.json())

assert_that(response.status_code, is_(200))
assert_that(response.json().get("message"), is_("Order and pet status updated successfully"))