Skip to content

Complete API test tasks: fix schema, build test infra, add coverage#209

Open
SinanIT wants to merge 1 commit intoautomationExamples:mainfrom
SinanIT:feature/sinank_complete_api_tests
Open

Complete API test tasks: fix schema, build test infra, add coverage#209
SinanIT wants to merge 1 commit intoautomationExamples:mainfrom
SinanIT:feature/sinank_complete_api_tests

Conversation

@SinanIT
Copy link
Copy Markdown

@SinanIT SinanIT commented Mar 19, 2026

What I did

Went through all three tasks. Fixed the schema bug, filled in the pet
tests, wrote the store PATCH test, and added some edge cases along
the way.

Changes

Schema (schemas.py)
The name field was typed as integer, changed it to string. Added order
and order_update_response schemas for the store test.

Test helpers (test_data.py)
Pulled endpoints, statuses, and expected messages into one place.
PetFactory generates unique pets with sequential IDs based on a
time offset, so tests never collide with each other even across runs.
ID ranges are separated so "nonexistent" IDs for 404 tests can't
accidentally match a created pet.

Shared fixtures (conftest.py)
create_pet fixture is shared across test files. Autouse logging
fixture so you can see which test is running. Also strips JAVA_HOME
from the HTML report metadata since it's not relevant.

Pet tests (test_pet.py) - 4 tests, 10 cases

  • test_pet_schema: creates its own pet, validates against schema
  • test_find_by_status_200: parameterized for all 3 statuses, each
    run creates a pet with that status first so we're not relying on
    whatever happens to be in the server. Checks status field and
    schema on every item
  • test_get_by_id_404: dynamic nonexistent IDs, checks 404 + message
  • test_find_by_status_400: invalid statuses like "unknown" and empty
    string, checks 400 + error message

Store tests (test_store.py) - 2 tests, 3 cases

  • test_patch_order_by_id: fixture creates a fresh pet + order per
    run. Parameterized for sold/available transitions. Validates
    response schema, message, and does a follow-up GET to confirm
    the pet status actually updated
  • test_patch_order_not_found: fake order ID, checks 404 + message

Config (pytest.ini)
Verbose output, auto HTML report, filtered pytest deprecation noise.

Bugs found

  1. schemas.py - name was integer instead of string (fixed)
  2. app.py:101 - f-string prefix missing on the findByStatus error
    message, {status} prints literally instead of the actual value
  3. app.py routing - negative IDs like /pets/-1 bypass the Flask
    int converter entirely, returns raw HTML 404 instead of JSON
image

- Fixed pet schema where 'name' was typed as integer instead of string,
  that was the root cause of test_pet_schema failing

- Created test_data.py to centralize endpoints, test constants, and a
  PetFactory that generates unique pets with sequential IDs. Keeps all
  the magic strings out of test files

- Added conftest.py with a shared create_pet fixture and logging so
  test runs are easy to trace. Also cleans up irrelevant metadata from
  the HTML report

- Every test creates its own data now, nothing depends on seed data or
  other tests. Ran into an issue where test_find_by_status_200 was
  silently passing on empty results for 'sold' so I added a guard for
  that

- Built the store PATCH test with a fixture that sets up a fresh pet
  and order each time. After patching I also GET the pet back to make
  sure the status actually changed, not just trusting the response

- Added a few edge case tests: invalid status on findByStatus (400)
  and patching a non-existent order (404)

- Configured pytest.ini for auto HTML reporting and filtered out the
  noisy deprecation warnings from pytest internals

- Found a couple bugs in app.py, noted in PR description"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants