Пример #1
0
def main(global_config, **settings):
    'Return a Pyramid WSGI application'
    # Connect to database
    initialize_sql(engine_from_config(settings, 'sqlalchemy.'))
    # Define methods
    def make_renderer_globals(system):
        'Define template constants'
        return {'SITE_NAME': 'board'}
    # Prepare configuration
    config = Configurator(settings=settings, 
        renderer_globals_factory=make_renderer_globals)
    # Configure caching
    set_cache_regions_from_settings(settings)
    # Configure static assets
    config.add_static_view('static', 'board:static')
    # Configure routes
    config.include(views)
    # Return WSGI app
    return config.make_wsgi_app()
Пример #2
0
'Tests'
import unittest
from pyramid.config import Configurator
from pyramid import testing
from pyramid_beaker import set_cache_regions_from_settings
from sqlalchemy import create_engine

from board.models import db, Post, initialize_sql


initialize_sql(create_engine('sqlite://'))


class TestViews(unittest.TestCase):

    def setUp(self):
        self.config = testing.setUp()
        set_cache_regions_from_settings({
            'cache.type': 'memory',
            'cache.regions': 'minute',
        })

    def tearDown(self):
        testing.tearDown()

    def test_index(self):
        from board.views import index
        # Make sure that index() returns as many posts as exist in the database
        info = index(testing.DummyRequest())
        self.assertEqual(len(info['posts']), db.query(Post).count())
Пример #3
0
'Tests'
import unittest
from pyramid.config import Configurator
from pyramid import testing
from pyramid_beaker import set_cache_regions_from_settings
from sqlalchemy import create_engine

from board.models import db, Post, initialize_sql

initialize_sql(create_engine('sqlite://'))


class TestViews(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()
        set_cache_regions_from_settings({
            'cache.type': 'memory',
            'cache.regions': 'minute',
        })

    def tearDown(self):
        testing.tearDown()

    def test_index(self):
        from board.views import index
        # Make sure that index() returns as many posts as exist in the database
        info = index(testing.DummyRequest())
        self.assertEqual(len(info['posts']), db.query(Post).count())

    def test_index_(self):
        from board.views import index_