| | |
| | | import unittest |
| | | from pyramid import testing |
| | | |
| | | from pyramid.tests.test_config import IDummy |
| | | from . import IDummy |
| | | |
| | | from pyramid.tests.test_config import dummy_view |
| | | from . import dummy_view |
| | | |
| | | from pyramid.compat import ( |
| | | im_func, |
| | |
| | | def test_add_view_view_callable_dottedname(self): |
| | | from pyramid.renderers import null_renderer |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view(view='pyramid.tests.test_config.dummy_view', |
| | | config.add_view(view='tests.test_config.dummy_view', |
| | | renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config) |
| | | self.assertEqual(wrapper(None, None), 'OK') |
| | |
| | | from pyramid.renderers import null_renderer |
| | | view = lambda *arg: 'OK' |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view(context='pyramid.tests.test_config.IDummy', |
| | | config.add_view(context='tests.test_config.IDummy', |
| | | view=view, renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config, IDummy) |
| | | self.assertEqual(wrapper, view) |
| | |
| | | from pyramid.renderers import null_renderer |
| | | view = lambda *arg: 'OK' |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view(for_='pyramid.tests.test_config.IDummy', |
| | | config.add_view(for_='tests.test_config.IDummy', |
| | | view=view, renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config, IDummy) |
| | | self.assertEqual(wrapper, view) |
| | |
| | | ) |
| | | |
| | | def test_add_view_with_template_renderer(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | from pyramid.interfaces import ISettings |
| | | class view(object): |
| | | def __init__(self, context, request): |
| | |
| | | return {'a':'1'} |
| | | config = self._makeOne(autocommit=True) |
| | | renderer = self._registerRenderer(config) |
| | | fixture = 'pyramid.tests.test_config:files/minimal.txt' |
| | | fixture = 'tests.test_config:files/minimal.txt' |
| | | config.introspection = False |
| | | config.add_view(view=view, renderer=fixture) |
| | | wrapper = self._getViewCallable(config) |
| | |
| | | self.assertEqual(result.body, b'moo') |
| | | |
| | | def test_add_view_with_template_renderer_no_callable(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | from pyramid.interfaces import ISettings |
| | | config = self._makeOne(autocommit=True) |
| | | renderer = self._registerRenderer(config) |
| | | fixture = 'pyramid.tests.test_config:files/minimal.txt' |
| | | fixture = 'tests.test_config:files/minimal.txt' |
| | | config.introspection = False |
| | | config.add_view(view=None, renderer=fixture) |
| | | wrapper = self._getViewCallable(config) |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view( |
| | | view=view, |
| | | containment='pyramid.tests.test_config.IDummy', |
| | | containment='tests.test_config.IDummy', |
| | | renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config) |
| | | context = DummyContext() |
| | |
| | | from zope.interface import directlyProvides |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |
| | |
| | | from zope.interface import directlyProvides |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view( |
| | | view='pyramid.tests.test_config.test_views.DummyViewDefaultsClass', |
| | | view='tests.test_config.test_views.DummyViewDefaultsClass', |
| | | renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config) |
| | | context = DummyContext() |
| | |
| | | from zope.interface import directlyProvides |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view( |
| | | 'pyramid.tests.test_config.test_views.DummyViewDefaultsClass', |
| | | 'tests.test_config.test_views.DummyViewDefaultsClass', |
| | | renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config) |
| | | context = DummyContext() |
| | |
| | | from pyramid.renderers import null_renderer |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | class view2(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IFactory' |
| | | 'containment':'tests.test_config.IFactory' |
| | | } |
| | | config = self._makeOne(autocommit=False) |
| | | config.add_view( |
| | |
| | | from pyramid.renderers import null_renderer |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | class view2(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | config = self._makeOne(autocommit=False) |
| | | config.add_view( |
| | |
| | | from zope.interface import implementedBy |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment': 'pyramid.tests.test_config.IDummy' |
| | | 'containment': 'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |
| | |
| | | from pyramid.renderers import null_renderer |
| | | config = self._makeOne() |
| | | result = config.derive_view( |
| | | 'pyramid.tests.test_config.dummy_view', |
| | | 'tests.test_config.dummy_view', |
| | | renderer=null_renderer) |
| | | self.assertFalse(result is dummy_view) |
| | | self.assertEqual(result(None, None), 'OK') |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | config.registry.registerUtility(info, IStaticURLInfo) |
| | | config.add_static_view('static', |
| | | 'pyramid.tests.test_config:files') |
| | | 'tests.test_config:files') |
| | | self.assertEqual( |
| | | info.added, |
| | | [(config, 'static', 'pyramid.tests.test_config:files', {})]) |
| | | [(config, 'static', 'tests.test_config:files', {})]) |
| | | |
| | | def test_add_static_view_package_here_relative(self): |
| | | from pyramid.interfaces import IStaticURLInfo |
| | |
| | | config.add_static_view('static', 'files') |
| | | self.assertEqual( |
| | | info.added, |
| | | [(config, 'static', 'pyramid.tests.test_config:files', {})]) |
| | | [(config, 'static', 'tests.test_config:files', {})]) |
| | | |
| | | def test_add_static_view_absolute(self): |
| | | import os |
| | |
| | | from zope.interface import implementedBy |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |
| | |
| | | from zope.interface import implementedBy |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |
| | |
| | | def test_set_view_mapper_dottedname(self): |
| | | from pyramid.interfaces import IViewMapperFactory |
| | | config = self._makeOne(autocommit=True) |
| | | config.set_view_mapper('pyramid.tests.test_config') |
| | | config.set_view_mapper('tests.test_config') |
| | | result = config.registry.getUtility(IViewMapperFactory) |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | self.assertEqual(result, test_config) |
| | | |
| | | def test_add_normal_and_exception_view_intr_derived_callable(self): |
| | |
| | | request = testing.DummyRequest() |
| | | config.add_static_view('static', 'path') |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config:path/', |
| | | 'pyramid.tests.test_config:other_path/') |
| | | 'tests.test_config:path/', |
| | | 'tests.test_config:other_path/') |
| | | def cb(val): |
| | | def cb_(request, subpath, kw): |
| | | kw['_query'] = {'x': val} |
| | |
| | | def view(): pass |
| | | result = self._callFUT(view) |
| | | self.assertEqual(result, |
| | | 'function pyramid.tests.test_config.test_views.view') |
| | | 'function tests.test_config.test_views.view') |
| | | |
| | | class Test_viewdefaults(unittest.TestCase): |
| | | def _makeOne(self, wrapped): |
| | |
| | | |
| | | class DummyViewDefaultsClass(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |