Skip to content

Commit

Permalink
[svn] tests for deprecated pylons.jsonify, Controller h
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
pjenvey committed Feb 17, 2007
1 parent 5e13ec9 commit db40d73
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/test_units/test_deprecated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from unittest import TestCase

from paste.wsgiwrappers import WSGIRequest

import pylons
from pylons import Controller
from pylons.util import ContextObj

class OldController(Controller):
def index(self):
return 'old'

class TestDeprecatedControllerImport(TestCase):
def setUp(self):
self.environ = {'pylons.routes_dict':dict(action='index'),
'paste.config':dict(global_conf=dict(debug=True))}
pylons.request._push_object(WSGIRequest(self.environ))
pylons.c._push_object(ContextObj())
self.controller = OldController()
self.controller.start_response = None

def test_index(self):
assert 'old' == self.controller()

from paste.fixture import TestApp
from paste.registry import RegistryManager

from pylons import jsonify
from pylons.decorators import jsonify as orig_jsonify
from pylons.controllers import WSGIController

from __init__ import ControllerWrap, SetupCacheGlobal, TestWSGIController

class SimpleTestWSGIController(TestWSGIController):
wsgi_app = None
def __init__(self, *args, **kargs):
TestWSGIController.__init__(self, *args, **kargs)
self.baseenviron = {}
app = ControllerWrap(self.wsgi_app)
app = self.sap = SetupCacheGlobal(app, self.baseenviron, setup_cache=False)
app = RegistryManager(app)
self.app = TestApp(app)

def setUp(self):
TestWSGIController.setUp(self)
self.baseenviron.update(self.environ)

class JsonifyController(WSGIController):
def index(self):
return {'iam': 'deprecated'}
index = jsonify(index)

class TestDeprecatedJsonify(SimpleTestWSGIController):
wsgi_app = JsonifyController
def test_wsgi_call(self):
resp = self.get_response()
assert '{"iam": "deprecated"}' in resp
assert orig_jsonify.__doc__ in jsonify.__doc__
4 changes: 4 additions & 0 deletions tests/test_webapps/filestotest/controller_sample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from projectname.lib.base import *
from pylons.decorators import rest
from pylons.i18n import get_lang, set_lang, LanguageError
from pylons import h as deprecated_h

class SampleController(BaseController):
def index(self):
Expand Down Expand Up @@ -76,3 +77,6 @@ def no_lang(self):
resp.write(_('No languages'))
return resp

def deprecated_h(self):
return Response('%s is %s' % \
(h.url_for(), deprecated_h.url_for()))
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ def test_params(self):
assert 'extra' in response
assert 'something' in response
assert 'data' in response

def test_deprecated_h(self):
response = self.app.get(url_for(controller='/sample', action='deprecated_h'))
assert '/sample/deprecated_h is /sample/deprecated_h' in response

0 comments on commit db40d73

Please sign in to comment.