当前位置: 首页>>代码示例>>Python>>正文


Python test.Client方法代码示例

本文整理汇总了Python中werkzeug.test.Client方法的典型用法代码示例。如果您正苦于以下问题:Python test.Client方法的具体用法?Python test.Client怎么用?Python test.Client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在werkzeug.test的用法示例。


在下文中一共展示了test.Client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_basic

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def test_basic(sentry_init, crashing_app, capture_events):
    sentry_init(send_default_pii=True)
    app = SentryWsgiMiddleware(crashing_app)
    client = Client(app)
    events = capture_events()

    with pytest.raises(ZeroDivisionError):
        client.get("/")

    (event,) = events

    assert event["transaction"] == "generic WSGI request"

    assert event["request"] == {
        "env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"},
        "headers": {"Host": "localhost"},
        "method": "GET",
        "query_string": "",
        "url": "http://localhost/",
    } 
开发者ID:getsentry,项目名称:sentry-python,代码行数:22,代码来源:test_wsgi.py

示例2: test_keyboard_interrupt_is_captured

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def test_keyboard_interrupt_is_captured(sentry_init, capture_events):
    sentry_init(send_default_pii=True)
    iterable = ExitingIterable(lambda: KeyboardInterrupt())
    app = SentryWsgiMiddleware(IterableApp(iterable))
    client = Client(app)
    events = capture_events()

    with pytest.raises(KeyboardInterrupt):
        client.get("/")

    (event,) = events

    assert "exception" in event
    exc = event["exception"]["values"][-1]
    assert exc["type"] == "KeyboardInterrupt"
    assert exc["value"] == ""
    assert event["level"] == "error" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:19,代码来源:test_wsgi.py

示例3: test_flow

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def test_flow(self, satosa_config_dict):
        """
        Performs the test.
        """
        test_client = Client(make_app(SATOSAConfig(satosa_config_dict)), BaseResponse)

        # Make request to frontend
        resp = test_client.get('/{}/{}/request'.format("backend", "frontend"))
        assert resp.status == '200 OK'
        headers = dict(resp.headers)
        assert headers["Set-Cookie"]

        # Fake response coming in to backend
        resp = test_client.get('/{}/response'.format("backend"), headers=[("Cookie", headers["Set-Cookie"])])
        assert resp.status == '200 OK'
        assert resp.data.decode('utf-8') == "Auth response received, passed to test frontend" 
开发者ID:IdentityPython,项目名称:SATOSA,代码行数:18,代码来源:test_wsgi_flow.py

示例4: test_full_path

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def test_full_path(self):
        trace_id = trace_sdk.generate_trace_id()
        # We need to use the Werkzeug test app because
        # The headers are injected at the wsgi layer.
        # The flask test app will not include these, and
        # result in the values not propagated.
        client = Client(self.app.wsgi_app, BaseResponse)
        # emulate b3 headers
        client.get(
            "/",
            headers={
                "traceparent": "00-{:032x}-{:016x}-{:02x}".format(
                    trace_id,
                    trace_sdk.generate_span_id(),
                    trace.TraceFlags.SAMPLED,
                )
            },
        )
        # assert the http request header was propagated through.
        prepared_request = self.send.call_args[0][1]
        headers = prepared_request.headers
        self.assertRegex(
            headers["traceparent"],
            r"00-{:032x}-[0-9a-f]{{16}}-01".format(trace_id),
        ) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:27,代码来源:test_flask_example.py

示例5: test_uninstrument

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def test_uninstrument(self):
        # pylint: disable=access-member-before-definition
        resp = self.client.get("/hello/123")
        self.assertEqual(200, resp.status_code)
        self.assertEqual([b"Hello: 123"], list(resp.response))
        span_list = self.memory_exporter.get_finished_spans()
        self.assertEqual(len(span_list), 1)

        FlaskInstrumentor().uninstrument()
        self.app = flask.Flask(__name__)

        self.app.route("/hello/<int:helloid>")(self._hello_endpoint)
        # pylint: disable=attribute-defined-outside-init
        self.client = Client(self.app, BaseResponse)

        resp = self.client.get("/hello/123")
        self.assertEqual(200, resp.status_code)
        self.assertEqual([b"Hello: 123"], list(resp.response))
        span_list = self.memory_exporter.get_finished_spans()
        self.assertEqual(len(span_list), 1) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:22,代码来源:test_automatic.py

示例6: _common_initialization

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def _common_initialization(self, config):
        # pylint: disable=unused-argument
        def excluded_endpoint(request):
            return Response("excluded")

        # pylint: disable=unused-argument
        def excluded2_endpoint(request):
            return Response("excluded2")

        config.add_route("hello", "/hello/{helloid}")
        config.add_view(self._hello_endpoint, route_name="hello")
        config.add_route("excluded_arg", "/excluded/{helloid}")
        config.add_view(self._hello_endpoint, route_name="excluded_arg")
        config.add_route("excluded", "/excluded_noarg")
        config.add_view(excluded_endpoint, route_name="excluded")
        config.add_route("excluded2", "/excluded_noarg2")
        config.add_view(excluded2_endpoint, route_name="excluded2")

        # pylint: disable=attribute-defined-outside-init
        self.client = Client(config.make_wsgi_app(), BaseResponse) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:22,代码来源:pyramid_base_test.py

示例7: make_request_and_maybe_assert_warn

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def make_request_and_maybe_assert_warn(
        self, headers, expected_warn_substr,
    ):
        @werkzeug.Request.application
        def _simple_app(req):
            return werkzeug.Response("OK", headers=headers)

        app = security_validator.SecurityValidatorMiddleware(_simple_app)
        server = werkzeug_test.Client(app, BaseResponse)

        with mock.patch.object(logger, "warning") as mock_warn:
            server.get("")

        if expected_warn_substr is None:
            mock_warn.assert_not_called()
        else:
            mock_warn.assert_called_with(_WARN_PREFIX + expected_warn_substr) 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:19,代码来源:security_validator_test.py

示例8: test_public_errors_serve_response

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def test_public_errors_serve_response(self):
        @application._handling_errors
        @wrappers.Request.application
        def app(request):
            raise errors.NotFoundError("no scalar data for run=foo, tag=bar")

        server = werkzeug_test.Client(app, wrappers.BaseResponse)
        response = server.get("/")
        self.assertEqual(
            response.get_data(),
            b"Not found: no scalar data for run=foo, tag=bar",
        )
        self.assertEqual(response.status_code, 404)
        self.assertStartsWith(
            response.headers.get("Content-Type"), "text/plain"
        ) 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:18,代码来源:application_test.py

示例9: setUp

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def setUp(self):
        plugins = [
            FakePlugin(plugin_name="foo"),
            FakePlugin(
                plugin_name="bar",
                is_active_value=False,
                element_name_value="tf-bar-dashboard",
            ),
            FakePlugin(
                plugin_name="baz",
                routes_mapping={"/esmodule": lambda req: None,},
                es_module_path_value="/esmodule",
            ),
        ]
        app = application.TensorBoardWSGI(plugins, path_prefix=self.path_prefix)
        self.server = werkzeug_test.Client(app, wrappers.BaseResponse) 
开发者ID:tensorflow,项目名称:tensorboard,代码行数:18,代码来源:application_test.py

示例10: setUp

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def setUp(self):
        # pylint: disable=g-import-not-at-top
        # Pre-import modules to patch them in advance.
        from google.appengine.ext.vmruntime import vmconfig

        # Instantiate an app with a simple fake configuration.
        with patch.object(wsgi_config, 'get_module_config_filename'):
            with patch.object(wsgi_config,
                              'get_module_config',
                              return_value=FAKE_APPINFO_EXTERNAL):
                with patch.object(vmconfig,
                                  'BuildVmAppengineEnvConfig',
                                  return_value=FAKE_APPENGINE_CONFIG):
                    from vmruntime import wsgi
                    self.app = wsgi.meta_app
        self.client = test.Client(self.app, wrappers.Response)
        # Separate client for concurrent tests.
        self.spare_client = test.Client(self.app, wrappers.Response)

        # Clear the global event flags (only used in concurrency tests).
        concurrent_request_is_started.clear()
        concurrent_request_should_proceed.clear() 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:24,代码来源:wsgi_test.py

示例11: from_wsgi

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def from_wsgi(
    schema_path: str,
    app: Any,
    base_url: Optional[str] = None,
    method: Optional[Filter] = None,
    endpoint: Optional[Filter] = None,
    tag: Optional[Filter] = None,
    operation_id: Optional[Filter] = None,
    validate_schema: bool = True,
    **kwargs: Any,
) -> BaseOpenAPISchema:
    kwargs.setdefault("headers", {}).setdefault("User-Agent", USER_AGENT)
    client = Client(app, WSGIResponse)
    response = client.get(schema_path, **kwargs)
    # Raising exception to provide unified behavior
    # E.g. it will be handled in CLI - a proper error message will be shown
    if 400 <= response.status_code < 600:
        raise HTTPError(response=response, url=schema_path)
    return from_file(
        response.data,
        location=schema_path,
        base_url=base_url,
        method=method,
        endpoint=endpoint,
        tag=tag,
        operation_id=operation_id,
        app=app,
        validate_schema=validate_schema,
    ) 
开发者ID:kiwicom,项目名称:schemathesis,代码行数:31,代码来源:loaders.py

示例12: client

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def client():
    return Client(application) 
开发者ID:getsentry,项目名称:sentry-python,代码行数:4,代码来源:test_basic.py

示例13: get_client

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def get_client(pyramid_config):
    def inner():
        return Client(pyramid_config.make_wsgi_app())

    return inner 
开发者ID:getsentry,项目名称:sentry-python,代码行数:7,代码来源:test_pyramid.py

示例14: get_client

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def get_client(app):
    def inner():
        return Client(app)

    return inner 
开发者ID:getsentry,项目名称:sentry-python,代码行数:7,代码来源:test_trytond.py

示例15: test_systemexit_zero_is_ignored

# 需要导入模块: from werkzeug import test [as 别名]
# 或者: from werkzeug.test import Client [as 别名]
def test_systemexit_zero_is_ignored(sentry_init, capture_events, request):
    zero_code = request.param
    sentry_init(send_default_pii=True)
    iterable = ExitingIterable(lambda: SystemExit(zero_code))
    app = SentryWsgiMiddleware(IterableApp(iterable))
    client = Client(app)
    events = capture_events()

    with pytest.raises(SystemExit):
        client.get("/")

    assert len(events) == 0 
开发者ID:getsentry,项目名称:sentry-python,代码行数:14,代码来源:test_wsgi.py


注:本文中的werkzeug.test.Client方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。