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


Python klein.Klein方法代码示例

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


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

示例1: test_routes

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def test_routes(self):
        """
        L{getRoutes} returns all the defined routes and their attributes.
        """
        app = Klein()

        def f():
            pass
        f.attr = "attr"

        def g():
            pass
        g.attr = "G"
        app.route(b"/", methods=[b"GET"])(f)
        app.route(b"/g", methods=[b"PUT", b"OPTIONS"])(g)

        routes = sorted(getRoutes(app))
        self.assertEqual(routes, [
            KleinRoute(methods={b"GET"}, path=b"/", endpoint="f",
                       attributes={'attr': 'attr'}),
            KleinRoute(methods={b'PUT', b'OPTIONS'}, path=b'/g', endpoint='g',
                       attributes={'attr': 'G'})]) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:24,代码来源:test_publicapi.py

示例2: test_must_be_documented

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def test_must_be_documented(self):
        """
        If any route doesn't have documentation, then ``SphinxError`` is
        raised.
        """
        app = Klein()

        @app.route(b"/", methods=[b"GET"])
        def dummy_f():
            """
            Developer docs.
            """

        self.assertRaises(
            SphinxError,
            lambda: list(makeRst(b"/prefix", 'section', app, None, {}))) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:18,代码来源:test_publicapi.py

示例3: webserver_for_test

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def webserver_for_test(test, url_path, response_content):
    """
    Create a webserver that serves ``response_content`` from ``url_path``.
    """
    app = Klein()

    @app.route(url_path)
    def _respond(request):
        return response_content
    factory = Site(app.resource())
    endpoint = serverFromString(reactor, b"tcp:0")
    listening = endpoint.listen(factory)

    def stop_port(port):
        test.addCleanup(port.stopListening)
        return port
    listening.addCallback(stop_port)
    return listening 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:20,代码来源:test_cinder.py

示例4: create_app

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def create_app():
  config = get_config()

  config['LOGBOOK'].push_application()

  if "PLUGINS" not in config or len(config["PLUGINS"]) < 1:
    logger.warn("Missing or invalid PLUGINS configuration!")

  if "PRACTICES" not in config or len(config["PRACTICES"]) < 1:
    logger.warn("Missing or invalid PRACTICES configuration!")
  else:
    logger.debug("PRACTICES:\n{:s}", stethoscope.utils.json_pp(config['PRACTICES']))

  app = klein.Klein()
  auth = stethoscope.auth.KleinAuthProvider(config)
  csrf = stethoscope.csrf.CSRFProtection(config)

  register_error_handlers(app, config, auth)
  register_endpoints(app, config, auth, csrf)

  logger.info("Shields up, weapons online.")

  return app 
开发者ID:Netflix-Skunkworks,项目名称:stethoscope,代码行数:25,代码来源:factory.py

示例5: setUp

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def setUp(self):
    super(AppTestCase, self).setUp()

    self.app = klein.Klein()
    self.kr = KleinResource(self.app)

    @self.app.route("/")
    @self.auth.token_required
    def token_required_endpoint(request, userinfo):
      return userinfo
    self.token_required_endpoint = token_required_endpoint

    @self.app.route("/api/<string:email>")
    @self.auth.match_required
    def match_required_endpoint(request, userinfo, email):
      logger.debug("in endpoint: request={!r}, userinfo={!r}, email={!r}", request, userinfo, email)
      return json.dumps(userinfo)
    self.match_required_endpoint = match_required_endpoint 
开发者ID:Netflix-Skunkworks,项目名称:stethoscope,代码行数:20,代码来源:test_auth.py

示例6: test_add_route

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def test_add_route(self):
    app = klein.Klein()
    auth = DummyAuthProvider()

    result = ['foobar']
    ext = get_mock_ext(result)

    callback = mock.Mock(side_effect=lambda x: x)

    stethoscope.api.endpoints.utils.add_get_route(ext, app, auth, 'resource', 'email',
                                                  callbacks=[callback])

    # see klein's test_app.py
    self.assertEqual(
        app.url_map.bind('resource-foo-email').match("/resource/foo/email/user@example.com"),
        ('resource-foo-email', {'email': "user@example.com"}))
    self.assertEqual(len(app.endpoints), 1)

    self.check_result(app, b'/resource/foo/email/user@example.com', result, callback) 
开发者ID:Netflix-Skunkworks,项目名称:stethoscope,代码行数:21,代码来源:test_factory.py

示例7: test_register_userinfo_api_endpoints

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def test_register_userinfo_api_endpoints(self):
    app = klein.Klein()
    auth = DummyAuthProvider()
    result = ['foobar']

    with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
        mock_instantiate_plugins:
      mock_instantiate_plugins.return_value = stevedore.ExtensionManager.make_test_instance(
          [get_mock_ext(result)])
      stethoscope.api.endpoints.userinfo.register_userinfo_api_endpoints(app, config, auth)

    # see klein's test_app.py
    self.assertEqual(
        app.url_map.bind('userinfo-foo-email').match("/userinfo/foo/email/user@example.com"),
        ('userinfo-foo-email', {'email': "user@example.com"})
    )
    self.assertEqual(len(app.endpoints), 1)

    self.check_result(app, b'/userinfo/foo/email/user@example.com', result) 
开发者ID:Netflix-Skunkworks,项目名称:stethoscope,代码行数:21,代码来源:test_factory.py

示例8: test_sections

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def test_sections(self):
        """
        Documentation is only generated for routes from the corresponding
        section.
        """
        app = Klein()

        @app.route(b"/", methods=[b"GET"])
        @user_documentation(
            u"Undocumented.", header=u"Header", section=u'other-section')
        def dummy_f():
            """
            Developer docs.
            """

        @app.route(b"/", methods=[b"GET"])
        @user_documentation(
            u"Documented.", header=u"Header", section=u'section')
        def dummy_g():
            """
            Developer docs.
            """

        rest = list(makeRst(b"/prefix", 'section', app, None, {}))

        self.assertEqual(rest, [
            'Header',
            '------',
            '',
            '',
            '.. http:get:: /prefix/',
            '',
            '   Documented.',
            '   ',
            '',
            ]) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:38,代码来源:test_publicapi.py

示例9: test_stuff

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def test_stuff(self):
        """
        L{makeRst} returns a generator that returns a bunch of lines of rest.
        """
        app = Klein()

        @app.route(b"/g", methods=[b"PUT"])
        @user_documentation(
            u"""
            Does G-like stuff.

            Like g, G and gg.
            """,
            header=u'g stuff',
            section=u'section')
        def dummy_g():
            pass

        rest = list(makeRst(b"/prefix", 'section', app, None, {}))

        self.assertEqual(rest, [
            'g stuff',
            '-------',
            '',
            '',
            '.. http:put:: /prefix/g',
            '',
            '   Does G-like stuff.',
            '   ',
            '   Like g, G and gg.',
            '   ',
            '',
            ]) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:35,代码来源:test_publicapi.py

示例10: test_private_not_visible

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def test_private_not_visible(self):
        """
        When an endpoint is decorated with ``@private_api`` it is
        omitted from result of ``makeRst``.
        """
        app = Klein()

        @private_api
        def g():
            pass

        app.route(b"/g", methods=[b"GET"])(g)
        rest = list(makeRst(b"/", "section", app, None, {}))
        self.assertEqual(rest, []) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:16,代码来源:test_publicapi.py

示例11: test_register_notification_api_endpoints

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def test_register_notification_api_endpoints(self):
    app = klein.Klein()
    auth = DummyAuthProvider()
    result_foo = [{'_source': {'event_timestamp': 0}}]
    result_bar = [{'_source': {'event_timestamp': 1}}]

    mock_hook = mock.Mock()
    mock_hook.obj.transform.side_effect = lambda x: x
    mock_hook_manager = stevedore.ExtensionManager.make_test_instance([mock_hook])
    mock_extension_manager = stevedore.ExtensionManager.make_test_instance(
        [get_mock_ext(result_foo, 'foo'), get_mock_ext(result_bar, 'bar')])

    with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
        mock_instantiate_plugins:
      mock_instantiate_plugins.side_effect = [mock_extension_manager, mock_hook_manager]
      stethoscope.api.endpoints.notifications.register_notification_api_endpoints(app, config, auth)

    # see klein's test_app.py
    adapter_foo = app.url_map.bind('notifications-foo-email')
    self.assertEqual(
        adapter_foo.match("/notifications/foo/email/user@example.com"),
        ('notifications-foo-email', {'email': "user@example.com"})
    )

    adapter_bar = app.url_map.bind('notifications-bar-email')
    self.assertEqual(
        adapter_bar.match("/notifications/bar/email/user@example.com"),
        ('notifications-bar-email', {'email': "user@example.com"})
    )

    self.assertEqual(
        app.url_map.bind('notifications-merged').match("/notifications/merged/user@example.com"),
        ('notifications-merged', {'email': "user@example.com"})
    )

    self.assertEqual(len(app.endpoints), 3)

    self.check_result(app, b'/notifications/foo/email/user@example.com', result_foo)
    self.check_result(app, b'/notifications/bar/email/user@example.com', result_bar)

    self.check_result(app, b'/notifications/merged/user@example.com', result_bar + result_foo) 
开发者ID:Netflix-Skunkworks,项目名称:stethoscope,代码行数:43,代码来源:test_factory.py

示例12: test_register_event_api_endpoints

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def test_register_event_api_endpoints(self):
    app = klein.Klein()
    auth = DummyAuthProvider()
    result_foo = [{'timestamp': 0}]
    result_bar = [{'timestamp': 1}]

    mock_hook = mock.Mock()
    mock_hook.obj.transform.side_effect = lambda x: x
    mock_hook_manager = stevedore.ExtensionManager.make_test_instance([mock_hook])
    mock_extension_manager = stevedore.ExtensionManager.make_test_instance(
        [get_mock_ext(result_foo, 'foo'), get_mock_ext(result_bar, 'bar')])

    with mock.patch('stethoscope.plugins.utils.instantiate_plugins') as \
        mock_instantiate_plugins:
      mock_instantiate_plugins.side_effect = [mock_extension_manager, mock_hook_manager]
      stethoscope.api.endpoints.events.register_event_api_endpoints(app, config, auth)

    # see klein's test_app.py
    self.assertEqual(
        app.url_map.bind('events-foo-email').match("/events/foo/email/user@example.com"),
        ('events-foo-email', {'email': "user@example.com"})
    )
    self.assertEqual(
        app.url_map.bind('events-bar-email').match("/events/bar/email/user@example.com"),
        ('events-bar-email', {'email': "user@example.com"})
    )

    self.assertEqual(app.url_map.bind('events-merged').match("/events/merged/user@example.com"),
        ('events-merged', {'email': "user@example.com"}))

    self.assertEqual(len(app.endpoints), 3)

    self.check_result(app, b'/events/foo/email/user@example.com', result_foo)
    self.check_result(app, b'/events/bar/email/user@example.com', result_bar)

    self.check_result(app, b'/events/merged/user@example.com', result_bar + result_foo) 
开发者ID:Netflix-Skunkworks,项目名称:stethoscope,代码行数:38,代码来源:test_factory.py

示例13: setUp

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def setUp(self):
    self.app = app = klein.Klein()
    self.auth = auth = DummyAuthProvider()
    self.config = config = {
      'DEBUG': True,
      'TESTING': True,
    }

    stethoscope.api.factory.register_error_handlers(app, config, auth) 
开发者ID:Netflix-Skunkworks,项目名称:stethoscope,代码行数:11,代码来源:test_validation.py

示例14: setUp

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def setUp(self):
    self.csrf = stethoscope.csrf.CSRFProtection({})
    self.app = klein.Klein()

    @self.app.route("/")
    @self.csrf.csrf_protect
    def endpoint(request):
      return mock.sentinel.DEFAULT 
开发者ID:Netflix-Skunkworks,项目名称:stethoscope,代码行数:10,代码来源:test_csrf.py

示例15: remove_multicast_distribution_set

# 需要导入模块: import klein [as 别名]
# 或者: from klein import Klein [as 别名]
def remove_multicast_distribution_set(self, device, data):
        raise NotImplementedError()

    # ~~~~~~~~~~~~~~~~~~~~ Embedded test Klein rest server ~~~~~~~~~~~~~~~~~~~~ 
开发者ID:opencord,项目名称:voltha,代码行数:6,代码来源:simulated_olt.py


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