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()))
Esempio n. 2
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()))
    def test_path_clash(self, mocked_warn):
        class BadThingImp(object):
            def __init__(self, request, context=None):
                pass
        add_resource(BadThingImp, collection_path='/badthing/{id}',
                     path='/badthing/{id}',
                     name='bad_thing_service')

        msg = "Warning: collection_path and path are not distinct."
        mocked_warn.assert_called_with(msg)
Esempio n. 4
0
    def test_path_clash(self, mocked_warn):
        class BadThingImp(object):
            def __init__(self, request, context=None):
                pass

        add_resource(BadThingImp,
                     collection_path='/badthing/{id}',
                     path='/badthing/{id}',
                     name='bad_thing_service')

        msg = "Warning: collection_path and path are not distinct."
        mocked_warn.assert_called_with(msg)
Esempio n. 5
0
def includeme(config: Configurator):
    settings = config.get_settings()

    config.add_route('home', '/')
    config.add_view(route_name='home', renderer='home.mako')

    config.add_cornice_resource(
        resource.add_resource(views.InfoResource, name='info', path='/info'))

    config.add_cornice_resource(
        resource.add_resource(views.QueryResource, name='query',
                              path='/query'))

    config.add_cornice_resource(
        resource.add_resource(views.LookupResource,
                              name='lookup',
                              path='/lookup'))

    config.add_cornice_resource(
        resource.add_resource(views.DirectionsResource,
                              name='directions',
                              path='/directions'))

    if settings['mvt.base_layers.enabled']:
        # Mapbox Vector Tile base layer views for use in dev
        add_mvt_view(config,
                     Street,
                     properties=(
                         'id',
                         'start_node_id',
                         'end_node_id',
                         'name',
                         'highway',
                         'bicycle',
                         'oneway_bicycle',
                     ))
        add_mvt_view(config, Intersection, properties=('id', ))

    add_mvt_view(config,
                 Street,
                 layer_name='bike',
                 properties=('id', 'name', 'bicycle'),
                 where_clause=
                 "cycleway IS NOT NULL and cycleway NOT IN ('no', 'proposed')")

    config.add_route('map.street_boundary', '/map/street-boundary')
    config.add_view(route_name='map.street_boundary',
                    view=views.street_bbox_view)
Esempio n. 6
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.include('pyramid_jinja2')
    config.add_renderer('img_json', JSON(indent=4))
    config.add_static_view('static', 'static', cache_max_age=3600)

    db_url = urlparse("mongodb://*****:*****@localhost:27017/loaddb")

    config.registry.db = MongoClient(
        host=db_url.hostname,
        port=db_url.port,
    )

    def add_db(request):
        db = config.registry.db[db_url.path[1:]]
        if db_url.username and db_url.password:
            db.authenticate(db_url.username, db_url.password)
        return db

    config.add_route('index', '/')
    config.add_request_method(add_db, 'db', reify=True)

    user_resource = resource.add_resource(File,
                                          collection_path='/api/v1/files',
                                          path='/api/v1/files/{uuid}')

    config.include("cornice")
    config.add_cornice_resource(user_resource)
    config.scan('loader')
    return config.make_wsgi_app()
Esempio n. 7
0
 def wrapper(cls):
     service_path = kwargs.pop('service_path', None)
     klass = add_resource(cls, depth, **kwargs)
     klass = add_execute_on_crud_resource(klass,
                                          service_path=service_path,
                                          **kwargs)
     return klass
Esempio n. 8
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)
Esempio n. 9
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)
    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()))
Esempio n. 11
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()))
Esempio n. 12
0
        except KeyError as e:
            return {'id': sha_id, 'exception':'KeyError', 'value': str(e)}
        response=Response(
            content_type='application/octet-stream',
            body=data
        )
        return response

    def delete(self, sha_id):
        sha_id=self.request.matchdict['id']
        if len(sha_id) != 64:
            abort(404)
        try:
            key=storage().remove(sha_id)
        except KeyError as e:
            return {'id': sha_id, 'exception':'KeyError', 'value': str(e)}
        return {'id': key, 'deleted':True}

#add_view(Documents.collection_post, renderer='json', status=201)
#add_view(Documents.get, renderer='json')
#add_view(Documents.delete, renderer='json')

document_resource = add_resource(
    Documents,
    path='/content/{id}',
    collection_path='/content',
) #, description="Document API")

def includeme(config):
    config.add_cornice_resource(document_resource)