From 8b4555a9c29f13f72d6b8719c63b92d62f04661c Mon Sep 17 00:00:00 2001
From: justjoinany <109097228+justjoinany@users.noreply.github.com>
Date: Tue, 24 Mar 2026 16:36:15 -0400
Subject: [PATCH 1/2] [Vernon Degala] - Ally Coding Challenge
---
.idea/.gitignore | 10 +++++
.../inspectionProfiles/profiles_settings.xml | 6 +++
.idea/misc.xml | 7 ++++
.idea/modules.xml | 8 ++++
.idea/pytest-api-example.iml | 19 ++++++++++
.idea/vcs.xml | 6 +++
api_helpers.py | 2 +-
app.py | 3 ++
schemas.py | 2 +-
test_pet.py | 32 +++++++++++++---
test_store.py | 37 +++++++++++++++++--
11 files changed, 122 insertions(+), 10 deletions(-)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/pytest-api-example.iml
create mode 100644 .idea/vcs.xml
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..ab1f4164
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,10 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Ignored default folder with query files
+/queries/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 00000000..105ce2da
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..bfe170c6
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..a3bbaeda
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/pytest-api-example.iml b/.idea/pytest-api-example.iml
new file mode 100644
index 00000000..d4510ba7
--- /dev/null
+++ b/.idea/pytest-api-example.iml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/api_helpers.py b/api_helpers.py
index 62f6f0db..3e82f4ba 100644
--- a/api_helpers.py
+++ b/api_helpers.py
@@ -1,6 +1,6 @@
import requests
-base_url = 'http://localhost:5000'
+base_url = 'http://127.0.0.1:5000'
# GET requests
def get_api_data(endpoint, params = {}):
diff --git a/app.py b/app.py
index 1925371f..83915380 100644
--- a/app.py
+++ b/app.py
@@ -44,6 +44,9 @@
},
{
'id': 2, 'name': 'flippy', 'type': 'fish', 'status': 'available'
+ },
+ {
+ 'id': 3, 'name': 'vernon', 'type': 'fish', 'status': 'sold'
}
]
diff --git a/schemas.py b/schemas.py
index 946cb6cc..760be600 100644
--- a/schemas.py
+++ b/schemas.py
@@ -6,7 +6,7 @@
"type": "integer"
},
"name": {
- "type": "integer"
+ "type": "string"
},
"type": {
"type": "string",
diff --git a/test_pet.py b/test_pet.py
index e2156781..a2236f42 100644
--- a/test_pet.py
+++ b/test_pet.py
@@ -2,7 +2,7 @@
import pytest
import schemas
import api_helpers
-from hamcrest import assert_that, contains_string, is_
+from hamcrest import assert_that, contains_string, is_, equal_to, any_of
'''
TODO: Finish this test by...
@@ -14,10 +14,14 @@ def test_pet_schema():
response = api_helpers.get_api_data(test_endpoint)
- assert response.status_code == 200
+ if response.status_code in [403, 404]:
+ pytest.fail("Forbidden. Server is blocking the request")
+ assert response.status_code == 200
# Validate the response schema against the defined schema in schemas.py
+ # vernon = response.json()
validate(instance=response.json(), schema=schemas.pet)
+ # print(vernon)
'''
TODO: Finish this test by...
@@ -26,7 +30,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", "pending", "sold"])
def test_find_by_status_200(status):
test_endpoint = "/pets/findByStatus"
params = {
@@ -35,12 +39,30 @@ def test_find_by_status_200(status):
response = api_helpers.get_api_data(test_endpoint, params)
# TODO...
+ assert response.status_code == 200
+ pets = response.json()
+ for pet in pets:
+ assert_that(pet["status"], is_(equal_to(status)))
+ validate(instance=pet, schema=schemas.pet)
+ print(pets)
'''
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", [4, 1000, -1, "vernon", 0.01, "v"])
+def test_get_by_id_404(pet_id):
# TODO...
- pass
\ No newline at end of file
+ test_endpoint = "/pets/" + str(pet_id)
+ params = {
+ "pet_id": pet_id
+ }
+ response = api_helpers.get_api_data(test_endpoint, params)
+ assert response.status_code == 404
+ assert_that(response.text, any_of(
+ contains_string(f"Pet with ID {pet_id} not found"),
+ contains_string(f"404 Not Found")
+ ))
+ # print(response)
\ No newline at end of file
diff --git a/test_store.py b/test_store.py
index 186bd792..e0fd6898 100644
--- a/test_store.py
+++ b/test_store.py
@@ -2,7 +2,7 @@
import pytest
import schemas
import api_helpers
-from hamcrest import assert_that, contains_string, is_
+from hamcrest import assert_that, contains_string, is_, any_of, equal_to
'''
TODO: Finish this test by...
@@ -12,5 +12,36 @@
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 post_order(request):
+ test_endpoint = "/store/order"
+ params = {
+ "pet_id": request.param,
+ }
+ response = api_helpers.post_api_data(test_endpoint, params)
+ if response.status_code != 201:
+ pytest.skip(f"Pet with ID {params["pet_id"]} is not available for order")
+ return response.json()
+
+@pytest.mark.parametrize("post_order, target_status", [
+ (0, "available"), #pet_id, expectd status
+ (1, "pending"),
+ (2, "available"),
+ (3, "sold"),
+], indirect=["post_order"])
+def test_patch_order_by_id(post_order, target_status):
+ order_id = post_order["id"]
+ pet_id = post_order["pet_id"]
+ test_endpoint = f"/store/order/{order_id}"
+ params = {
+ "status": target_status,
+ }
+ response = api_helpers.patch_api_data(test_endpoint, params)
+ assert response.status_code == 200
+ assert_that(response.json()["message"], equal_to("Order and pet status updated successfully"))
+
+ test_endpoint = f"/pets/{pet_id}"
+ check_pet_applied = api_helpers.get_api_data(test_endpoint)
+ assert_that(check_pet_applied.json()["status"], equal_to(target_status))
+
From ced4586a238e040dc9cedf5e7e8730a1629ad9aa Mon Sep 17 00:00:00 2001
From: justjoinany <109097228+justjoinany@users.noreply.github.com>
Date: Tue, 24 Mar 2026 16:54:55 -0400
Subject: [PATCH 2/2] [Vernon Degala] just adding notes
---
api_helpers.py | 2 +-
app.py | 1 +
schemas.py | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/api_helpers.py b/api_helpers.py
index 3e82f4ba..72cc9341 100644
--- a/api_helpers.py
+++ b/api_helpers.py
@@ -1,6 +1,6 @@
import requests
-base_url = 'http://127.0.0.1:5000'
+base_url = 'http://127.0.0.1:5000' # I used the loopback address instead of localhost since I am getting a 403 status code
# GET requests
def get_api_data(endpoint, params = {}):
diff --git a/app.py b/app.py
index 83915380..c7c89d84 100644
--- a/app.py
+++ b/app.py
@@ -35,6 +35,7 @@
api.add_namespace(store_ns)
# In-memory data storage
+# I added id = 3 just to test the sold status
pets = [
{
'id': 0, 'name': 'snowball', 'type': 'cat', 'status': 'available'
diff --git a/schemas.py b/schemas.py
index 760be600..24e46c0f 100644
--- a/schemas.py
+++ b/schemas.py
@@ -6,7 +6,7 @@
"type": "integer"
},
"name": {
- "type": "string"
+ "type": "string" # I changed this from integer to string. I am getting this error: jsonschema.exceptions.ValidationError: 'ranger' is not of type 'integer'
},
"type": {
"type": "string",