Skip to content
Browse files

fixed tests, hacked in amf (this needs to be cleaner).

  • Loading branch information...
1 parent 38b8a2f commit 372db82609264e649e26f7741b11bfbb2d8aa16c percious committed Sep 9, 2009
View
23 tg/amfify.py
@@ -0,0 +1,23 @@
+try:
+ from pyamf.remoting.gateway.wsgi import WSGIGateway
+
+except:
+ print 'You must easy_install pyamf for to use amf renderer'
+ raise
+from pylons import request
+
+def render_amf(template_name, template_vars, **kwargs):
+ assert 0
+ # somehow we need to dummy out the services here, but im not sure how
+ # yet
+ def dummy(*args, **kw):
+ return template_vars
+ services = {
+ 'something.method': dummy,
+ }
+
+ # setup our server
+ app = WSGIGateway(services)
+ def start_request(*args, **kw):pass
+ r = app(request.environ, start_request)
+ return r
View
7 tg/configuration.py
@@ -352,6 +352,10 @@ def setup_jinja_renderer(self):
self.render_functions.jinja = render_jinja
+ def setup_amf_renderer(self):
+ from tg.amfify import render_amf
+ self.render_functions.amf = render_amf
+
def setup_json_renderer(self):
from tg.render import render_json
self.render_functions.json = render_json
@@ -439,6 +443,9 @@ def load_environment(global_conf, app_conf):
if 'jinja' in self.renderers:
self.setup_jinja_renderer()
+ if 'amf' in self.renderers:
+ self.setup_amf_renderer()
+
if self.use_legacy_renderer:
self.setup_default_renderer()
View
3 tg/controllers/dispatcher.py
@@ -278,6 +278,9 @@ def _find_first_exposed(self, controller, methods):
if self._is_exposed(controller, method):
return getattr(controller, method)
+ def _setup_wsgiorg_routing_args(self, url_path, remainder, params):
+ pass
+
def _is_exposed(self, controller, name):
"""Override this function to define how a controller method is
determined to be exposed.
View
10 tg/decorators.py
@@ -82,7 +82,7 @@ def register_custom_template_engine(self, custom_format, content_type, engine, t
exclude_names):
"""Registers a custom engine on the controller.
- Mulitple engines can be registered, but only one engine per
+ Multiple engines can be registered, but only one engine per
custom_format.
The engine is registered when @expose is used with the
@@ -246,9 +246,9 @@ def __init__(self, template='', content_type=None, exclude_names=None,
custom_format=None):
if exclude_names is None:
exclude_names = []
-
- if template == 'json':
- engine, template = 'json', ''
+
+ if template in config.get('renderers', []):
+ engine, template = template, ''
elif ':' in template:
engine, template = template.split(':', 1)
@@ -270,7 +270,7 @@ def __init__(self, template='', content_type=None, exclude_names=None,
else:
content_type = 'text/html'
- if engine == 'json' and 'tmpl_context' not in exclude_names:
+ if (engine == 'json' or engine == 'amf') and 'tmpl_context' not in exclude_names:
exclude_names.append('tmpl_context')
self.engine = engine
View
2 tg/render.py
@@ -132,7 +132,7 @@ def render(template_vars, template_engine=None, template_name=None, **kwargs):
if not template_vars:
template_vars={}
- if template_engine != "json":
+ if template_engine != "json" and template_engine!= 'amf':
#Get the extra vars, and merge in the vars from the controller
tg_vars = _get_tg_vars()
tg_vars.update(template_vars)
View
9 tg/test_stack/rendering/controllers/root.py
@@ -1,7 +1,7 @@
"""Main Controller"""
from tg import expose, redirect, config, validate
-from tg.decorators import paginate, use_custom_format
+from tg.decorators import paginate, use_custom_format, override_template
from tg.controllers import TGController
from tw.forms import TableForm, TextField, CalendarDatePicker, SingleSelectField, TextArea
from tw.api import WidgetsList
@@ -120,3 +120,10 @@ def mako_inherits_dotted(self):
def custom_format(self, format):
use_custom_format(self.custom_format, format)
return dict(format=format, status="ok")
+
+ @expose("genshi:tg.tests.non_overridden")
+ def template_override(self, override=False):
+ if override:
+ override_template(self.template_override, "genshi:tg.tests.overridden")
+ return dict()
+
View
13 tg/test_stack/rendering/test_rendering.py
@@ -69,3 +69,16 @@ def test_mako_inheritance():
print resp
assert "inherited mako page" in resp
assert "Inside parent template" in resp
+
+def test_template_override():
+ app = setup_noDB()
+ r =app.get('/template_override')
+ assert "Not overridden" in r
+ r = app.get('/template_override', params=dict(override=True))
+ assert "This is overridden." in r
+ # now invoke the controller again without override,
+ # it should yield the old result
+ r =app.get('/template_override')
+ assert "Not overridden" in r
+
+
View
8 tg/test_stack/rendering/test_toscawidgets.py
@@ -17,13 +17,15 @@ def setup_noDB():
return app_from_config(base_config)
-expected_field = """<input type="text" name="year" class="textfield" id="movie_form_year" value="1984" size="4" />"""
+expected_field = """\
+<td class="fieldcol">
+ <input xmlns="http://www.w3.org/1999/xhtml" type="text" name="year" class="textfield" id="movie_form_year" value="1984" size="4"/>
+ </td>"""
def test_basic_form_rendering():
app = setup_noDB()
resp = app.get('/form')
- print resp.body
assert "form" in resp
- assert expected_field in resp
+ assert expected_field in resp, resp
View
4 tg/tests/test_rest_controller_dispatch.py
@@ -48,6 +48,9 @@ class LookupAlwaysHelper:
def __init__(self, var):
self.var = var
+ def _setup_wsgiorg_routing_args(self, url_path, remainder, params):
+ pass
+
@expose()
def always(self, *args, **kwargs):
return 'always go here'
@@ -58,6 +61,7 @@ def _dispatch(self, state, remainder):
class LookupAlwaysController(TGController):
+
@expose()
def lookup(self, a, *args):
return LookupAlwaysHelper(a), args
View
15 tg/tests/test_tg_controller_dispatch.py
@@ -86,11 +86,6 @@ def redirect_sub(self):
def hello(self, name):
return "Why HELLO! " + name
- @expose("genshi:tg.tests.non_overridden")
- def template_override(self, override=False):
- if override:
- override_template(self.template_override, "genshi:tg.tests.overridden")
- return dict()
class SubController3(object):
@expose()
@@ -349,16 +344,6 @@ def test_new_before_controller(self):
r = self.app.get('/sub/newbefore')
assert '__my_before__' in r, r
- def test_template_override(self):
- r =self.app.get('/sub/template_override')
- assert "Not overridden" in r
- r = self.app.get('/sub/template_override', params=dict(override=True))
- assert "This is overridden." in r
- # now invoke the controller again without override,
- # it should yield the old result
- r =self.app.get('/sub/template_override')
- assert "Not overridden" in r
-
def test_unicode_default_dispatch(self):
r =self.app.get('/sub/äö')
assert "%C3%A4%C3%B6" in r

0 comments on commit 372db82

Please sign in to comment.
Something went wrong with that request. Please try again.