Sync ZODB tutorial source files with the scaffold
| | |
| | | setup(name='tutorial', |
| | | version='0.0', |
| | | description='tutorial', |
| | | long_description=README + '\n\n' + CHANGES, |
| | | long_description=README + '\n\n' + CHANGES, |
| | | classifiers=[ |
| | | "Programming Language :: Python", |
| | | "Framework :: Pyramid", |
| | |
| | | packages=find_packages(), |
| | | include_package_data=True, |
| | | zip_safe=False, |
| | | install_requires = requires, |
| | | tests_require= requires, |
| | | install_requires=requires, |
| | | tests_require=requires, |
| | | test_suite="tutorial", |
| | | entry_points = """\ |
| | | entry_points="""\ |
| | | [paste.app_factory] |
| | | main = tutorial:main |
| | | """, |
| | | ) |
| | | |
| | |
| | | conn = get_connection(request) |
| | | return appmaker(conn.root()) |
| | | |
| | | |
| | | def main(global_config, **settings): |
| | | """ This function returns a WSGI application. |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | authn_policy = AuthTktAuthenticationPolicy( |
| | | 'sosecret', callback=groupfinder, hashalg='sha512') |
| | |
| | | self.assertEqual(wiki.__name__, None) |
| | | |
| | | class AppmakerTests(unittest.TestCase): |
| | | |
| | | def _callFUT(self, zodb_root): |
| | | from .models import appmaker |
| | | return appmaker(zodb_root) |
| | |
| | | info = self._callFUT(context, request) |
| | | self.assertEqual(info['page'], context) |
| | | self.assertEqual( |
| | | info['content'], |
| | | info['content'], |
| | | '<div class="document">\n' |
| | | '<p>Hello <a href="http://example.com/add_page/CruelWorld">' |
| | | 'CruelWorld</a> ' |
| | |
| | | request.subpath = ['AnotherPage'] |
| | | info = self._callFUT(context, request) |
| | | self.assertEqual(info['page'].data,'') |
| | | self.assertEqual(info['save_url'], |
| | | request.resource_url( |
| | | context, 'add_page', 'AnotherPage')) |
| | | self.assertEqual( |
| | | info['save_url'], |
| | | request.resource_url(context, 'add_page', 'AnotherPage')) |
| | | |
| | | def test_it_submitted(self): |
| | | context = testing.DummyResource() |
| | |
| | | page.__name__ = pagename |
| | | page.__parent__ = context |
| | | |
| | | return dict(page = page, save_url = save_url, |
| | | logged_in = authenticated_userid(request)) |
| | | return dict(page=page, save_url=save_url, |
| | | logged_in=authenticated_userid(request)) |
| | | |
| | | @view_config(name='edit_page', context='.models.Page', |
| | | renderer='templates/edit.pt', |
| | |
| | | context.data = request.params['body'] |
| | | return HTTPFound(location = request.resource_url(context)) |
| | | |
| | | return dict(page = context, |
| | | save_url = request.resource_url(context, 'edit_page'), |
| | | logged_in = authenticated_userid(request)) |
| | | return dict(page=context, |
| | | save_url=request.resource_url(context, 'edit_page'), |
| | | logged_in=authenticated_userid(request)) |
| | | |
| | | @view_config(context='.models.Wiki', name='login', |
| | | renderer='templates/login.pt') |
| | |
| | | setup(name='tutorial', |
| | | version='0.0', |
| | | description='tutorial', |
| | | long_description=README + '\n\n' + CHANGES, |
| | | long_description=README + '\n\n' + CHANGES, |
| | | classifiers=[ |
| | | "Programming Language :: Python", |
| | | "Framework :: Pyramid", |
| | |
| | | packages=find_packages(), |
| | | include_package_data=True, |
| | | zip_safe=False, |
| | | install_requires = requires, |
| | | tests_require= requires, |
| | | install_requires=requires, |
| | | tests_require=requires, |
| | | test_suite="tutorial", |
| | | entry_points = """\ |
| | | entry_points="""\ |
| | | [paste.app_factory] |
| | | main = tutorial:main |
| | | """, |
| | | ) |
| | | |
| | |
| | | from pyramid_zodbconn import get_connection |
| | | from .models import appmaker |
| | | |
| | | |
| | | def root_factory(request): |
| | | conn = get_connection(request) |
| | | return appmaker(conn.root()) |
| | | |
| | | |
| | | def main(global_config, **settings): |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | |
| | | from persistent.mapping import PersistentMapping |
| | | |
| | | |
| | | class MyModel(PersistentMapping): |
| | | __parent__ = __name__ = None |
| | | |
| | | |
| | | def appmaker(zodb_root): |
| | | if not 'app_root' in zodb_root: |
| | | app_root = MyModel() |
| | |
| | | request = testing.DummyRequest() |
| | | info = my_view(request) |
| | | self.assertEqual(info['project'], 'tutorial') |
| | | |
| | |
| | | from pyramid.view import view_config |
| | | from .models import MyModel |
| | | |
| | | |
| | | @view_config(context=MyModel, renderer='templates/mytemplate.pt') |
| | | def my_view(request): |
| | | return {'project':'tutorial'} |
| | | return {'project': 'tutorial'} |
| | |
| | | setup(name='tutorial', |
| | | version='0.0', |
| | | description='tutorial', |
| | | long_description=README + '\n\n' + CHANGES, |
| | | long_description=README + '\n\n' + CHANGES, |
| | | classifiers=[ |
| | | "Programming Language :: Python", |
| | | "Framework :: Pyramid", |
| | |
| | | packages=find_packages(), |
| | | include_package_data=True, |
| | | zip_safe=False, |
| | | install_requires = requires, |
| | | tests_require= requires, |
| | | install_requires=requires, |
| | | tests_require=requires, |
| | | test_suite="tutorial", |
| | | entry_points = """\ |
| | | entry_points="""\ |
| | | [paste.app_factory] |
| | | main = tutorial:main |
| | | """, |
| | | ) |
| | | |
| | |
| | | from pyramid_zodbconn import get_connection |
| | | from .models import appmaker |
| | | |
| | | |
| | | def root_factory(request): |
| | | conn = get_connection(request) |
| | | return appmaker(conn.root()) |
| | | |
| | | |
| | | def main(global_config, **settings): |
| | | """ This function returns a WSGI application. |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | config = Configurator(root_factory=root_factory, settings=settings) |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | from pyramid.view import view_config |
| | | from .models import MyModel |
| | | |
| | | @view_config(renderer='templates/mytemplate.pt') |
| | | |
| | | @view_config(context=MyModel, renderer='templates/mytemplate.pt') |
| | | def my_view(request): |
| | | return {'project':'tutorial'} |
| | | return {'project': 'tutorial'} |
| | |
| | | setup(name='tutorial', |
| | | version='0.0', |
| | | description='tutorial', |
| | | long_description=README + '\n\n' + CHANGES, |
| | | long_description=README + '\n\n' + CHANGES, |
| | | classifiers=[ |
| | | "Programming Language :: Python", |
| | | "Framework :: Pyramid", |
| | |
| | | packages=find_packages(), |
| | | include_package_data=True, |
| | | zip_safe=False, |
| | | install_requires = requires, |
| | | tests_require= requires, |
| | | install_requires=requires, |
| | | tests_require=requires, |
| | | test_suite="tutorial", |
| | | entry_points = """\ |
| | | entry_points="""\ |
| | | [paste.app_factory] |
| | | main = tutorial:main |
| | | """, |
| | | ) |
| | | |
| | |
| | | conn = get_connection(request) |
| | | return appmaker(conn.root()) |
| | | |
| | | |
| | | def main(global_config, **settings): |
| | | """ This function returns a WSGI application. |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | authn_policy = AuthTktAuthenticationPolicy( |
| | | 'sosecret', callback=groupfinder, hashalg='sha512') |
| | |
| | | self.assertEqual(wiki.__name__, None) |
| | | |
| | | class AppmakerTests(unittest.TestCase): |
| | | |
| | | def _callFUT(self, zodb_root): |
| | | from .models import appmaker |
| | | return appmaker(zodb_root) |
| | |
| | | page.__name__ = pagename |
| | | page.__parent__ = context |
| | | |
| | | return dict(page = page, save_url = save_url, |
| | | logged_in = authenticated_userid(request)) |
| | | return dict(page=page, save_url=save_url, |
| | | logged_in=authenticated_userid(request)) |
| | | |
| | | @view_config(name='edit_page', context='.models.Page', |
| | | renderer='templates/edit.pt', |
| | |
| | | context.data = request.params['body'] |
| | | return HTTPFound(location = request.resource_url(context)) |
| | | |
| | | return dict(page = context, |
| | | save_url = request.resource_url(context, 'edit_page'), |
| | | logged_in = authenticated_userid(request)) |
| | | return dict(page=context, |
| | | save_url=request.resource_url(context, 'edit_page'), |
| | | logged_in=authenticated_userid(request)) |
| | | |
| | | @view_config(context='.models.Wiki', name='login', |
| | | renderer='templates/login.pt') |
| | |
| | | setup(name='tutorial', |
| | | version='0.0', |
| | | description='tutorial', |
| | | long_description=README + '\n\n' + CHANGES, |
| | | long_description=README + '\n\n' + CHANGES, |
| | | classifiers=[ |
| | | "Programming Language :: Python", |
| | | "Framework :: Pyramid", |
| | |
| | | packages=find_packages(), |
| | | include_package_data=True, |
| | | zip_safe=False, |
| | | install_requires = requires, |
| | | tests_require= requires, |
| | | install_requires=requires, |
| | | tests_require=requires, |
| | | test_suite="tutorial", |
| | | entry_points = """\ |
| | | entry_points="""\ |
| | | [paste.app_factory] |
| | | main = tutorial:main |
| | | """, |
| | | ) |
| | | |
| | |
| | | from pyramid.config import Configurator |
| | | from pyramid_zodbconn import get_connection |
| | | from tutorial.models import appmaker |
| | | from .models import appmaker |
| | | |
| | | |
| | | def root_factory(request): |
| | | conn = get_connection(request) |
| | | return appmaker(conn.root()) |
| | | |
| | | |
| | | def main(global_config, **settings): |
| | | """ This function returns a WSGI application. |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | config = Configurator(root_factory=root_factory, settings=settings) |
| | | config.add_static_view('static', 'static', cache_max_age=3600) |
| | | config.scan('tutorial') |
| | | config.scan() |
| | | return config.make_wsgi_app() |
| | |
| | | class PageModelTests(unittest.TestCase): |
| | | |
| | | def _getTargetClass(self): |
| | | from tutorial.models import Page |
| | | from .models import Page |
| | | return Page |
| | | |
| | | def _makeOne(self, data=u'some data'): |
| | |
| | | def test_constructor(self): |
| | | instance = self._makeOne() |
| | | self.assertEqual(instance.data, u'some data') |
| | | |
| | | |
| | | class WikiModelTests(unittest.TestCase): |
| | | |
| | | def _getTargetClass(self): |
| | | from tutorial.models import Wiki |
| | | from .models import Wiki |
| | | return Wiki |
| | | |
| | | def _makeOne(self): |
| | |
| | | self.assertEqual(wiki.__name__, None) |
| | | |
| | | class AppmakerTests(unittest.TestCase): |
| | | |
| | | def _callFUT(self, zodb_root): |
| | | from tutorial.models import appmaker |
| | | from .models import appmaker |
| | | return appmaker(zodb_root) |
| | | |
| | | def test_it(self): |
| | |
| | | |
| | | class ViewWikiTests(unittest.TestCase): |
| | | def test_it(self): |
| | | from tutorial.views import view_wiki |
| | | from .views import view_wiki |
| | | context = testing.DummyResource() |
| | | request = testing.DummyRequest() |
| | | response = view_wiki(context, request) |
| | |
| | | |
| | | class ViewPageTests(unittest.TestCase): |
| | | def _callFUT(self, context, request): |
| | | from tutorial.views import view_page |
| | | from .views import view_page |
| | | return view_page(context, request) |
| | | |
| | | def test_it(self): |
| | |
| | | info = self._callFUT(context, request) |
| | | self.assertEqual(info['page'], context) |
| | | self.assertEqual( |
| | | info['content'], |
| | | info['content'], |
| | | '<div class="document">\n' |
| | | '<p>Hello <a href="http://example.com/add_page/CruelWorld">' |
| | | 'CruelWorld</a> ' |
| | |
| | | '</p>\n</div>\n') |
| | | self.assertEqual(info['edit_url'], |
| | | 'http://example.com/thepage/edit_page') |
| | | |
| | | |
| | | |
| | | |
| | | class AddPageTests(unittest.TestCase): |
| | | def _callFUT(self, context, request): |
| | | from tutorial.views import add_page |
| | | from .views import add_page |
| | | return add_page(context, request) |
| | | |
| | | def test_it_notsubmitted(self): |
| | |
| | | self.assertEqual( |
| | | info['save_url'], |
| | | request.resource_url(context, 'add_page', 'AnotherPage')) |
| | | |
| | | |
| | | def test_it_submitted(self): |
| | | context = testing.DummyResource() |
| | | request = testing.DummyRequest({'form.submitted':True, |
| | |
| | | |
| | | class EditPageTests(unittest.TestCase): |
| | | def _callFUT(self, context, request): |
| | | from tutorial.views import edit_page |
| | | from .views import edit_page |
| | | return edit_page(context, request) |
| | | |
| | | def test_it_notsubmitted(self): |
| | |
| | | self.assertEqual(info['page'], context) |
| | | self.assertEqual(info['save_url'], |
| | | request.resource_url(context, 'edit_page')) |
| | | |
| | | |
| | | def test_it_submitted(self): |
| | | context = testing.DummyResource() |
| | | request = testing.DummyRequest({'form.submitted':True, |
| | |
| | | context.data = request.params['body'] |
| | | return HTTPFound(location = request.resource_url(context)) |
| | | |
| | | return dict(page = context, |
| | | save_url = request.resource_url(context, 'edit_page')) |
| | | return dict(page=context, |
| | | save_url=request.resource_url(context, 'edit_page')) |