Open vytas7 opened 3 years ago
Provide a global method in testing.helpers which creates a Request and Response object.
I think it could also be useful if we also allow setting the context with this function. Maybe by passing a dict that gets translated in the context object.
@CaselIT maybe it would be enough to document the context part?
One can operate on the created req
or resp
as usual, i.e.:
>>> req = falcon.testing.create_asgi_req(path='/things', method='PATCH')
>>> req.context.key = 'value'
>>> req.context
Context({'key': 'value'})
sure that works too, but it shouldn't be too hard to allow context to be passed as argument (unless **kw
is already sent to another mapping where context may be a key used by people)
I see, that might make sense. I don't think we should pipe **kw
there though, because that might be ambiguous with setting env/scope key-values. But we can add another mapping argument.
no, I just meant that it should be fine to add a context=None
there, unless we take **kw
and use it to set another mapping. If that's the case then this would be a backward incompatible change since people could be using context to pass data somewhere else.
If that's the case then best course of action is to either not have it or use another keyword that's more unlikely, like requext_context
or something
Ah, no, these functions are incomplete (cannot set body
, json
, etc) and lack examples, it is absolutely not a breaking change to add things there.
I started looking into this (during EuroPython sprints) 😄
New methods were introduced as part of https://github.com/falconry/falcon/issues/1506 that afford an alternative approach to testing by creating arbitrary req/resp/ws:
create_req
create_asgi_req
create_scope_ws
Write a paragraph on how to use these goodies. From https://github.com/falconry/falcon/issues/1506:
Also check if we want to recommend instantiating
Response
directly, or we want to provide a wrapper method for that too.(Requirements transplanted from https://github.com/falconry/falcon/issues/1506)
testing.helpers
which creates aRequest
andResponse
object.json
,body
, andstream
Content-Length
Content-Type
TestClient
which will utilize the global method but fill in some of theenvironment
details and utilize application specificRequest
andResponse
.