Repository navigation
Closed
Labels
priority: mediumMedium prioritytype: featureNew feature or requestworkload: daysLikely takes days to resolve
Milestone
Description
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:
.jsonproperty; httpx:.json()method); - the body attribute (
.datavs.content); - the query argument (
query_stringvsparams); - the raw body argument (
datavscontent).
Do:
foca.testing.Client(app): httpx-style methods (get,post,put,patch,delete,options,request), withparams,json,content,headers,follow_redirects. Responses havestatus_code,headers,content,textandjson().- 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.testingsets 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'stest_request_contextand sets Connexion 2's context.- pytest fixtures, documented, e.g.,
foca_clientbuilt from aFocainstance. - Port FOCA's HTTP-level tests to the client. Unit tests that need request data use
request_context.
Acceptance criteria
-
foca.testingis public, typed and documented (including how apps move fromapp.app.test_client(),app_context()andtest_request_context()). - FOCA's tests have no
app.app.test_client();test_request_contextis used only insidefoca.testing. - Coverage stays at 100 %; the client's API is tested against the real app (JSON, bytes, headers, query parameters, redirects).
Decided
- Names as proposed:
foca.testing.Clientandfoca.testing.request_context. - The test issuer (feat(testing): add pytest plugin and test issuer #630) works with this client.
Prepares #188.
Metadata
Metadata
Assignees
Labels
priority: mediumMedium prioritytype: featureNew feature or requestworkload: daysLikely takes days to resolve
Activity