Commits

percious  committed d047351

fixes for pylons 0.10

  • Participants
  • Parent commits 2de9f0f

Comments (0)

Files changed (6)

File tg/controllers/dispatcher.py

         applicable method, so therefore we head back up the branches of the
         tree until we found a method which matches with a default or lookup method.
         """
-        
+
         orig_remainder_len = len(remainder)
         current_controller = state.controller
 
         This method defines how the object dispatch mechanism works, including
         checking for security along the way.
         """
-        
+
         current_controller = state.controller
 
         if hasattr(current_controller, '_check_security'):
             return self._dispatch_first_found_default_or_lookup(state, remainder)
 
         current_path = remainder[0]
-        
+
         #an exposed method matching the path is found
         if self._is_exposed(current_controller, current_path):
             #check to see if the argspec jives

File tg/test_stack/__init__.py

                     templates=[os.path.join(test_config_path, 'templates')],
                     i18n=os.path.join(test_config_path, 'i18n')
                     )
+        print test_config_path
 
         #Then we overide those values with what was passed in
         for key, value in values.items():

File tg/test_stack/dispatch/test_url_dispatch.py

     return app_from_config(base_config)
 
 
-app = setup_noDB()
+app = None
+def setup():
+    global app
+    app = setup_noDB()
 
 @no_warn #should be _default now
 def test_tg_style_default():

File tg/test_stack/rendering/controllers/root.py

 #then, we create an instance of this form
 base_movie_form = MovieForm("movie_form", action='create')
 
+
+class GoodJsonObject(object):
+    def __json__(self):
+        return {'Json':'Rocks'}
+
+class BadJsonObject(object):
+    pass
+
+class JsonController(TGController):
+
+    @expose('json')
+    def json(self):
+        return dict(a='hello world', b=True)
+
+    @expose('json', exclude_names=["b"])
+    def excluded_b(self):
+        return dict(a="visible", b="invisible")
+
+    @expose('json')
+    @expose('genshi:test', content_type='application/xml')
+    def xml_or_json(self):
+        return dict(name="John Carter", title='officer', status='missing')
+
+    @expose('json')
+    def json_with_object(self):
+        return dict(obj=GoodJsonObject())
+
+    @expose('json')
+    def json_with_bad_object(self):
+        return dict(obj=BadJsonObject())
+
 class RootController(TGController):
+
+    j = JsonController()
+
     @expose('genshi:index.html')
     def index(self):
         return {}

File tg/test_stack/rendering/test_decorators.py

+from tg.test_stack import TestConfig, app_from_config
+from tg.util import Bunch
+from webtest import TestApp
+from pylons import tmpl_context
+from tg.util import no_warn
+
+def make_app():
+    base_config = TestConfig(folder = 'rendering',
+                             values = {'use_sqlalchemy': False,
+                                       'pylons.helpers': Bunch(),
+                                       'use_legacy_renderer': False,
+                                       # this is specific to mako
+                                       # to make sure inheritance works
+                                       'use_dotted_templatenames': False,
+                                       'pylons.tmpl_context_attach_args': False
+
+                                       }
+                             )
+    return app_from_config(base_config)
+
+app = None
+def setup():
+    global app
+    app = make_app()
+
+class TestTGController():
+
+    def setup(self):
+        self.app = app
+
+    def test_simple_jsonification(self):
+        resp = self.app.get('/j/json')
+        assert '{"a": "hello world", "b": true}' in resp.body
+
+    def test_multi_dispatch_json(self):
+        resp = self.app.get('/j/xml_or_json', headers={'accept':'application/json'})
+        assert '''"status": "missing"''' in resp
+        assert '''"name": "John Carter"''' in resp
+        assert '''"title": "officer"''' in resp
+
+    def test_json_with_object(self):
+        resp = self.app.get('/j/json_with_object')
+        assert '''"Json": "Rocks"''' in resp.body
+
+    @no_warn
+    def test_json_with_bad_object(self):
+        try:
+            resp = self.app.get('/j/json_with_bad_object')
+        except TypeError, e:
+            pass
+        assert "is not JSON serializable" in str(e), str(e)

File tg/tests/test_decorators.py

-# -*- coding: utf-8 -*-
-import paste.httpexceptions as httpexceptions
-
-import tg
-from tg.util import no_warn
-import pylons
-from tg.controllers import TGController
-from tg.decorators import expose
-
-from tg.tests.base import TestWSGIController, make_app, setup_session_dir, teardown_session_dir
-
-
-def setup():
-    setup_session_dir()
-def teardown():
-    teardown_session_dir()
-
-class GoodJsonObject(object):
-    def __json__(self):
-        return {'Json':'Rocks'} 
-
-class BadJsonObject(object):
-    pass
-
-class BasicTGController(TGController):
-
-    @expose('json')
-    def json(self):
-        return dict(a='hello world', b=True)
-
-    @expose('json', exclude_names=["b"])
-    def excluded_b(self):
-        return dict(a="visible", b="invisible")
-
-    @expose('json')
-    @expose('genshi:test', content_type='application/xml')
-    def xml_or_json(self):
-        return dict(name="John Carter", title='officer', status='missing')
-
-    @expose('json')
-    def json_with_object(self):
-        return dict(obj=GoodJsonObject())
-
-    @expose('json')
-    def json_with_bad_object(self):
-        return dict(obj=BadJsonObject())
-
-class TestTGController(TestWSGIController):
-    def __init__(self, *args, **kargs):
-        TestWSGIController.__init__(self, *args, **kargs)
-        self.app = make_app(BasicTGController)
-
-    def test_simple_jsonification(self):
-        resp = self.app.get('/json')
-        assert '{"a": "hello world", "b": true}' in resp.body
-
-    def test_multi_dispatch_json(self):
-        resp = self.app.get('/xml_or_json', headers={'accept':'application/json'})
-        assert '''"status": "missing"''' in resp
-        assert '''"name": "John Carter"''' in resp
-        assert '''"title": "officer"''' in resp
-    
-    #TODO: Setup genshi search path, and test genshi rendering
-    
-    #TODO: Add tests for 
-
-    def test_json_with_object(self):
-        resp = self.app.get('/json_with_object')
-        assert '''"Json": "Rocks"''' in resp.body
-    
-    @no_warn
-    def test_json_with_bad_object(self):
-        try:
-            resp = self.app.get('/json_with_bad_object')
-        except TypeError, e:
-            pass
-        assert "is not JSON serializable" in str(e)