U )._'@sdZddlZddlmZddlZddlmZddlmZddl m Z ddl m Z dd l mZdd lmZGd d d ejjZd dZGdddeZGdddeZdS)z flask.testing ~~~~~~~~~~~~~ Implements test support helpers. This module is lazily imported and usually not used in production environments. :copyright: 2010 Pallets :license: BSD-3-Clause N)contextmanager) CliRunner)Client) url_parse)_request_ctx_stack) ScriptInfo)dumpscs*eZdZdZdfdd ZddZZS) EnvironBuilderaAn :class:`~werkzeug.test.EnvironBuilder`, that takes defaults from the application. :param app: The Flask application to configure the environment from. :param path: URL path being requested. :param base_url: Base URL where the app is being served, which ``path`` is relative to. If not given, built from :data:`PREFERRED_URL_SCHEME`, ``subdomain``, :data:`SERVER_NAME`, and :data:`APPLICATION_ROOT`. :param subdomain: Subdomain name to append to :data:`SERVER_NAME`. :param url_scheme: Scheme to use instead of :data:`PREFERRED_URL_SCHEME`. :param json: If given, this is serialized as JSON and passed as ``data``. Also defaults ``content_type`` to ``application/json``. :param args: other positional arguments passed to :class:`~werkzeug.test.EnvironBuilder`. :param kwargs: other keyword arguments passed to :class:`~werkzeug.test.EnvironBuilder`. /Nc s|s |s |r(|dk t|p|ks(td|dkr|jdp>d}|jd} |rZd||}|dkrl|jd}t|} dj| jp|| jp|| dd }| j }| j rt | j t rd nd } || | j 7}||_ tt|j||f||dS) Nz8Cannot pass "subdomain" or "url_scheme" with "base_url".Z SERVER_NAME localhostZAPPLICATION_ROOTz{0}.{1}ZPREFERRED_URL_SCHEMEz{scheme}://{netloc}/{path}r )schemenetlocpath??)boolAssertionErrorconfiggetformatrr rlstriprquery isinstancebytesappsuperr __init__) selfrrbase_urlZ subdomain url_schemeargskwargsZ http_hostZapp_rooturlsep __class__C:\Users\Miouzora\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\flask/testing.pyr/s6    zEnvironBuilder.__init__cKs|d|jt|f|S)zSerialize ``obj`` to a JSON-formatted string. The serialization will be configured according to the config associated with this EnvironBuilder's ``app``. r) setdefaultr json_dumps)robjr"r'r'r(r*XszEnvironBuilder.json_dumps)r NNN)__name__ __module__ __qualname____doc__rr* __classcell__r'r'r%r(r s)r cOsttdt||S)zCreate a :class:`flask.testing.EnvironBuilder`. .. deprecated: 1.1 Will be removed in 2.0. Construct ``flask.testing.EnvironBuilder`` directly instead. z"make_test_environ_builder()" is deprecated and will be removed in 2.0. Construct "flask.testing.EnvironBuilder" directly instead.)warningswarnDeprecationWarningr )r!r"r'r'r(make_test_environ_builderbs r4csHeZdZdZdZfddZeddZddZd d Z d d Z Z S) FlaskClientaDWorks like a regular Werkzeug test client but has some knowledge about how Flask works to defer the cleanup of the request context stack to the end of a ``with`` body when used in a ``with`` statement. For general information about how to use this class refer to :class:`werkzeug.test.Client`. .. versionchanged:: 0.12 `app.test_client()` includes preset default environment, which can be set after instantiation of the `app.test_client()` object in `client.environ_base`. Basic usage is outlined in the :ref:`testing` chapter. Fcs(tt|j||ddtjd|_dS)Nz 127.0.0.1z werkzeug/)Z REMOTE_ADDRZHTTP_USER_AGENT)rr5rwerkzeug __version__ environ_base)rr!r"r%r'r(rszFlaskClient.__init__c os|jdkrtd|j}|di}|j|tj}|j||}|j}| ||j }|dkrhtdt |z |VW5t X| } ||s|||| | |j j} |j|j j| W5QRXdS)aWhen used in combination with a ``with`` statement this opens a session transaction. This can be used to modify the session that the test client uses. Once the ``with`` block is left the session is stored back. :: with client.session_transaction() as session: session['value'] = 42 Internally this is implemented by going through a temporary test request context and since session handling could depend on request variables this function accepts the same arguments as :meth:`~flask.Flask.test_request_context` which are directly passed through. Nz:Session transactions only make sense with cookies enabled.environ_overridesz?Session backend did not open a session. Check the configuration)Z cookie_jar RuntimeError applicationr)Z inject_wsgirtopZtest_request_contextsession_interfaceZ open_sessionrequestpushpopresponse_classZis_null_sessionZ save_sessionZget_wsgi_headersenvironZ extract_wsgi) rr!r"rr9Z outer_reqctxcr=sessrespheadersr'r'r(session_transactions0       zFlaskClient.session_transactioncOs|dd}|dd}|dd}|st|dkrt|dtjjtfr|j}t|dtjjrz| |d n| |d|j |d<nJ|j | did<| d |jt|j f||}z | }W5|Xtj|||||d S) Nas_tupleFbufferedfollow_redirectsrrzflask._preserve_contextr9r8)rHrIrJ)r@lenrr6testr dictr8copyupdateZ get_environpreserve_contextr)r;closeropen)rr!r"rHrIrJrBZbuilderr'r'r(rRs<         zFlaskClient.opencCs|jrtdd|_|S)NzCannot nest client invocationsT)rPr:rr'r'r( __enter__szFlaskClient.__enter__cCs,d|_tj}|dk r(|jr(|qq(qdS)NF)rPrr<Z preservedr@)rexc_type exc_valuetbr<r'r'r(__exit__s  zFlaskClient.__exit__) r,r-r.r/rPrrrGrRrTrXr0r'r'r%r(r5ss  4&r5cs.eZdZdZfddZdfdd ZZS)FlaskCliRunnerzA :class:`~click.testing.CliRunner` for testing a Flask app's CLI commands. Typically created using :meth:`~flask.Flask.test_cli_runner`. See :ref:`testing-cli`. c s||_tt|jf|dSN)rrrYr)rrr"r%r'r(rszFlaskCliRunner.__init__Nc sD|dkrjj}d|kr.tfddd|d<ttj||f|S)acInvokes a CLI command in an isolated environment. See :meth:`CliRunner.invoke ` for full method documentation. See :ref:`testing-cli` for examples. If the ``obj`` argument is not given, passes an instance of :class:`~flask.cli.ScriptInfo` that knows how to load the Flask app being tested. :param cli: Command object to invoke. Default is the app's :attr:`~flask.app.Flask.cli` group. :param args: List of strings to invoke the command with. :return: a :class:`~click.testing.Result` object. Nr+csjSrZ)rr'rSr'r(z'FlaskCliRunner.invoke..)Z create_app)rclirrrYinvoke)rr]r!r"r%rSr(r^s zFlaskCliRunner.invoke)NN)r,r-r.r/rr^r0r'r'r%r(rYs rY)r/r1 contextlibrZ werkzeug.testr6Z click.testingrrZ werkzeug.urlsrrr]rjsonr r*rLr r4r5rYr'r'r'r(s        I