Skip to content

test: cover client.py JWT/JWKS and cli.py formatters - #51

Merged
mrebbert merged 1 commit into
mainfrom
test/coverage-sweep
Oct 16, 2026
Merged

mrebbert merged 1 commit into
mainfrom
test/coverage-sweep

Conversation

@mrebbert

Copy link
Copy Markdown
Owner

Summary

Schließt die zwei Coverage-Lücken, die am dichtesten am 95-Prozent-Gate lagen.

client.py: 90 → 100 Prozent

Drei neue Klassen in `tests/test_client.py`:

  • TestRequestEmptyBody — `_request` liefert `None` wenn der Server mit `Content-Length: 0` oder leerem Body antwortet. Beide Zweige (vorher 278, 281 missing) sind jetzt abgedeckt.
  • TestGetJwks — `_get_jwks` holt den JWK-Set bei Erstaufruf und cached ihn danach. `PyJWKSet.from_json` wird genau einmal aufgerufen; der zweite `_get_jwks`-Call läuft ohne HTTP-Verkehr durch (aioresponses-Context endet nach dem ersten Hit und würde einen zweiten Zugriff hart failen).
  • TestDecodeToken — `_decode_token` wählt die JWK mit passender `kid` aus und ruft `jwt.decode` mit dem richtigen Key, Audience und Algorithmus auf. Zweiter Test weist nach, dass eine fehlende Übereinstimmung zu `AuthenticationError("No matching JWK for token 'kid'")` führt.

cli.py: 90 → 91 Prozent

  • TestFormatHelpers — `_kwh`, `_w`, `_pct` werden direkt gegen beide Zweige (populierter Wert vs. `None`) sowie Vorzeichenlogik getestet. Zeile 1133 (`_w`-Formatter) ist jetzt abgedeckt.
  • TestMainDispatch — `main()` schließt beim Erfolg wie beim Exception-Pfad jeden Eintrag aus `Client._live`. Deckt den `finally`-Zweig in Zeile 1435 ab.

Gesamt

Datei Vorher Nachher
`onekommafive/client.py` 90 % 100 %
`onekommafive/cli.py` 90 % 91 %
Projekt-Gesamt 95.11 % 96.14 %

Puffer über dem 95-Prozent-Gate wächst von 0.11 auf 1.14 Prozentpunkte.

Test plan

  • `uv run pytest` → 496 passed, 34 skipped
  • `uv run pytest --cov --cov-fail-under=95` → grün, 96.14 %
  • `uv run mypy --strict onekommafive` → sauber
  • `uv run pre-commit run --all-files` → sauber
  • Keine Secrets, keine credentials in den neuen Tests (nur `FAKE_ACCESS_TOKEN` aus den bestehenden Fixtures)

🤖 Generated with Claude Code

https://claude.ai/code/session_01RgkYaQACLxezeceA1hrXQs

- test_client.py gets three new test classes: TestRequestEmptyBody for
  _request's content-length=0 and empty-body return-None branches,
  TestGetJwks for the one-shot fetch + in-memory cache, TestDecodeToken
  for the matching-kid happy path plus the AuthenticationError raised
  when no JWK matches the token's kid.
- test_cli_helpers.py gets TestFormatHelpers for the _kwh / _w / _pct
  branches that every print path uses, and TestMainDispatch asserting
  that main() closes any live sync-client in finally on both success
  and exception.

Coverage: onekommafive/client.py 90% -> 100%, onekommafive/cli.py
90% -> 91%, project total 95.11% -> 96.14%.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RgkYaQACLxezeceA1hrXQs
@mrebbert
mrebbert merged commit 63fb116 into main Oct 16, 2026
8 checks passed
@mrebbert
mrebbert deleted the test/coverage-sweep branch October 16, 2026 04:51
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