MCPcopy
hub / github.com/pallets/werkzeug / Client

Class Client

src/werkzeug/test.py:773–1200  ·  view source on GitHub ↗

Simulate sending requests to a WSGI application without running a WSGI or HTTP server. :param application: The WSGI application to make requests to. :param response_wrapper: A :class:`.Response` class to wrap response data with. Defaults to :class:`.TestResponse`. If it's not a

Source from the content-addressed store, hash-verified

771
772
773class Client:
774 """Simulate sending requests to a WSGI application without running a WSGI or HTTP
775 server.
776
777 :param application: The WSGI application to make requests to.
778 :param response_wrapper: A :class:`.Response` class to wrap response data with.
779 Defaults to :class:`.TestResponse`. If it's not a subclass of ``TestResponse``,
780 one will be created.
781 :param use_cookies: Persist cookies from ``Set-Cookie`` response headers to the
782 ``Cookie`` header in subsequent requests. Domain and path matching is supported,
783 but other cookie parameters are ignored.
784 :param allow_subdomain_redirects: Allow requests to follow redirects to subdomains.
785 Enable this if the application handles subdomains and redirects between them.
786
787 .. versionchanged:: 2.3
788 Simplify cookie implementation, support domain and path matching.
789
790 .. versionchanged:: 2.1
791 All data is available as properties on the returned response object. The
792 response cannot be returned as a tuple.
793
794 .. versionchanged:: 2.0
795 ``response_wrapper`` is always a subclass of :class:``TestResponse``.
796
797 .. versionchanged:: 0.5
798 Added the ``use_cookies`` parameter.
799 """
800
801 def __init__(
802 self,
803 application: WSGIApplication,
804 response_wrapper: type[Response] | None = None,
805 use_cookies: bool = True,
806 allow_subdomain_redirects: bool = False,
807 ) -> None:
808 self.application = application
809
810 if response_wrapper in {None, Response}:
811 response_wrapper = TestResponse
812 elif response_wrapper is not None and not issubclass(
813 response_wrapper, TestResponse
814 ):
815 response_wrapper = type(
816 "WrapperTestResponse",
817 (TestResponse, response_wrapper),
818 {},
819 )
820
821 self.response_wrapper = t.cast(type["TestResponse"], response_wrapper)
822
823 if use_cookies:
824 self._cookies: dict[tuple[str, str, str], Cookie] | None = {}
825 else:
826 self._cookies = None
827
828 self.allow_subdomain_redirects = allow_subdomain_redirects
829
830 def get_cookie(

Callers 15

test_basicMethod · 0.90
test_ie7_unc_pathMethod · 0.90
test_cookie_forgingFunction · 0.90
test_set_cookie_appFunction · 0.90
test_no_initial_cookieFunction · 0.90
test_resent_cookieFunction · 0.90
test_disable_cookiesFunction · 0.90
test_cookie_default_pathFunction · 0.90
test_follow_redirectFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_basicMethod · 0.72
test_ie7_unc_pathMethod · 0.72
test_cookie_forgingFunction · 0.72
test_set_cookie_appFunction · 0.72
test_no_initial_cookieFunction · 0.72
test_resent_cookieFunction · 0.72
test_disable_cookiesFunction · 0.72
test_cookie_default_pathFunction · 0.72
test_follow_redirectFunction · 0.72