Permalink
Browse files

fix tests post mako/chameleon removal

  • Loading branch information...
1 parent 7282f30 commit 128e0791ed6b66b2ac4c8d2ea34448663f0434b4 @reedobrien reedobrien committed Mar 13, 2012
@@ -1,8 +1,13 @@
from pyramid.view import view_config
-@view_config(name='one', renderer='one.pt')
+@view_config(name='one', renderer='string')
def one(request):
- return {'name':'One!'}
+ return 'One!'
+
+
+@view_config(name='two', renderer='string')
+def two(request):
+ return 'Two!'
def includeme(config):
config.scan()
@@ -1,4 +0,0 @@
-<div xmlns="http://www.w3.org/1999/xhtml"
- xmlns:tal="http://xml.zope.org/namespaces/tal">
- ${name}
-</div>
@@ -1,6 +0,0 @@
-from pyramid.view import view_config
-
-@view_config(name='two', renderer='two.pt')
-def two(request):
- return {'nameagain':'Two!'}
-
@@ -1,4 +0,0 @@
-<div xmlns="http://www.w3.org/1999/xhtml"
- xmlns:tal="http://xml.zope.org/namespaces/tal">
- ${nameagain}
-</div>
@@ -1,3 +0,0 @@
-<html>
-${result}
-</html>
@@ -1,11 +1,11 @@
from pyramid.view import view_config
-@view_config(renderer='templates/foo.mak', name='first')
+@view_config(renderer='string', name='first')
def first(request):
return {'result':'OK1'}
@view_config(
- renderer='pyramid.tests.pkgs.viewdecoratorapp.views:templates/foo.mak',
+ renderer='string',
name='second')
def second(request):
return {'result':'OK2'}
@@ -42,13 +42,10 @@ def test_add_translation_dirs_missing_dir(self):
def test_add_translation_dirs_no_specs(self):
from pyramid.interfaces import ITranslationDirectories
- from pyramid.interfaces import IChameleonTranslate
config = self._makeOne()
config.add_translation_dirs()
self.assertEqual(config.registry.queryUtility(ITranslationDirectories),
None)
- self.assertEqual(config.registry.queryUtility(IChameleonTranslate),
- None)
def test_add_translation_dirs_asset_spec(self):
from pyramid.interfaces import ITranslationDirectories
@@ -83,19 +80,6 @@ def test_add_translation_dirs_multiple_specs_multiple_calls(self):
self.assertEqual(config.registry.getUtility(ITranslationDirectories),
[locale3, locale, locale2])
- def test_add_translation_dirs_registers_chameleon_translate(self):
- from pyramid.interfaces import IChameleonTranslate
- from pyramid.threadlocal import manager
- request = DummyRequest()
- config = self._makeOne(autocommit=True)
- manager.push({'request':request, 'registry':config.registry})
- try:
- config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale')
- translate = config.registry.getUtility(IChameleonTranslate)
- self.assertEqual(translate('Approve'), 'Approve')
- finally:
- manager.pop()
-
def test_add_translation_dirs_abspath(self):
from pyramid.interfaces import ITranslationDirectories
config = self._makeOne(autocommit=True)
@@ -1307,16 +1307,18 @@ def test_add_route_with_for_(self):
wrapper = self._getViewCallable(config, IOther, request_type)
self.assertEqual(wrapper, None)
+ ## ???: Maybe this should not be here since we don't have template renderers
+ ## ???: Dunno if this us useful with a string renderer
def test_add_route_with_view_renderer(self):
config = self._makeOne(autocommit=True)
self._registerRenderer(config)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view,
- view_renderer='files/minimal.txt')
+ view_renderer='string')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
self._assertRoute(config, 'name', 'path')
- self.assertEqual(wrapper(None, None).body, b'Hello!')
+ self.assertEqual(wrapper(None, None).body, b'OK')
def test_add_route_with_view_attr(self):
from pyramid.renderers import null_renderer
@@ -1335,17 +1337,6 @@ def alt(self):
request = self._makeRequest(config)
self.assertEqual(wrapper(None, request), 'OK')
- def test_add_route_with_view_renderer_alias(self):
- config = self._makeOne(autocommit=True)
- self._registerRenderer(config)
- view = lambda *arg: 'OK'
- config.add_route('name', 'path', view=view,
- renderer='files/minimal.txt')
- request_type = self._getRouteRequestIface(config, 'name')
- wrapper = self._getViewCallable(config, None, request_type)
- self._assertRoute(config, 'name', 'path')
- self.assertEqual(wrapper(None, None).body, b'Hello!')
-
def test_add_route_with_view_permission(self):
from pyramid.interfaces import IAuthenticationPolicy
from pyramid.interfaces import IAuthorizationPolicy
@@ -961,32 +961,6 @@ class Bar(object):
self.assertEqual(wrapper.__discriminator__(foo, request)[5], IFoo)
self.assertEqual(wrapper.__discriminator__(bar, request)[5], IBar)
- def test_add_view_with_template_renderer(self):
- from pyramid.tests import test_config
- from pyramid.interfaces import ISettings
- class view(object):
- def __init__(self, context, request):
- self.request = request
- self.context = context
-
- def __call__(self):
- return {'a':'1'}
- config = self._makeOne(autocommit=True)
- renderer = self._registerRenderer(config)
- fixture = 'pyramid.tests.test_config:files/minimal.txt'
- config.add_view(view=view, renderer=fixture)
- wrapper = self._getViewCallable(config)
- request = self._makeRequest(config)
- result = wrapper(None, request)
- self.assertEqual(result.body, b'Hello!')
- settings = config.registry.queryUtility(ISettings)
- result = renderer.info
- self.assertEqual(result.registry, config.registry)
- self.assertEqual(result.type, '.txt')
- self.assertEqual(result.package, test_config)
- self.assertEqual(result.name, fixture)
- self.assertEqual(result.settings, settings)
-
def test_add_view_with_default_renderer(self):
class view(object):
def __init__(self, context, request):
@@ -1008,25 +982,6 @@ def __call__(self, *arg, **kw):
result = wrapper(None, request)
self.assertEqual(result.body, b'moo')
- def test_add_view_with_template_renderer_no_callable(self):
- from pyramid.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'
- config.add_view(view=None, renderer=fixture)
- wrapper = self._getViewCallable(config)
- request = self._makeRequest(config)
- result = wrapper(None, request)
- self.assertEqual(result.body, b'Hello!')
- settings = config.registry.queryUtility(ISettings)
- result = renderer.info
- self.assertEqual(result.registry, config.registry)
- self.assertEqual(result.type, '.txt')
- self.assertEqual(result.package, test_config)
- self.assertEqual(result.name, fixture)
- self.assertEqual(result.settings, settings)
-
def test_add_view_with_request_type_as_iface(self):
from pyramid.renderers import null_renderer
from zope.interface import directlyProvides
@@ -1710,19 +1665,21 @@ def view(request): return Response('OK')
request_iface=IRequest)
result = view(None, request)
self.assertEqual(result.location, '/scriptname/foo/?a=1&b=2')
-
+
def test_add_notfound_view_with_renderer(self):
from zope.interface import implementedBy
from pyramid.interfaces import IRequest
+ from pyramid.response import Response
from pyramid.httpexceptions import HTTPNotFound
config = self._makeOne(autocommit=True)
- view = lambda *arg: {}
+ view = lambda *arg: 'div'
config.add_notfound_view(
view,
- renderer='pyramid.tests.test_config:files/minimal.pt')
+ renderer='string')
config.begin()
- try: # chameleon depends on being able to find a threadlocal registry
+ try:
request = self._makeRequest(config)
+ request.response = Response()
view = self._getViewCallable(config,
ctx_iface=implementedBy(HTTPNotFound),
request_iface=IRequest)
@@ -1734,18 +1691,20 @@ def test_add_notfound_view_with_renderer(self):
def test_add_forbidden_view_with_renderer(self):
from zope.interface import implementedBy
from pyramid.interfaces import IRequest
+ from pyramid.response import Response
from pyramid.httpexceptions import HTTPForbidden
config = self._makeOne(autocommit=True)
- view = lambda *arg: {}
+ view = lambda *arg: 'div'
config.add_forbidden_view(
view,
- renderer='pyramid.tests.test_config:files/minimal.pt')
+ renderer='string')
config.begin()
- try: # chameleon requires a threadlocal registry
+ try:
request = self._makeRequest(config)
view = self._getViewCallable(config,
ctx_iface=implementedBy(HTTPForbidden),
request_iface=IRequest)
+ request.response = Response()
result = view(None, request)
finally:
config.end()
@@ -578,26 +578,28 @@ def test_hello(self):
res = self.testapp.get('/hello', status=200)
self.assertTrue(b'Hello' in res.body)
-if os.name != 'java': # uses chameleon
- class RendererScanAppTest(IntegrationBase, unittest.TestCase):
- package = 'pyramid.tests.pkgs.rendererscanapp'
- def test_root(self):
- res = self.testapp.get('/one', status=200)
- self.assertTrue(b'One!' in res.body)
-
- def test_two(self):
- res = self.testapp.get('/two', status=200)
- self.assertTrue(b'Two!' in res.body)
-
- def test_rescan(self):
- self.config.scan('pyramid.tests.pkgs.rendererscanapp')
- app = self.config.make_wsgi_app()
- from webtest import TestApp
- testapp = TestApp(app)
- res = testapp.get('/one', status=200)
- self.assertTrue(b'One!' in res.body)
- res = testapp.get('/two', status=200)
- self.assertTrue(b'Two!' in res.body)
+
+class RendererScanAppTest(IntegrationBase, unittest.TestCase):
+ package = 'pyramid.tests.pkgs.rendererscanapp'
+
+ def test_root(self):
+ res = self.testapp.get('/one', status=200)
+ self.assertTrue(b'One!' in res.body)
+
+ def test_two(self):
+ res = self.testapp.get('/two', status=200)
+ self.assertTrue(b'Two!' in res.body)
+
+ def test_rescan(self):
+ self.config.scan('pyramid.tests.pkgs.rendererscanapp')
+ app = self.config.make_wsgi_app()
+ from webtest import TestApp
+ testapp = TestApp(app)
+ res = testapp.get('/one', status=200)
+ self.assertTrue(b'One!' in res.body)
+ res = testapp.get('/two', status=200)
+ self.assertTrue(b'Two!' in res.body)
+
class DummyContext(object):
pass

0 comments on commit 128e079

Please sign in to comment.