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
23 changes: 17 additions & 6 deletions test_pet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ 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)

Expand All @@ -26,21 +24,34 @@ 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)
# Added assertion for response code
assert response.status_code == 200
# added assertion each item in response
data = response.json()
assert isinstance(data, list)
for pet in data:
assert pet.get("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, 999999, "abcd"])
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
34 changes: 32 additions & 2 deletions test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,35 @@
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 order_payload():
return {
"pet_id": 0,
"quantity": 1,
"status": "available",
"complete": False
}

def test_patch_order_by_id(order_payload):

create_resp = api_helpers.post_api_data("/store/order", order_payload)
assert create_resp.status_code == 201

created_order = create_resp.json()
order_id = created_order["id"]
pet_id = created_order["pet_id"]

# 2. Prepare PATCH payload
patch_payload = {
"status": "available"
}

patch_resp = api_helpers.patch_api_data(f"/store/order/{order_id}", patch_payload)
assert_that(patch_resp.status_code, is_(200))
patch_json = patch_resp.json()

assert_that(
patch_json["message"],
contains_string("Order and pet status updated successfully")
)