Testing your django app with webtest
on Apr 25, 2013 by Danu
I’ve been watching both presentations that Carl Meyer held at Pycon 2012/13 and I highly recommend them if you want a deep dive into writing tests with django. They outline some very good principles for writing effective and maintainable tests. They also highlight a suite of test utilities and frameworks which help you in writing better tests. Among the others, Webtest caught my attention via django-webtest for writing integration/functional tests.
-
def testLoginProcess(self):
-
login = self.app.get(reverse('auth_login'))
-
login.form['username'] = 'danu'
-
login.form['password'] = 'test123'
-
response = login.form.submit('Log in').follow()
-
assert_equals('200 OK', response.status)
-
assert_contains(response, 'Welcome danu :]', count=1, status_code=200)
-
-
def testLoginWithInvalidCredentials(self):
-
login = self.app.get(reverse('auth_login'))
-
login.form['username'] = 'foo'
-
login.form['password'] = 'bar'
-
response = login.form.submit('Log in')
-
assert_contains(
-
response,
-
'Please enter a correct username and password. '
-
'Note that both fields are case-sensitive.',
-
count=1,
-
status_code=200
-
)
tests/__init__.py
and for rest of the goodness that nose offers.
Tags: django functional webtest integration | Category: testing , python , django Back To Top
comments powered by Disqus