class documentation

class TestResponse(Response): (source)

View In Hierarchy

:class:`~werkzeug.wrappers.Response` subclass that provides extra information about requests made with the test :class:`Client`. Test client requests will always return an instance of this class. If a custom response class is passed to the client, it is subclassed along with this to support test information. If the test request included large files, or if the application is serving a file, call :meth:`close` to close any open files and prevent Python showing a ``ResourceWarning``. .. versionchanged:: 2.2 Set the ``default_mimetype`` to None to prevent a mimetype being assumed if missing. .. versionchanged:: 2.1 Removed deprecated behavior for treating the response instance as a tuple. .. versionadded:: 2.0 Test client methods always return instances of this class.

Method __init__ Undocumented
Class Variable __test__ Undocumented
Class Variable default_mimetype Undocumented
Instance Variable history A list of intermediate responses. Populated when the test request is made with ``follow_redirects`` enabled.
Instance Variable request A request object with the environ used to make the request that resulted in this response.
Property text The response data as text. A shortcut for ``response.get_data(as_text=True)``.
Instance Variable _compat_tuple Undocumented

Inherited from Response:

Class Method force_type Enforce that the WSGI response is a response object of the current type. Werkzeug will use the :class:`Response` internally in many situations like the exceptions. If you call :meth:`get_response` on an exception you will get back a regular :class:`Response` object, even if you are using a custom subclass.
Class Method from_app Create a new response object from an application output. This works best if you pass it an application that returns a generator all the time. Sometimes applications may use the `write()` callable returned by the `start_response` function...
Method __call__ Process this response as WSGI application.
Method __enter__ Undocumented
Method __exit__ Undocumented
Method __repr__ Undocumented
Method add_etag Add an etag for the current response if there is none yet.
Method calculate_content_length Returns the content length if available or `None` otherwise.
Method call_on_close Adds a function to the internal list of functions that should be called as part of closing down the response. Since 0.7 this function also returns the function that was passed so that this can be used as a decorator.
Method close Close the wrapped response if possible. You can also use the object in a with statement which will automatically close it.
Method freeze Make the response object ready to be pickled. Does the following:
Method get_app_iter Returns the application iterator for the given environ. Depending on the request method and the current status code the return value might be an empty response rather than the one from the response.
Method get_data The string representation of the response body. Whenever you call this property the response iterable is encoded and flattened. This can lead to unwanted behavior if you stream big data.
Method get_json Parse :attr:`data` as JSON. Useful during testing.
Method get_wsgi_headers This is automatically called right before the response is started and returns headers modified for the given environment. It returns a copy of the headers from the response with some modifications applied if necessary.
Method get_wsgi_response Returns the final WSGI response as tuple. The first item in the tuple is the application iterator, the second the status and the third the list of headers. The response returned is created specially for the given environment...
Method iter_encoded Iter the response encoded with the encoding of the response. If the response object is invoked as WSGI application the return value of this method is used as application iterator unless :attr:`direct_passthrough` was activated.
Method make_conditional Make the response conditional to the request. This method works best if an etag was defined for the response already. The `add_etag` method can be used to do that. If called without etag just the date header is set.
Method make_sequence Converts the response iterator in a list. By default this happens automatically if required. If `implicit_sequence_conversion` is disabled, this method is not automatically called and some properties might raise exceptions...
Method set_data Sets a new string as response. The value must be a string or bytes. If a string is set it's encoded to the charset of the response (utf-8 by default).
Class Variable autocorrect_location_header Undocumented
Class Variable automatically_set_content_length Undocumented
Class Variable data Undocumented
Class Variable implicit_sequence_conversion Undocumented
Instance Variable content_range The ``Content-Range`` header as a :class:`~werkzeug.datastructures.ContentRange` object. Available even if the header is not set.
Instance Variable direct_passthrough Undocumented
Instance Variable response Undocumented
Instance Variable status_code The HTTP status code as a number.
Property is_sequence If the iterator is buffered, this property will be `True`. A response object will consider an iterator to be buffered if the response attribute is a list or tuple.
Property is_streamed If the response is streamed (the response is not an iterable with a length information) this property is `True`. In this case streamed means that there is no information about the number of iterations...
Property json The parsed JSON data if :attr:`mimetype` indicates JSON (:mimetype:`application/json`, see :attr:`is_json`).
Property stream The response iterable as write-only stream.
Method _ensure_sequence This method can be called by methods that need a sequence. If `mutable` is true, it will also ensure that the response sequence is a standard Python list.
Method _is_range_request_processable Return ``True`` if `Range` header is present and if underlying resource is considered unchanged when compared with `If-Range` header.
Method _process_range_request Handle Range Request related headers (RFC7233). If `Accept-Ranges` header is valid, and Range Request is processable, we set the headers as described by the RFC, and wrap the underlying response in a RangeWrapper.
Method _wrap_range_response Wrap existing Response in case of Range Request context.
Instance Variable _on_close Undocumented

Inherited from Response (via Response):

Method access_control_allow_credentials.setter Undocumented
Method content_range.setter Undocumented
Method content_security_policy.setter Undocumented
Method content_security_policy_report_only.setter Undocumented
Method delete_cookie Delete a cookie. Fails silently if key doesn't exist.
Method get_etag Return a tuple in the form ``(etag, is_weak)``. If there is no ETag the return value is ``(None, None)``.
Method mimetype.setter Undocumented
Method retry_after.setter Undocumented
Method set_cookie Sets a cookie.
Method set_etag Set the etag, and override the old one if there was one.
Method status.setter Undocumented
Method status_code.setter Undocumented
Class Variable accept_ranges Undocumented
Class Variable access_control_allow_headers Undocumented
Class Variable access_control_allow_methods Undocumented
Class Variable access_control_allow_origin Undocumented
Class Variable access_control_expose_headers Undocumented
Class Variable access_control_max_age Undocumented
Class Variable age Undocumented
Class Variable allow Undocumented
Class Variable charset Undocumented
Class Variable content_encoding Undocumented
Class Variable content_language Undocumented
Class Variable content_length Undocumented
Class Variable content_location Undocumented
Class Variable content_md5 Undocumented
Class Variable content_type Undocumented
Class Variable cross_origin_embedder_policy Undocumented
Class Variable cross_origin_opener_policy Undocumented
Class Variable date Undocumented
Class Variable default_status Undocumented
Class Variable expires Undocumented
Class Variable last_modified Undocumented
Class Variable location Undocumented
Class Variable max_cookie_size Undocumented
Class Variable vary Undocumented
Instance Variable headers Undocumented
Property access_control_allow_credentials Whether credentials can be shared by the browser to JavaScript code. As part of the preflight request it indicates whether credentials can be used on the cross origin request.
Property cache_control The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.
Property content_security_policy The ``Content-Security-Policy`` header as a :class:`~werkzeug.datastructures.ContentSecurityPolicy` object. Available even if the header is not set.
Property content_security_policy_report_only The ``Content-Security-policy-report-only`` header as a :class:`~werkzeug.datastructures.ContentSecurityPolicy` object. Available even if the header is not set.
Property is_json Check if the mimetype indicates JSON data, either :mimetype:`application/json` or :mimetype:`application/*+json`.
Property mimetype The mimetype (content type without charset etc.)
Property mimetype_params The mimetype parameters as dict. For example if the content type is ``text/html; charset=utf-8`` the params would be ``{'charset': 'utf-8'}``.
Property retry_after The Retry-After response-header field can be used with a 503 (Service Unavailable) response to indicate how long the service is expected to be unavailable to the requesting client.
Property status The HTTP status code as a string.
Property www_authenticate The ``WWW-Authenticate`` header in a parsed form.
Method _clean_status Undocumented
Instance Variable _status Undocumented
Instance Variable _status_code Undocumented
def __init__(self, response: t.Iterable[bytes], status: str, headers: Headers, request: Request, history: t.Tuple[TestResponse] = (), **kwargs: t.Any): (source)
__test__: bool = (source)

Undocumented

A list of intermediate responses. Populated when the test request is made with ``follow_redirects`` enabled.

A request object with the environ used to make the request that resulted in this response.

The response data as text. A shortcut for ``response.get_data(as_text=True)``. .. versionadded:: 2.1

_compat_tuple = (source)

Undocumented