Skip to content

feat(testing): add an httpx-style test client #635

Closed

Description

@uniqueg

FOCA's tests and the apps' tests use Flask's test tooling directly. In tests/ on dev:

Repo test_client test_request_context app_context app.app
FOCA 94 48 83 67
cloud-registry 8 26 53 26
proTES 19 12 29 40
trs-filer 1 20 79 5

On Connexion 3, app.app.test_client() bypasses the middleware (security, validation, CORS, errors), and without Flask it doesn't exist. Starlette's TestClient has the httpx API instead.

A scratch prototype (about 80 lines) ran the same 14 requests against Connexion 2.15.1 and Connexion 3.3.0 AsyncApp with one client API. It hid the differences in:

  • the JSON accessor (Flask: .json property; httpx: .json() method);
  • the body attribute (.data vs .content);
  • the query argument (query_string vs params);
  • the raw body argument (data vs content).

Do:

  • foca.testing.Client(app): httpx-style methods (get, post, put, patch, delete, options, request), with params, json, content, headers, follow_redirects. Responses have status_code, headers, content, text and json().
    • It is a context manager, so that the implementation in the ASGI release can run the app's lifespan.
    • In 0.22 it wraps Flask's test client. In the ASGI release it is Starlette's TestClient, which follows redirects by default (Flask's doesn't); foca.testing sets one default.
  • foca.testing.request_context(path="/", method="GET", headers=None, token_info=None): a context manager for unit tests of code that uses the accessors from feat: add request and claims accessors #634, without HTTP. In 0.22 it enters Flask's test_request_context and sets Connexion 2's context.
  • pytest fixtures, documented, e.g., foca_client built from a Foca instance.
  • Port FOCA's HTTP-level tests to the client. Unit tests that need request data use request_context.

Acceptance criteria

  • foca.testing is public, typed and documented (including how apps move from app.app.test_client(), app_context() and test_request_context()).
  • FOCA's tests have no app.app.test_client(); test_request_context is used only inside foca.testing.
  • Coverage stays at 100 %; the client's API is tested against the real app (JSON, bytes, headers, query parameters, redirects).

Decided

Prepares #188.

Activity

  1. added this to the v0.22.0 milestone on Nov 3, 2026
  2. added
    priority: medium
    status: blocked
    on Nov 3, 2026
  3. added
    type: feature
    workload: days
    on Nov 3, 2026
  4. added
    status: triage
    status: in progress
    and removed
    status: blocked
    status: triage
    on Nov 6, 2026
  5. removed
    status: in progress
    on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: featureworkload: days

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions