How to use the cornice.service.get_services function in cornice

To help you get started, we’ve selected a few cornice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Cornices / cornice / tests / test_service.py View on Github external
def test_get_services(self):
        self.assertEqual([], get_services())
        foobar = Service("Foobar", "/foobar")
        self.assertIn(foobar, get_services())

        barbaz = Service("Barbaz", "/barbaz")
        self.assertIn(barbaz, get_services())

        self.assertEqual([barbaz, ], get_services(exclude=['Foobar', ]))
        self.assertEqual([foobar, ], get_services(names=['Foobar', ]))
        self.assertEqual([foobar, barbaz],
                         get_services(names=['Foobar', 'Barbaz']))
github Kinto / kinto / tests / core / test_openapi.py View on Github external
def setUp(self):
        super(OpenAPITest, self).setUp()
        self.request = mock.MagicMock()
        self.request.registry.settings = self.get_app_settings()
        self.generator = OpenAPI(get_services(), self.request)
        self.api_doc = self.generator.generate()
github Cornices / cornice / tests / test_service.py View on Github external
def test_get_services(self):
        self.assertEqual([], get_services())
        foobar = Service("Foobar", "/foobar")
        self.assertIn(foobar, get_services())

        barbaz = Service("Barbaz", "/barbaz")
        self.assertIn(barbaz, get_services())

        self.assertEqual([barbaz, ], get_services(exclude=['Foobar', ]))
        self.assertEqual([foobar, ], get_services(names=['Foobar', ]))
        self.assertEqual([foobar, barbaz],
                         get_services(names=['Foobar', 'Barbaz']))
github Kinto / kinto / tests / core / test_openapi.py View on Github external
def setUp(self):
        super(OpenAPITest, self).setUp()
        self.request = mock.MagicMock()
        self.request.registry.settings = self.get_app_settings()
        self.generator = OpenAPI(get_services(), self.request)
        self.api_doc = self.generator.generate()
github Cornices / cornice / tests / test_service.py View on Github external
def test_get_services(self):
        self.assertEqual([], get_services())
        foobar = Service("Foobar", "/foobar")
        self.assertIn(foobar, get_services())

        barbaz = Service("Barbaz", "/barbaz")
        self.assertIn(barbaz, get_services())

        self.assertEqual([barbaz, ], get_services(exclude=['Foobar', ]))
        self.assertEqual([foobar, ], get_services(names=['Foobar', ]))
        self.assertEqual([foobar, barbaz],
                         get_services(names=['Foobar', 'Barbaz']))
github Cornices / cornice / tests / test_service.py View on Github external
def test_get_services(self):
        self.assertEqual([], get_services())
        foobar = Service("Foobar", "/foobar")
        self.assertIn(foobar, get_services())

        barbaz = Service("Barbaz", "/barbaz")
        self.assertIn(barbaz, get_services())

        self.assertEqual([barbaz, ], get_services(exclude=['Foobar', ]))
        self.assertEqual([foobar, ], get_services(names=['Foobar', ]))
        self.assertEqual([foobar, barbaz],
                         get_services(names=['Foobar', 'Barbaz']))
github Cornices / cornice.ext.swagger / tests / test_generate_swagger_spec.py View on Github external
class User(object):
            def __init__(self, request, context=None):
                self.request = request
                self.context = context

            def collection_get(self):
                return {'users': [1, 2, 3]}

            @view(
                renderer='json',
                content_type='application/json',
                schema=RequestSchema())
            def collection_post(self):
                return {'test': 'yeah'}

        services = get_services()
        ret = _generate_swagger(services)

        self.assertEqual(
            sorted(ret["paths"].keys()), [
                '/users',
                '/users/{id}',
            ])

        self.assertEqual(
            sorted(ret["definitions"]['Body']["required"]), ['bar', 'foo'])
github Cornices / cornice.ext.swagger / cornice_swagger / views.py View on Github external
def open_api_json_view(request):
    """
    :param request:
    :return:

    Generates JSON representation of Swagger spec
    """
    doc = cornice_swagger.CorniceSwagger(
        cornice.service.get_services(), pyramid_registry=request.registry)
    kwargs = request.registry.settings['cornice_swagger.spec_kwargs']
    my_spec = doc.generate(**kwargs)
    return my_spec
github Cornices / cornice / cornice / ext / sphinxext.py View on Github external
# import the modules, which will populate the SERVICES variable.
        for module in self.options.get('modules', []):
            if module in MODULES:
                reload(MODULES[module])
            else:
                MODULES[module] = import_module(module)

        names = self.options.get('services', [])

        service = self.options.get('service')
        if service is not None:
            names.append(service)

        # filter the services according to the options we got
        services = get_services(names=names or None,
                                exclude=self.options.get('exclude'))

        return [self._render_service(s) for s in services]
github Kinto / kinto / kinto / core / views / openapi.py View on Github external
def openapi_view(request):

    # Only build json once
    try:
        return openapi_view.__json__
    except AttributeError:
        openapi_view.__json__ = OpenAPI(get_services(), request).generate()
        return openapi_view.__json__