Exemplo n.º 1
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from feedduty.models import (
         BaseModel,
         MyModel,
         )
     DBSession.configure(bind=engine)
     BaseModel.metadata.create_all(engine)
     with transaction.manager:
         model = MyModel(name='one', value=55)
         DBSession.add(model)
Exemplo n.º 2
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from feedduty.models import (
         BaseModel,
         MyModel,
     )
     DBSession.configure(bind=engine)
     BaseModel.metadata.create_all(engine)
     with transaction.manager:
         model = MyModel(name='one', value=55)
         DBSession.add(model)
Exemplo n.º 3
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    # configure SQLAlchemy
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    BaseModel.metadata.bind = engine

    # Load pyramid configuration
    config = Configurator(settings=settings)

    # Configure extensions
    config.add_jinja2_search_path("feedduty:api/templates")
    config.add_jinja2_search_path("feedduty:web/templates")

    # Configure renderers
    # Configure JSON renderer to understand certain objects
    json_renderer = JSON()
    json_renderer.add_adapter(datetime.datetime, _datetime_adapter)

    config.add_renderer('json', json_renderer)
    config.add_renderer('.html', jinja2_renderer)

    # Static assets - this should only work in dev, in prod it should be served by web server (nginx?)
    config.add_static_view('static', 'feedduty:static', cache_max_age=3600)

    # API Routing configuration
    config.add_route('api_main', '/api')

    # Catch all route - loads the web app
    config.add_route('app', '/')

    # scan for view handlers
    config.scan('feedduty.api.views')
    config.scan('feedduty.web.views')

    # return a uwsgi compatible app
    return config.make_wsgi_app()