Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
    def setUp(self):
        from pyramid.renderers import JSONP

        self.config = testing.setUp()
        self.config.add_renderer('jsonp', JSONP(param_name='callback'))
        self.config.include("cornice")
        self.authz_policy = ACLAuthorizationPolicy()
        self.config.set_authorization_policy(self.authz_policy)

        self.authn_policy = AuthTktAuthenticationPolicy('$3kr1t')
        self.config.set_authentication_policy(self.authn_policy)

        add_view(ThingImp.collection_get, permission='read')
        thing_resource = add_resource(
            ThingImp, collection_path='/thing', path='/thing/{id}',
            name='thing_service')

        add_view(UserImp.get, renderer='json')
        add_view(UserImp.get, renderer='jsonp')
        add_view(UserImp.collection_post, renderer='json', accept='text/json')
        user_resource = add_resource(
            UserImp, collection_path='/users', path='/users/{id}',
            name='user_service', factory=dummy_factory)

        self.config.add_cornice_resource(thing_resource)
        self.config.add_cornice_resource(user_resource)
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
Exemplo n.º 4
0
    def setUp(self):
        from pyramid.renderers import JSONP

        self.config = testing.setUp()
        self.config.add_renderer('jsonp', JSONP(param_name='callback'))
        self.config.include("cornice")
        self.authz_policy = ACLAuthorizationPolicy()
        self.config.set_authorization_policy(self.authz_policy)

        self.authn_policy = AuthTktAuthenticationPolicy('$3kr1t')
        self.config.set_authentication_policy(self.authn_policy)

        add_view(ThingImp.collection_get, permission='read')
        thing_resource = add_resource(ThingImp,
                                      collection_path='/thing',
                                      path='/thing/{id}',
                                      name='thing_service',
                                      collection_acl=my_collection_acl)

        add_view(UserImp.get, renderer='json')
        add_view(UserImp.get, renderer='jsonp')
        add_view(UserImp.collection_post, renderer='json', accept='text/json')
        user_resource = add_resource(UserImp,
                                     collection_path='/users',
                                     path='/users/{id}',
                                     name='user_service',
                                     factory=dummy_factory)

        self.config.add_cornice_resource(thing_resource)
        self.config.add_cornice_resource(user_resource)
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
Exemplo n.º 5
0
        def wrapper(method):
            method.crud_resource_execute_name = name
            method.crud_resource_execute_path = path

            if collection:
                method.is_a_crud_resource_execute_on_collection = True
                validators = (collection_execute_validator, )
            else:
                method.is_a_crud_resource_execute = True
                validators = (execute_validator, )

            add_view(method,
                     validators=validators,
                     permission=permission,
                     **kwargs)
            return method
Exemplo n.º 6
0
    def setUp(self):
        from pyramid.renderers import JSONP
        self.config = testing.setUp(autocommit=False)
        self.config.add_renderer('jsonp', JSONP(param_name='callback'))
        self.config.include("cornice")

        add_view(UserImp.get, renderer='json')
        add_view(UserImp.get, renderer='jsonp')
        add_view(UserImp.collection_post, renderer='json', accept='text/json')
        user_resource = add_resource(
            UserImp, collection_path='/users', path='/users/{id}',
            name='user_service', factory=dummy_factory)

        self.config.add_cornice_resource(user_resource)
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
Exemplo n.º 7
0
    def setUp(self):
        from pyramid.renderers import JSONP
        self.config = testing.setUp(autocommit=False)
        self.config.add_renderer('jsonp', JSONP(param_name='callback'))
        self.config.include("cornice")

        add_view(UserImp.get, renderer='json')
        add_view(UserImp.get, renderer='jsonp')
        add_view(UserImp.collection_post, renderer='json', accept='text/json')
        user_resource = add_resource(UserImp,
                                     collection_path='/users',
                                     path='/users/{id}',
                                     name='user_service',
                                     factory=dummy_factory)

        self.config.add_cornice_resource(user_resource)
        self.app = TestApp(CatchErrors(self.config.make_wsgi_app()))
Exemplo n.º 8
0
    def __new__(mcs, name, bases, namespace):

        # collectin_get
        if "collection_get" not in namespace:

            def collection_get(self):
                return super(cls, self).collection_get()

        else:
            collection_get = namespace["collection_get"]

        (
            collection_get_schema,
            collection_get_response_schemas,
            collection_get_validators,
            collection_get_error_handler,
            factory,
        ) = _unpack_decorated_args(collection_get)

        namespace["collection_get"] = add_view(
            collection_get,
            schema=collection_get_schema,
            validators=collection_get_validators,
            content_type="application/vnd.api+json",
            apispec_show=True,
            renderer="json_api",
            factory=factory,
            error_handler=collection_get_error_handler,
            # permission="view",
            apispec_response_schemas=collection_get_response_schemas,
        )

        # collection_post
        if "collection_post" not in namespace:

            def collection_post(self):
                return super(cls, self).collection_post()

        else:
            collection_post = namespace["collection_post"]

        (
            collection_post_schema,
            collection_post_response_schemas,
            collection_post_validators,
            collection_post_error_handler,
            factory,
        ) = _unpack_decorated_args(collection_post)

        namespace["collection_post"] = add_view(
            collection_post,
            validators=collection_post_validators,
            apispec_show=True,
            content_type="application/vnd.api+json",
            renderer="json_api",
            schema=collection_post_schema,
            apispec_response_schemas=collection_post_response_schemas,
            error_handler=collection_post_error_handler,
            factory=factory
            # permission="edit",
        )

        if (
            "resource_response_schemas" in namespace
            and namespace["resource_response_schemas"]
        ):
            resource_response_schemas = namespace["resource_response_schemas"]
        else:
            resource_response_schemas = None

        # get
        if "get" not in namespace:

            def get(self):
                return super(cls, self).get()

        else:
            get = namespace["get"]

        (
            resource_get_schema,
            resource_get_response_schemas,
            resource_get_validators,
            resource_get_error_handler,
            factory,
        ) = _unpack_decorated_args(get)

        namespace["get"] = add_view(
            get,
            # apispec_show=True,
            schema=resource_get_schema,
            validators=resource_get_validators,
            apispec_response_schemas=resource_get_response_schemas,
            renderer="json_api",
            content_type="application/vnd.api+json",
            error_handler=resource_get_error_handler,
            factory=factory
            # permission="view",
        )

        # post
        if "post" not in namespace:

            def post(self):
                return super(cls, self).post()

        else:
            post = namespace["post"]

        (
            resource_post_schema,
            resource_post_response_schemas,
            resource_post_validators,
            resource_post_error_handler,
            factory,
        ) = _unpack_decorated_args(post)

        namespace["post"] = add_view(
            post,
            validators=resource_post_validators,
            # apispec_show=True,
            schema=resource_post_schema,
            apispec_response_schemas=resource_post_response_schemas,
            renderer="json_api",
            error_handler=resource_post_error_handler,
            factory=factory
            # permission="edit",
        )

        # delete
        if "delete" not in namespace:

            def delete(self):
                return super(cls, self).delete()

        else:
            delete = namespace["delete"]

        (
            resource_delete_schema,
            resource_delete_response_schemas,
            resource_delete_validators,
            resource_delete_error_handler,
            factory,
        ) = _unpack_decorated_args(delete)

        namespace["delete"] = add_view(
            delete,
            validators=resource_delete_validators,
            # apispec_show=True,
            schema=resource_delete_schema,
            apispec_response_schemas=resource_delete_response_schemas,
            renderer="json_api",
            error_handler=resource_delete_error_handler,
            factory=factory
            # permission="edit",
        )

        # put
        if "put" not in namespace:

            def put(self):
                return super(cls, self).put()

        else:
            put = namespace["put"]

        (
            resource_put_schema,
            resource_put_response_schemas,
            resource_put_validators,
            resource_put_error_handler,
            factory_put,
        ) = _unpack_decorated_args(put)

        namespace["put"] = add_view(
            put,
            validators=resource_put_validators,
            # apispec_show=True,
            schema=resource_put_schema,
            apispec_response_schemas=resource_put_response_schemas,
            renderer="json_api",
            error_handler=resource_put_error_handler,
            factory=factory_put
            # permission="edit",
        )

        # patch
        if "patch" not in namespace:

            def patch(self):
                return super(cls, self).patch()

        else:
            patch = namespace["patch"]

        (
            resource_patch_schema,
            resource_patch_response_schemas,
            resource_patch_validators,
            resource_patch_error_handler,
            factory_patch,
        ) = _unpack_decorated_args(patch)

        namespace["patch"] = add_view(
            patch,
            validators=resource_patch_validators,
            # apispec_show=True,
            schema=resource_patch_schema,
            apispec_response_schemas=resource_patch_response_schemas,
            renderer="json_api",
            error_handler=resource_patch_error_handler,
            factory=factory_patch
            # permission="edit",
        )

        cls = super(Meta, mcs).__new__(mcs, name, bases, namespace)
        return cls