From c5e9c2bc2d56710a44869aab2bfe29be728d48be Mon Sep 17 00:00:00 2001 From: Brad Evans Date: Fri, 24 Oct 2025 12:28:04 -0400 Subject: [PATCH 1/5] updated tests --- schemas.py | 2 +- test_pet.py | 29 +++++++++++++++++++++++++---- test_store.py | 30 +++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/schemas.py b/schemas.py index 946cb6c..760be60 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 e215678..b690c8a 100644 --- a/test_pet.py +++ b/test_pet.py @@ -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", "pending", "sold"]) def test_find_by_status_200(status): test_endpoint = "/pets/findByStatus" params = { @@ -34,6 +34,15 @@ def test_find_by_status_200(status): } response = api_helpers.get_api_data(test_endpoint, params) + + assert response.status_code == 200 + + pets = response.json() + + for pet in pets: + assert_that(pet['status'], is_(status)) + validate(instance=pet, schema=schemas.pet) + # TODO... ''' @@ -41,6 +50,18 @@ def test_find_by_status_200(status): 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 \ No newline at end of file +@pytest.mark.parametrize("pet_id", [895231, 99990, 123456789]) +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 + + + + body = response.json() + assert_that(body['message'], contains_string("not found")) + + \ No newline at end of file diff --git a/test_store.py b/test_store.py index 186bd79..ec14106 100644 --- a/test_store.py +++ b/test_store.py @@ -13,4 +13,32 @@ 4) Validate the response message "Order and pet status updated successfully" ''' def test_patch_order_by_id(): - pass + create_endpoint = "/store/order" + create_payload = { + "pet_id": 2 + } + + create_response = api_helpers.post_api_data(create_endpoint, create_payload) + assert create_response.status_code == 201 + + + order_id = create_response.json()["id"] + + + patch_endpoint = f"/store/order/{order_id}" + patch_payload = { + "status": "sold" + } + + response = api_helpers.patch_api_data(patch_endpoint, patch_payload) + + assert response.status_code == 200 + body = response.json() + assert "Order and pet status updated successfully" in body["message"] + + + + + + + From 90303b0034dcdb59a150e1545d49a2a2d7d5ec16 Mon Sep 17 00:00:00 2001 From: Brad Evans Date: Fri, 24 Oct 2025 13:00:16 -0400 Subject: [PATCH 2/5] test: add reset logic and enable report.html sharing --- .gitignore | 2 +- report.html | 770 ++++++++++++++++++++++++++++++++++++++++++++++++++ test_store.py | 3 + 3 files changed, 774 insertions(+), 1 deletion(-) create mode 100644 report.html diff --git a/.gitignore b/.gitignore index 751d372..0b5d0f9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ __pycache__ test_scratch.py pet_scratch.py store_scratch.py -report.html +#report.html style.css \ No newline at end of file diff --git a/report.html b/report.html new file mode 100644 index 0000000..01f2837 --- /dev/null +++ b/report.html @@ -0,0 +1,770 @@ + + + + + report.html + + + +

report.html

+

Report generated on 24-Oct-2025 at 12:55:18 by pytest-html + v4.1.1

+
+

Environment

+
+
+ + + + + +
+
+

Summary

+
+
+

8 tests took 00:00:21.

+

(Un)check the boxes to filter the results.

+
+ +
+
+
+
+ + 0 Failed, + + 8 Passed, + + 0 Skipped, + + 0 Expected failures, + + 0 Unexpected passes, + + 0 Errors, + + 0 Reruns +
+
+  /  +
+
+
+
+
+
+
+
+ + + + + + + + + +
ResultTestDurationLinks
+ +
+
+ +
+ \ No newline at end of file diff --git a/test_store.py b/test_store.py index ec14106..5ea1c26 100644 --- a/test_store.py +++ b/test_store.py @@ -36,6 +36,9 @@ def test_patch_order_by_id(): body = response.json() assert "Order and pet status updated successfully" in body["message"] + reset_payload = {"status": "available"} + reset_response = api_helpers.patch_api_data(patch_endpoint, reset_payload) + From 3930e707e267b0fc33e283a974463293a14d59b9 Mon Sep 17 00:00:00 2001 From: Brad Evans Date: Fri, 24 Oct 2025 13:05:45 -0400 Subject: [PATCH 3/5] ci: add GitHub Actions workflow to run pytest and publish report --- .github/workflows/tests.yml | 34 ++++++++++++++++++++++++++++++++++ .gitignore | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..2a06027 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,34 @@ +name: Run Pytest and Publish Report + +on: + push: + branches: [ main ] + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install requests pytest pyhamcrest jsonschema pytest-html flask_restx flask + + - name: Run tests and generate report + run: pytest -v --html=report.html + + - name: Publish report to GitHub Pages + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_branch: gh-pages + publish_dir: . diff --git a/.gitignore b/.gitignore index 0b5d0f9..751d372 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ __pycache__ test_scratch.py pet_scratch.py store_scratch.py -#report.html +report.html style.css \ No newline at end of file From d6cf27c61c14baba4d95645b66c1a73889d40bbe Mon Sep 17 00:00:00 2001 From: Brad Evans Date: Fri, 24 Oct 2025 13:08:24 -0400 Subject: [PATCH 4/5] git commit -m "remove report.html from repo (ignored by git)" --- report.html | 770 ---------------------------------------------------- 1 file changed, 770 deletions(-) delete mode 100644 report.html diff --git a/report.html b/report.html deleted file mode 100644 index 01f2837..0000000 --- a/report.html +++ /dev/null @@ -1,770 +0,0 @@ - - - - - report.html - - - -

report.html

-

Report generated on 24-Oct-2025 at 12:55:18 by pytest-html - v4.1.1

-
-

Environment

-
-
- - - - - -
-
-

Summary

-
-
-

8 tests took 00:00:21.

-

(Un)check the boxes to filter the results.

-
- -
-
-
-
- - 0 Failed, - - 8 Passed, - - 0 Skipped, - - 0 Expected failures, - - 0 Unexpected passes, - - 0 Errors, - - 0 Reruns -
-
-  /  -
-
-
-
-
-
-
-
- - - - - - - - - -
ResultTestDurationLinks
- - - \ No newline at end of file From 2fc3585ea302367bca8ec7d782348ed28e2fd3e3 Mon Sep 17 00:00:00 2001 From: bradevansqa <103956857+bradevansqa@users.noreply.github.com> Date: Fri, 24 Oct 2025 13:28:52 -0400 Subject: [PATCH 5/5] Include Pytest report link in README Add link to Pytest report in README --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 339ce55..8c09a21 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +Pytest Report: +https://bradevansqa.github.io/pytest-api-example/report.html + # Sample API Test Using Pytest and SwaggerUI ## System Requirements @@ -47,4 +50,4 @@ pytest -v --html=report.html ### Tasks - [ ] Extend and fix the 3 tests from [test_pet.py](test_pet.py#1). There are TODO instructions for each test listed in the file - [ ] Create the PATCH test for [test_store.py](test_store.py#1). There are TODO instructions for test along with optional tasks -- [ ] Take note of any bugs you may have found \ No newline at end of file +- [ ] Take note of any bugs you may have found