How to use the pyramid.config.Configurator function in pyramid

To help you get started, we’ve selected a few pyramid 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 ramses-tech / ramses / tests / test_views.py View on Github external
def test_parent_queryset_es(self):
        from pyramid.config import Configurator
        from ramses.acl import BaseACL

        class View(self.view_cls, BaseView):
            _json_encoder = 'foo'

        config = Configurator()
        config.include('nefertari')
        root = config.get_root_resource()
        user = root.add(
            'user', 'users', id_name='username',
            view=View, factory=BaseACL)
        user.add(
            'story', 'stories', id_name='prof_id',
            view=View, factory=BaseACL)
        view_cls = root.resource_map['user:story'].view
        view_cls._json_encoder = 'foo'

        request = Mock(
            registry=Mock(),
            path='/foo/foo',
            matchdict={'username': 'user12', 'prof_id': 4},
            accept=[''], method='GET'
github algoo / hapic / tests / func / test_hapic_file_marshmallow.py View on Github external
def get_pyramid_context():
    h = Hapic(processor_class=MarshmallowProcessor)

    configurator = Configurator(autocommit=True)

    h.reset_context()
    h.set_context(
        PyramidContext(configurator, default_error_builder=MarshmallowDefaultErrorBuilder())
    )

    class MySchema(marshmallow.Schema):
        name = marshmallow.fields.String(required=True)

    @h.with_api_doc()
    @h.input_body(MySchema())
    def my_controller():
        return {"name": "test"}

    configurator.add_route("test", "/test", request_method="POST")
    configurator.add_view(my_controller, route_name="test")
github Kinto / kinto / tests / core / test_initialization.py View on Github external
def test_requests_have_a_bound_data_attribute(self):
        config = Configurator()
        kinto.core.initialize(config, "0.0.1", "name")

        def on_new_request(event):
            data = event.request.bound_data
            self.assertEqual(data, {})
            self.assertEqual(id(data), id(event.request.bound_data))

        config.add_subscriber(on_new_request, NewRequest)
        app = webtest.TestApp(config.make_wsgi_app())
        app.get("/v0/")
github knowsuchagency / ninjadog / tests / pyramid / test_pyramid.py View on Github external
def testapp(settings):
    from pyramid.config import Configurator
    with Configurator(settings=settings) as config:
        config.include('ninjadog')
        config.add_route('home', '/')
        config.add_view(
            lambda request: {'title': 'title', 'subtitle': 'subtitle', 'content': 'This is a paragraph'},
            route_name='home',
            renderer='./templates/child.pug',
        )
        app = config.make_wsgi_app()

        yield _TestApp(app)
github Pylons / pyramid_openapi3 / examples / singlefile / app.py View on Github external
def app(spec):
    """Prepare a Pyramid app."""
    with Configurator() as config:
        config.include("pyramid_openapi3")
        config.pyramid_openapi3_spec(spec)
        config.pyramid_openapi3_add_explorer()
        config.add_route("hello", "/hello")
        config.scan(".")
        return config.make_wsgi_app()
github hathawsh / yasso / src / yasso / main.py View on Github external
def resource_app(global_config, root_factory=None, **settings):
    """App for clients that have an access token.
    """
    if root_factory is None:
        root_factory = make_root_factory(global_config, settings)
    config = Configurator(
        root_factory=root_factory,
        settings=settings,
        authentication_policy=BearerAuthenticationPolicy(root_factory),
        authorization_policy=ACLAuthorizationPolicy(),
    )
    config.scan(resourceviews)
    return config.make_wsgi_app()
github Pylons / pyramid_cookbook / humans / resources / step01 / application.py View on Github external
def main():
    config = Configurator(root_factory=bootstrap)
    config.include('pyramid_chameleon')
    config.scan("views")
    app = config.make_wsgi_app()
    return app
github jnosal / seth / examples / crud.py View on Github external
from seth.db.base import Model


Base = declarative_base(cls=Model)


# Basic model definition
class SuperModel(Base):
    string_column = sa.Column(sa.String(512))

    def __repr__(self):
        return u"SuperModel {0}".format(self.id)


if __name__ == '__main__':
    config = Configurator()
    settings = {
        'sqlalchemy.url': 'sqlite://'
    }

    engine = engine_from_config(settings, prefix='sqlalchemy.')
    maker = scoped_session(sessionmaker(
        extension=ZopeTransactionExtension()
    ))
    maker.configure(bind=engine)
    db.register_maker(maker=maker)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)

    # create two blank models
    session = db.get_session()
    session.add(SuperModel(**{'string_column': 'a'}))
github jnosal / seth / examples / listener.py View on Github external
def __repr__(self):
        return u"SuperModel {0}".format(self.id)


class SampleResource(generics.GenericApiView):

    def get(self):
        print SuperModel.query.count()
        SuperModel.query.all()
        return {}


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    config = Configurator()
    settings = {
        'sqlalchemy.url': 'sqlite://'
    }

    engine = engine_from_config(settings, prefix='sqlalchemy.')
    maker = scoped_session(sessionmaker(
        extension=ZopeTransactionExtension()
    ))
    maker.configure(bind=engine)
    db.register_maker(maker=maker)
    Base.metadata.bind = engine
    Base.metadata.create_all(engine)

    # create two blank models
    session = db.get_session()
    for i in range(10000):
github sontek / pyvore / pyvore / pyvore / scripts / populate.py View on Github external
def main(argv=sys.argv): # pragma: no cover
    if len(argv) != 2:
        usage(argv)

    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)

    config = Configurator(
        settings=settings
    )

    config.include('pyvore.models')

    engine = engine_from_config(settings, 'sqlalchemy.')
    session = DBSession(bind=engine)
    Entity.metadata.bind = engine
    SUEntity.metadata.bind = engine

    Entity.metadata.drop_all(engine)
    SUEntity.metadata.drop_all(engine)

    SUEntity.metadata.create_all(engine)
    Entity.metadata.create_all(engine)