Skip to content

Add behavior tests for the health and hello endpoints - #1

Merged
murops merged 1 commit into
mainfrom
test/behavior-coverage
Oct 23, 2026
Merged

murops merged 1 commit into
mainfrom
test/behavior-coverage

Conversation

@murops

@murops murops commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

What changes

Adds 31 tests to tests/test_main.py (4 → 35). No changes to app/, dependencies or CI.

Line coverage of app/main.py was already 100%, but most behavior had no assertions. The new tests pin down:

  • /healthz: response body is {"status": "ok"}.
  • /hello: valid names (parametrized: 1 and 64 characters, empty, accents, Japanese, emoji, special characters, <script>); the 64-character limit is counted in characters, not bytes; 422 details (loc, type == "string_too_long"); unknown query params are ignored; with a repeated name, the last value wins.
  • Routing: 404 for unknown paths, 307 redirect for /healthz/, 405 with an Allow: GET header for other methods.
  • Logging middleware (caplog): one line per request in the GET /hello 200 <ms>ms format, no query string in the log, 4xx statuses logged, /healthz not logged, timing taken from perf_counter.

Why

Coverage alone didn't protect the API's contract: a change to the length limit, the error format or the logging middleware would still pass the old tests.

How to test

uv run pytest

35 passed locally, 100% line coverage on app/main.py; ruff check and ruff format --check are clean.

🤖 Generated with Claude Code

Line coverage was already 100%, but most behavior had no assertions.
The new tests cover:

- response bodies, the 64-character limit (counted in characters, not
  bytes) and unicode/emoji/special-character names
- 422 error details, unknown and repeated query parameters
- 404, 405 with the Allow header, and the trailing-slash redirect
- the logging middleware: format, no query string, /healthz skipped,
  timing taken from perf_counter

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

@murops
murops merged commit 7d6cf15 into main Oct 23, 2026
5 checks passed
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.

1 participant