You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The test client can currently return a number of different values. The default is to return a tuple of (app_iter, status_code, headers) representing the data passed to the WSGI start_response function. If you pass as_tuple=True, you get (environ, response), where response is that tuple, so (environ, (app_iter, status_code, header), representing the WSGI request and response. But if you pass response_wrapper, the response tuple in both those cases becomes a Response class.
For most tests it's easier to assert properties of a Response object, so most code ends up importing and passing Response. Even then, it misses out on useful test information, such as redirect history (#763), and the request is still only accessible as a separate environ dict.
Client.open should always return a Response object, with the following behavior. The Request and Response wrappers on their own add essentially no overhead, they don't do anything with the data passed to them until properties are accessed.
To support test-related data and methods, create a new TestResponse subclass. If no response_wrapper is passed, or Response is passed as the wrapper, use TestResponse instead.
To continue to support passing a custom response_wrapper, if the passed class is not a subclass of TestResponse, make a new class with both the custom class and TestResponse as bases.
To continue to support tests that expected a tuple (app_iter, status_code, headers = client.get(...), or status_code = client.get(...)), the class can implement __iter__ and __getitem__, along with deprecation warnings.
Store the environ that produced the response by wrapping it in Request and storing it in a TestResponse.request attribute. Deprecate the as_tuple parameter.
The text was updated successfully, but these errors were encountered: