Testing: Getting the dict from a controller instead of the rendered page

19 views
Skip to first unread message

León Domingo

unread,
May 3, 2012, 5:13:30 PM5/3/12
to turbo...@googlegroups.com
Hi guys,
I'm begging to testing with TG and a question comes up.

WebTest allows us to get the response from a particular URL but that response is the rendered version, the associated template + returning dict from the controller.
Is there a way to get only the dict returned by the controller? My idea is to test the "web side" with Selenium, so the dict is the only information I need at this moment.

Thanks in advance

Moritz Schlarb

unread,
May 3, 2012, 6:17:48 PM5/3/12
to turbo...@googlegroups.com
You could expose it as json, which would just render the objects from the dict you return.

E.g.
@expose('json')
def func(self):
    return dict(a='blah')

would let you access: /func.json and get:
{"a": "blah"}

Does that help you?

León Domingo

unread,
May 3, 2012, 6:41:11 PM5/3/12
to turbo...@googlegroups.com
This works but it makes me add @expose('json') to every method.

In fact, i would like to do something like this:

class MyController(BaseController):
    @expose('some_template.html')
    def foo(self):
          return dict(a=1, b=2)

my_controller = MyController()
response = my_controller.foo()
# test values inside "response" dict

but it's not possible, at least directly

León Domingo

Ender - Factoría de Software
leon.d...@ender.es
Avda. Cerro del Águila, 7. S23 - 2ª Planta
28703 S.S. de los Reyes (MADRID)
Tlf. 902 01 44 01

   


--
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To view this discussion on the web visit https://groups.google.com/d/msg/turbogears/-/q3dXOVUkS08J.

To post to this group, send email to turbo...@googlegroups.com.
To unsubscribe from this group, send email to turbogears+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/turbogears?hl=en.

Reply all
Reply to author
Forward
0 new messages