Functional testing in Pylons, Twill and wsgi_intercept
Posted by Graham Stratton Sun, 13 May 2007 20:08:00 GMT
When trying to do some functional testing in Pylons, I initially tried Paste’s solution, which worked a bit, but I got stuck on trying to select multiple options in a select box. So I decided to move over to Twill, which I am already familiar with anyway.
In order to use Twill for in-process testing, Titus Brown, the developer of Twill, has provided a cunning module called wsgi_intercept. Yes, there is a clue in the name. wsgi_intercept replaces httplib.HTTPConnection, redirecting specified requests to the wsgi application. Titus has an article on testing with Twill and wsgi_intercept.
Using the module with Pylons is quite easy. I created a new project called squirrel, with a controller called nuts. In squirrel/tests/init.py, I added:
import twill
class TwillTestController(TestCase):
wsgi_app = loadapp('config:test.ini', relative_to=conf_dir)
def setUp(self):
def build_app():
return self.wsgi_app
twill.add_wsgi_intercept('localhost', 8080, build_app)
def tearDown(self):
twill.remove_wsgi_intercept('localhost', 8080)
Then I changed squirrel/tests/functional/test_nuts.py to
from squirrel.tests import TwillTestController
from twill.commands import *
class TestNutsController(TwillTestController):
def test_index(self):
go('http://localhost:8080/')
find('World')
notfind('Universe')
And running nosetests works quite nicely for me. Unless, that is, http_proxy is set, which it is on my work machine. I haven’t yet traced this problem to see whether it can be fixed or not, though I suspect there won’t be a simple solution.

thanks for the share
That sound s good.I will try.And I am trying to search Tiffany Jewelry online store
Thanks for the advice. Hope it will be easy too. As for me, I like to find video tutorials. Then you can follow everything spep by step.
I think http_proxy is set…
thanks for sharing thoes informations , It is usefull, i like it!I hope you do better and better on your website,And popular more and more!
I was just doing some web browsing on my Garmin Phone during my break at my work place, and I came across something I thought was interesting . It linked over to your website so I clicked over. I can’t really find the relevance between your site and the one I came from, but your site good none the less.thanks for sharing thoes informations , It is interesting, i like it!
Is pylons.config available during tests?Anyone?
It is useful for me,thanks for your nice share. womens ralph lauren polo shirts
I wanted to thank you for this great read!! I definitely enjoyed every little bit of it, I have you bookmarked to check out all the new stuff you post….
Hi… that was great stuff.. I really like this subject. Could you tell me more … I would love to explore.
I wanted to thank you for this great read!! I definitely enjoyed every little bit of it . I have you bookmarked to check out new stuff on your post..
Nice to be visiting your blog again, it has been months for me. I need this article to complete my assignment in college. Thanks.
This is a great blog posting and very useful. I really appreciate the research you put into it…
This article is so interesting I am completely engrossed. Thanks for a great read.
I am quite interested in this topic. Hope you will elaborate more on it in future posts…..
Although Django is currently the most popular webframework for Python, it is by no means your only choice. Where Django grew out of the needs of newsrooms to implement content management solutions rapidly, Pylons grew out of a need to build web applications in environments that may have existing databases to integrate with, and the applications don’t fit neatly into the class of applications that are loosely defined in the “content management” space.
This explains how to use fixture in the test suite of a simple Address Book application written in Pylons powered by two tables in a SQLite database via SQLAlchemy. If you’re not already familiar with Using DataSet and Using LoadableFixture then you’ll be OK but it wouldn’t hurt to read those docs first. The concepts here will probably also work with similar Python frameworks backed by SQLAlchemy. If you’ve got something working in another framework, please let me know.
Testing is the process of ensuring that the code you write performs in the way it was intended. Testing encompasses many different aspects that are relevant to a Pylons application. For example, it is important the libraries do what they are supposed to, that the controllers return the correct HTML pages for the actions they are performing, and that the application behaves in a way that the users find intuitive.
Amazing!I also wish him good luck to defend his gold medal. I like to share it with all my friends and hope they will also encourage him.
I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me.
Great idea, it very instructive for me. I have just got interested in blogging and hopefully i am able to do so.Thanks.
Great idea, it very instructive for me. I have just got interested in blogging and hopefully i am able to do so.Thanks.
I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me.
It is useful,thanks!
Amazing!Thanks for sharing!
I hope this would work fine for me.