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


Python Service.add_view方法代码示例

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


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

示例1: test_fallback_no_required_csrf

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
 def test_fallback_no_required_csrf(self):
     service = Service(name='fallback-csrf', path='/', content_type='application/json')
     service.add_view('POST', lambda _:'', require_csrf=False)
     register_service_views(self.config, service)
     self.config.include('cornice')
     app = self.config.make_wsgi_app()
     testapp = TestApp(app)
     testapp.post('/', status=415, headers={'Content-Type': 'application/xml'})
开发者ID:mozilla-services,项目名称:cornice,代码行数:10,代码来源:test_pyramidhook.py

示例2: _get_app

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
    def _get_app(self):
        self.config.include('cornice')

        failing_service = Service(name='failing', path='/fail')
        failing_service.add_view('GET', lambda r: 1 / 0)
        self.config.add_cornice_service(failing_service)

        return TestApp(CatchErrors(self.config.make_wsgi_app()))
开发者ID:joesteeve,项目名称:cornice,代码行数:10,代码来源:test_init.py

示例3: test_fallback_no_predicate

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
 def test_fallback_no_predicate(self):
     service = Service(name='fallback-test', path='/',
                       effective_principals=('group:admins',))
     service.add_view('GET', lambda _:_)
     register_service_views(self.config, service)
     self.config.include('cornice')
     app = self.config.make_wsgi_app()
     testapp = TestApp(app)
     testapp.get('/', status=404)
开发者ID:mozilla-services,项目名称:cornice,代码行数:11,代码来源:test_pyramidhook.py

示例4: includeme

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
def includeme(config):
    # FIXME this should also work in includeme
    user_info = Service(name='users', path='/{username}/info')
    user_info.add_view('get', get_info)
    config.add_cornice_service(user_info)

    resource.add_view(ThingImp.collection_get, permission='read')
    thing_resource = resource.add_resource(
        ThingImp, collection_path='/thing', path='/thing/{id}',
        name='thing_service')
    config.add_cornice_resource(thing_resource)
开发者ID:foozzi,项目名称:cornice,代码行数:13,代码来源:views.py

示例5: setUp

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
    def setUp(self):
        self.config = testing.setUp()
        self.config.include("cornice")
        self.config.add_route('proute', '/from_pyramid')
        self.config.scan("tests.test_pyramidhook")

        def handle_response(request):
            return {'service': request.current_service.name,
                    'route': request.matched_route.name}
        rserv = Service(name="ServiceWPyramidRoute", pyramid_route="proute")
        rserv.add_view('GET', handle_response)

        register_service_views(self.config, rserv)
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
开发者ID:mozilla-services,项目名称:cornice,代码行数:16,代码来源:test_pyramidhook.py

示例6: test_fallback_permission

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
    def test_fallback_permission(self):
        """
        Fallback view should be registered with NO_PERMISSION_REQUIRED
        Fixes: https://github.com/mozilla-services/cornice/issues/245
        """
        service = Service(name='fallback-test', path='/')
        service.add_view('GET', lambda _:_)
        register_service_views(self.config, service)

        # This is a bit baroque
        introspector = self.config.introspector
        views = introspector.get_category('views')
        fallback_views = [i for i in views
                          if i['introspectable']['route_name']=='fallback-test']

        for v in fallback_views:
            if v['introspectable'].title == u'function cornice.pyramidhook._fallback_view':
                permissions = [p['value'] for p in v['related'] if p.type_name == 'permission']
                self.assertIn(NO_PERMISSION_REQUIRED, permissions)
开发者ID:mozilla-services,项目名称:cornice,代码行数:21,代码来源:test_pyramidhook.py

示例7: test

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
 def test(self):
     # Compiled regexs are, apparently, non-pickleable
     service = Service(name="test", path="/", schema={'a': re.compile('')})
     service.add_view('GET', lambda _:_)
     register_service_views(self.config, service)
开发者ID:mozilla-services,项目名称:cornice,代码行数:7,代码来源:test_pyramidhook.py

示例8: get_fresh_air

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
    def get_fresh_air(self):
        resp = Response()
        resp.text = u'air with ' + repr(self.context)
        return resp

    def make_it_fresh(self, response):
        response.text = u'fresh ' + response.text
        return response

    def check_temperature(self, request, **kw):
        if not 'X-Temperature' in request.headers:
            request.errors.add('header', 'X-Temperature')

tc = Service(name="TemperatureCooler", path="/fresh-air",
             klass=TemperatureCooler, factory=dummy_factory)
tc.add_view("GET", "get_fresh_air", filters=('make_it_fresh',),
            validators=('check_temperature',))


class TestService(TestCase):

    def setUp(self):
        self.config = testing.setUp(
            settings={'pyramid.debug_authorization': True})

        # Set up debug_authorization logging to console
        logging.basicConfig(level=logging.DEBUG)
        debug_logger = logging.getLogger()
        self.config.registry.registerUtility(debug_logger, IDebugLogger)

        self.config.include("cornice")
开发者ID:mozilla-services,项目名称:cornice,代码行数:33,代码来源:test_pyramidhook.py

示例9: get_fresh_air

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
    def get_fresh_air(self):
        resp = Response()
        resp.body = 'air'
        return resp

    def make_it_fresh(self, response):
        response.body = 'fresh ' + response.body
        return response

    def check_temperature(self, request):
        if not 'X-Temperature' in request.headers:
            request.errors.add('header', 'X-Temperature')

tc = Service(name="TemperatureCooler", path="/fresh-air",
             klass=TemperatureCooler)
tc.add_view("GET", "get_fresh_air", filters=('make_it_fresh',),
            validators=('check_temperature',))


class TestService(TestCase):

    def setUp(self):
        self.config = testing.setUp()
        self.config.include("cornice")
        self.config.scan("cornice.tests.test_service")
        self.config.scan("cornice.tests.test_pyramidhook")
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))

    def tearDown(self):
        testing.tearDown()

    def test_404(self):
开发者ID:CDC,项目名称:cornice,代码行数:34,代码来源:test_pyramidhook.py

示例10: test

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
 def test(self):
     service = Service(name="test", path="/", schema=NonpickableSchema())
     service.add_view('GET', lambda _:_)
     register_service_views(self.config, service)
开发者ID:cghnassia,项目名称:Roki_Rakat,代码行数:6,代码来源:test_pyramidhook.py

示例11: get_fresh_air

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
    def get_fresh_air(self):
        resp = Response()
        resp.text = u'air with ' + repr(self.context)
        return resp

    def make_it_fresh(self, response):
        response.text = u'fresh ' + response.text
        return response

    def check_temperature(self, request):
        if not 'X-Temperature' in request.headers:
            request.errors.add('header', 'X-Temperature')

tc = Service(name="TemperatureCooler", path="/fresh-air",
             klass=TemperatureCooler, factory=dummy_factory)
tc.add_view("GET", "get_fresh_air", filters=('make_it_fresh',),
            validators=('check_temperature',))


class TestService(TestCase):

    def setUp(self):
        self.config = testing.setUp()
        self.config.include("cornice")
        self.config.scan("cornice.tests.test_service")
        self.config.scan("cornice.tests.test_pyramidhook")
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))

    def tearDown(self):
        testing.tearDown()

    def test_404(self):
开发者ID:cghnassia,项目名称:Roki_Rakat,代码行数:34,代码来源:test_pyramidhook.py

示例12: get_fresh_air

# 需要导入模块: from cornice import Service [as 别名]
# 或者: from cornice.Service import add_view [as 别名]
    def get_fresh_air(self):
        resp = Response()
        resp.body = "air"
        return resp

    def make_it_fresh(self, response):
        response.body = "fresh " + response.body
        return response

    def check_temperature(self, request):
        if not "X-Temperature" in request.headers:
            request.errors.add("header", "X-Temperature")


tc = Service(name="TemperatureCooler", path="/fresh-air", klass=TemperatureCooler)
tc.add_view("GET", "get_fresh_air", filters=("make_it_fresh",), validators=("check_temperature",))


class TestService(TestCase):
    def setUp(self):
        self.config = testing.setUp()
        self.config.include("cornice")
        self.config.scan("cornice.tests.test_service")
        self.config.scan("cornice.tests.test_pyramidhook")
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))

    def tearDown(self):
        testing.tearDown()

    def test_404(self):
        # a get on a resource that explicitely return a 404 should return
开发者ID:msabramo,项目名称:cornice,代码行数:33,代码来源:test_pyramidhook.py


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