Пример #1
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    Session.configure(bind=engine)
    Base.metadata.bind = engine
    configure_views(Session)
    config = Configurator(settings=settings)
    config.add_static_view('static', 'static', cache_max_age=3600)

    config.add_route('home', '/', views.HomeView.as_view())
    config.add_route('about', '/about', TemplateView.as_view(template_name='example_project:templates/about.pt'))
    config.add_route('book_list_redirect', '/book', RedirectView.as_view(url='/book/list', permanent=True))
    config.add_route('book_list', '/book/list', views.BookListView.as_view())
    config.add_route('book_update', '/book/update/{pk}', views.BookUpdateView.as_view())
    config.add_route('book_delete', '/book/delete/{pk}', views.BookDeleteView.as_view())
    config.add_route('book_create', '/book/create', views.BookCreateView.as_view())

    return config.make_wsgi_app()
Пример #2
0
from contextlib import contextmanager
import unittest
from pyramid import testing
from pyramid.config import Configurator
import six
from sqlalchemy import create_engine, event
from sqlalchemy.orm import scoped_session, sessionmaker
from zope.sqlalchemy import ZopeTransactionExtension
from webtest import TestApp
from pyramid_views.views import MultipleObjectTemplateResponseMixin, SingleObjectTemplateResponseMixin
from pyramid_views import configure_views

Session = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
engine = create_engine('sqlite://')
Session.configure(bind=engine)
configure_views(Session)


def app_main(global_config, **settings):
    config = Configurator(settings=settings)
    app = config.make_wsgi_app()
    return app

# Initialise the app globally to speed up testing
app = app_main({}, **{})


class BaseTest(unittest.TestCase):
    def setUp(self):
        super(BaseTest, self).setUp()
        from .models import Base