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


Python handlers.http方法代码示例

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


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

示例1: sentry_stub

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def sentry_stub(self, container_factory, sentry_dsn, tracker):
        """ Start a container to imitate a sentry server
        """

        class SentryStub(object):
            name = "sentry"

            @http('POST', "/api/1/store/")
            def report(self, request):
                tracker(request.get_data())
                return 200, "OK"

        address = parse.urlparse(sentry_dsn).netloc.split("@")[-1]
        config = {
            'WEB_SERVER_ADDRESS': address
        }

        container = container_factory(SentryStub, config)
        container.start()

        return container 
开发者ID:nameko,项目名称:nameko-sentry,代码行数:23,代码来源:test_nameko_sentry.py

示例2: config

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def config(rabbit_config):
    config = rabbit_config.copy()
    config.update({
        'SENTRY': {
            'DSN': 'http://user:pass@localhost:9000/1',
            'CLIENT_CONFIG': {
                'site': 'site name'
            }
        }
    })
    return config 
开发者ID:nameko,项目名称:nameko-sentry,代码行数:13,代码来源:test_nameko_sentry.py

示例3: test_normal_http_entrypoint

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def test_normal_http_entrypoint(
        self, container_factory, config, web_session
    ):
        class Service(object):
            name = "service"

            sentry = SentryReporter()

            @http('GET', '/resource')
            def resource(self, request):
                raise CustomException()

        container = container_factory(Service, config)
        container.start()

        with entrypoint_waiter(container, 'resource'):
            web_session.get('/resource')

        sentry = get_extension(container, SentryReporter)

        assert sentry.client.send.call_count == 1
        _, kwargs = sentry.client.send.call_args

        expected_http = {
            'url': ANY,
            'query_string': "",
            'method': 'GET',
            'data': {},
            'headers': ANY,
            'env': ANY
        }
        assert kwargs['request'] == expected_http 
开发者ID:nameko,项目名称:nameko-sentry,代码行数:34,代码来源:test_nameko_sentry.py

示例4: test_json_payload

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def test_json_payload(
        self, container_factory, config, web_session
    ):
        class Service(object):
            name = "service"

            sentry = SentryReporter()

            @http('POST', '/resource')
            def resource(self, request):
                raise CustomException()

        container = container_factory(Service, config)
        container.start()

        submitted_data = {
            'foo': 'bar'
        }
        with entrypoint_waiter(container, 'resource'):
            rv = web_session.post('/resource', json=submitted_data)
            assert rv.status_code == 500
            assert "CustomException" in rv.text

        sentry = get_extension(container, SentryReporter)

        assert sentry.client.send.call_count == 1
        _, kwargs = sentry.client.send.call_args

        received_data = kwargs['request']['data']
        assert received_data == json.dumps(submitted_data).encode('utf-8') 
开发者ID:nameko,项目名称:nameko-sentry,代码行数:32,代码来源:test_nameko_sentry.py

示例5: test_form_submission

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def test_form_submission(
        self, container_factory, config, web_session
    ):
        class Service(object):
            name = "service"

            sentry = SentryReporter()

            @http('POST', '/resource')
            def resource(self, request):
                raise CustomException()

        container = container_factory(Service, config)
        container.start()

        submitted_data = {
            'foo': 'bar'
        }
        with entrypoint_waiter(container, 'resource'):
            web_session.post('/resource', data=submitted_data)

        sentry = get_extension(container, SentryReporter)

        assert sentry.client.send.call_count == 1
        _, kwargs = sentry.client.send.call_args

        assert kwargs['request']['data'] == submitted_data 
开发者ID:nameko,项目名称:nameko-sentry,代码行数:29,代码来源:test_nameko_sentry.py

示例6: test_client_disconnect

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def test_client_disconnect(
        self, container_factory, config, web_session
    ):
        class Service(object):
            name = "service"

            sentry = SentryReporter()

            @http('POST', '/resource')
            def resource(self, request):
                raise CustomException()

        container = container_factory(Service, config)
        container.start()

        request = Mock(
            method="GET",
            url="http://example.com",
            mimetype='application/json',
            environ={}
        )
        type(request).data = PropertyMock(side_effect=ClientDisconnected)

        with entrypoint_hook(container, 'resource') as hook:
            with pytest.raises(CustomException):
                hook(request)

        sentry = get_extension(container, SentryReporter)

        assert sentry.client.send.call_count == 1
        _, kwargs = sentry.client.send.call_args

        assert kwargs['request']['data'] == {} 
开发者ID:nameko,项目名称:nameko-sentry,代码行数:35,代码来源:test_nameko_sentry.py

示例7: sentry_dsn

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def sentry_dsn(self, free_port):
        return 'eventlet+http://user:pass@127.0.0.1:{}/1'.format(free_port) 
开发者ID:nameko,项目名称:nameko-sentry,代码行数:4,代码来源:test_nameko_sentry.py

示例8: check_demo_service

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def check_demo_service(self):
        response = requests.get('http://0.0.0.0:8000/health')
        print("DemoChassisService HEALTH CHECK: status_code {}, response: {}".format(
            response.status_code, response.text)) 
开发者ID:morganjbruce,项目名称:microservices-in-action,代码行数:6,代码来源:demo.py

示例9: app_with_scout

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def app_with_scout(nameko_config=None, scout_config=None):
    """
    Context manager that yields a fresh Nameko WSGI app with Scout configured.
    """
    if scout_config is None:
        scout_config = {}

    scout_config["core_agent_launch"] = False
    scout_config.setdefault("monitor", True)
    Config.set(**scout_config)

    class Service(object):
        name = "myservice"

        scout = ScoutReporter()

        @http("GET", "/")
        def home(self, request):
            return "Welcome home."

        @http("GET", "/crash/")
        def crash(self, request):
            raise ValueError("BØØM!")  # non-ASCII

        @http("GET", "/return-error-response/")
        def return_error_response(self, request):
            return Response(status=503, response="Something went wrong")

        @http("GET", "/return-error-2tuple/")
        def return_error_2tuple(self, request):
            return (503, "Something went wrong")

        @http("GET", "/return-error-3tuple/")
        def return_error_3tuple(self, request):
            return (503, {}, "Something went wrong")

        @http("GET", "/return-error-badtuple/")
        def return_error_badtuple(self, request):
            return ("Nameko doesn't support one tuples",)

    if nameko_config is None:
        nameko_config = {}
    # Container setup copied from Nameko's container_factory pytest fixture,
    # which we don't use - see pytest.ini
    container_cls = get_container_cls(nameko_config)
    container = container_cls(Service, nameko_config)
    try:
        container.start()

        # A bit of introspection to look inside the container and pull out the WSGI
        # app
        app = list(container.subextensions)[0].get_wsgi_app()

        # N.B. We're sidestepping the Nameko testing conventions
        # (https://docs.nameko.io/en/stable/testing.html) to make our tests more
        # uniform between frameworks. See pytest.ini.

        yield app
    finally:
        container.kill()
        Config.reset_all() 
开发者ID:scoutapp,项目名称:scout_apm_python,代码行数:63,代码来源:test_nameko.py

示例10: test_concurrency

# 需要导入模块: from nameko.web import handlers [as 别名]
# 或者: from nameko.web.handlers import http [as 别名]
def test_concurrency(
        self, container_factory, config, web_session
    ):

        class Service(object):
            name = "service"

            sentry = SentryReporter()

            @http('GET', '/resource')
            def resource(self, request):
                breadcrumbs.record(message=request.query_string)
                raise CustomException()

        container = container_factory(Service, config)
        container.start()

        called = Mock()

        def called_twice(worker_ctx, res, exc_info):
            called()
            return called.call_count == 2

        with entrypoint_waiter(container, 'resource', callback=called_twice):
            eventlet.spawn(web_session.get, '/resource?q1')
            eventlet.spawn(web_session.get, '/resource?q2')

        sentry = get_extension(container, SentryReporter)

        assert sentry.client.send.call_count == 2

        breadcrumbs_map = {
            kwargs['request']['query_string']: kwargs['breadcrumbs']['values']
            for (_, kwargs) in sentry.client.send.call_args_list
        }

        expected_crumb_q1 = {
            'category': None,
            'data': None,
            'level': ANY,
            'message': 'q1'.encode('utf-8'),
            'timestamp': ANY,
            'type': 'default'
        }
        assert expected_crumb_q1 in breadcrumbs_map['q1']
        assert expected_crumb_q1 not in breadcrumbs_map['q2']

        expected_crumb_q2 = {
            'category': None,
            'data': None,
            'level': ANY,
            'message': 'q2'.encode('utf-8'),
            'timestamp': ANY,
            'type': 'default'
        }
        assert expected_crumb_q2 in breadcrumbs_map['q2']
        assert expected_crumb_q2 not in breadcrumbs_map['q1'] 
开发者ID:nameko,项目名称:nameko-sentry,代码行数:59,代码来源:test_nameko_sentry.py


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