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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ test_scratch.py
pet_scratch.py
store_scratch.py
report.html
style.css
style.css

# virtual env
.venv
20 changes: 19 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,21 @@
},
}
}


order = {
"type": "object",
"required": ["id", "pet_id"],
"properties": {
"id": {
"type": "string"
},
"pet_id": {
"type": "integer"
},
"status": {
"type": "string",
"enum": ["available", "sold", "pending"]
},
}
}
28 changes: 25 additions & 3 deletions test_pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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"), pytest.param(" ", marks=pytest.mark.xfail)])
def test_find_by_status_200(status):
test_endpoint = "/pets/findByStatus"
params = {
Expand All @@ -35,12 +35,34 @@ def test_find_by_status_200(status):

response = api_helpers.get_api_data(test_endpoint, params)
# TODO...
# 2) Validate the appropriate response code
assert response.status_code == 200

# check if the response is a list object
assert isinstance(response.json(), list), "Response is not a list"

# 3) Validate the 'status' property in the response is equal to the expected status
# 4) Validate the schema for each object in the response
for item in response.json():
assert item['status'] == status
validate(instance=item,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():
@pytest.mark.parametrize("pet_id", [
9999, # non-existent pet_id
# -1, # invalid negative pet_id, But I get a default html 404 when i try this.
1000000000 # very large pet_id ,invalid for now
])
def test_get_by_id_404(pet_id):
# TODO...
pass
test_endpoint = f"/pets/{pet_id}"

response = api_helpers.get_api_data(test_endpoint)

assert response.status_code == 404
assert response.json() is not None
assert f"Pet with ID {pet_id} not found" in response.json()["message"]
44 changes: 42 additions & 2 deletions test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,45 @@
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

#using pytest fixture to create an order for available pet
@pytest.fixture
def create_order():
# Create a new order for testing
order_data = {
"pet_id": 2 # Assuming pet with id 2 exists and is available
}
response = api_helpers.post_api_data('/store/order', order_data)
assert response.status_code == 201
order = response.json()
yield order

#revert/clean up
order_id = order['id']
test_endpoint = f'/store/order/{order_id}'
update_data = {
"status": 'available'
}
response = api_helpers.patch_api_data(test_endpoint, update_data)

@pytest.mark.parametrize("status", [("sold"),("pending")])
def test_patch_order_by_id(create_order,status):
order = create_order

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

order_id = order['id']


test_endpoint = f'/store/order/{order_id}'
update_data = {
"status": status
}
response = api_helpers.patch_api_data(test_endpoint, update_data)

assert response.status_code == 200
response_data = response.json()
assert response_data["message"] == "Order and pet status updated successfully"