django-webtest
Easy integration/functional testing for Django
django-webtest is an app for instant integration of Ian Bicking's WebTest with django's testing framework. WebTest plays on the same field as twill. WebTest has nice API, is fast, small, talk to django application via WSGI instead of HTTP and is an easy way to write functional/integration/acceptance tests. It can follow links, submit forms, parse html, xml and json responses with different parsing libraries, upload files and more.
from django_webtest import WebTest
class MyTestCase(WebTest):
# optional: we want some initial data to be able to login
fixtures = ['users', 'blog_posts']
# optional: default extra_environ for this TestCase
extra_environ = {'REMOTE_ADDR': '10.20.30.1'}
def testBlog(self):
# pretend to be logged in as user `kmike` and go to the index page
index = self.app.get('/', user='kmike')
# All the webtest API is available. For example, we click
# on a <a href="/tech-blog/">Blog</a> link, check that it
# works (result page doesn't raise exceptions and returns 200 http
# code) and test if result page have 'My Article' text in
# it's body.
assert 'My Article' in index.click('Blog')
django-webtest provides django.test.TestCase subclass (WebTest) that creates webtest.TestApp around django wsgi interface and make it available in tests as self.app.
It also features optional user argument for self.app.get and self.app.post methods to help making authorized requests. This argument should be django.contrib.auth.models.User instance or a string with user's username for user who is supposed to be logged in.
For 500 errors original traceback is shown instead of usual html result from handler500.
- Source control:
- http://bitbucket.org/kmike/django-webtest/src
- Bug tracker:
- http://bitbucket.org/kmike/django-webtest/issues
- Home page:
- http://bitbucket.org/kmike/django-webtest
- Pypi:
- http://pypi.python.org/pypi/django-webtest/
- Authors
- Mikhail Korobov
- Tags
- django testing
Releases
- 1.1.1 on Jul, 25
This app is being cared for by: Mikhail Korobov
Comments
There are no comments.
Login to add comments

