Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

82 lines (64 sloc) 2.827 kb
# -*- coding: utf-8 -*-
Functional test suite for the root controller.
This is an example of how functional tests can be written for controllers.
As opposed to a unit-test, which test a small unit of functionality,
functional tests exercise the whole application and its WSGI stack.
Please read for more information.
from import assert_true
from {{package}}.tests import TestController
class TestRootController(TestController):
"""Tests for the method in the root controller."""
def test_index(self):
"""The front page is working properly"""
response ='/')
msg = 'TurboGears 2 is rapid web application development toolkit '\
'designed to make your life easier.'
# You can look for specific strings:
assert_true(msg in response)
# You can also access a BeautifulSoup'ed response in your tests
# (First run $ easy_install BeautifulSoup
# and then uncomment the next two lines)
#links = response.html.findAll('a')
#print links
#assert_true(links, "Mummy, there are no links here!")
def test_environ(self):
"""Displaying the wsgi environ works"""
response ='/environ.html')
assert_true('The keys in the environment are: ' in response)
def test_data(self):
"""The data display demo works with HTML"""
response ='/data.html?a=1&b=2')
expected = """\
assert expected in str(response), response
def test_data_json(self):
"""The data display demo works with JSON"""
resp ='/data.json?a=1&b=2')
assert '"a": "1", "b": "2"' in resp, resp
{{if auth == 'sqlalchemy' or auth == 'ming'}}
def test_secc_with_manager(self):
"""The manager can access the secure controller"""
# Note how authentication is forged:
environ = {'REMOTE_USER': 'manager'}
resp ='/secc', extra_environ=environ, status=200)
assert 'Secure Controller here' in resp.body, resp.body
def test_secc_with_editor(self):
"""The editor cannot access the secure controller"""
environ = {'REMOTE_USER': 'editor'}'/secc', extra_environ=environ, status=403)
# It's enough to know that authorization was denied with a 403 status
def test_secc_with_anonymous(self):
"""Anonymous users must not access the secure controller"""'/secc', status=401)
# It's enough to know that authorization was denied with a 401 status
Jump to Line
Something went wrong with that request. Please try again.