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.

Posted in  | 26 comments

Comments

  1. replica watches said 1034 days later:

    thanks for the share

  2. Tiffany silver jewelry said 1082 days later:

    That sound s good.I will try.And I am trying to search Tiffany Jewelry online store

  3. Video tutorials said 1147 days later:

    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.

  4. Engagement Rings said 1170 days later:

    I think http_proxy is set…

  5. pll fm transmitter said 1187 days later:

    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!

  6. tiffany Earrings said 1191 days later:

    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!

  7. Simon Lanyards said 1193 days later:

    Is pylons.config available during tests?‎Anyone?

  8. cheap ralph lauren polo shirts said 1194 days later:

    It is useful for me,thanks for your nice share. womens ralph lauren polo shirts

  9. Non Destructive Material Testing said 1197 days later:

    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….

  10. Mobile Prepaid said 1197 days later:

    Hi… that was great stuff.. I really like this subject. Could you tell me more … I would love to explore.

  11. iPhone Accessories said 1197 days later:

    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..

  12. Electronic Cigarettes said 1197 days later:

    Nice to be visiting your blog again, it has been months for me. I need this article to complete my assignment in college. Thanks.

  13. Cheap Brother Printer Ink said 1197 days later:

    This is a great blog posting and very useful. I really appreciate the research you put into it…

  14. Search Engine Optimisation UK said 1197 days later:

    This article is so interesting I am completely engrossed. Thanks for a great read.

  15. Business Process Outsourcing said 1197 days later:

    I am quite interested in this topic. Hope you will elaborate more on it in future posts…..

  16. Website Designers Los Angeles said 1197 days later:

    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.

  17. Web Design Company said 1197 days later:

    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.

  18. Point of Sale Systems said 1197 days later:

    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.

  19. Sales staff said 1197 days later:

    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.

  20. IT Employment said 1197 days later:

    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.

  21. used audi a4/http://www.autoquake.com/used-Audi-A8 said 1201 days later:

    Great idea, it very instructive for me. I have just got interested in blogging and hopefully i am able to do so.Thanks.

  22. http://www.autoquake.com/used-Audi-A8/sdfd@gmail.com said 1201 days later:

    Great idea, it very instructive for me. I have just got interested in blogging and hopefully i am able to do so.Thanks.

  23. used audi a4 said 1201 days later:

    I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me.

  24. coach book bag said 1207 days later:

    It is useful,thanks!

  25. silverjewelryqueen said 1208 days later:

    Amazing!Thanks for sharing!

  26. skin tags said 1208 days later:

    I hope this would work fine for me.

(leave url/email »)

   Comment Markup Help Preview comment