1
# -*- coding: utf-8 -*-
3
Functional test suite for the root controller.
5
This is an example of how functional tests can be written for controllers.
7
As opposed to a unit-test, which test a small unit of functionality,
8
functional tests exercise the whole application and its WSGI stack.
10
Please read http://pythonpaste.org/webtest/ for more information.
13
from nose.tools import assert_true
15
from madgraph3.tests import TestController
18
class TestRootController(TestController):
19
"""Tests for the method in the root controller."""
22
"""The front page is working properly"""
23
response = self.app.get('/')
24
msg = 'TurboGears 2 is rapid web application development toolkit '\
25
'designed to make your life easier.'
26
# You can look for specific strings:
27
assert_true(msg in response)
29
# You can also access a BeautifulSoup'ed response in your tests
30
# (First run $ easy_install BeautifulSoup
31
# and then uncomment the next two lines)
33
#links = response.html.findAll('a')
35
#assert_true(links, "Mummy, there are no links here!")
37
def test_environ(self):
38
"""Displaying the wsgi environ works"""
39
response = self.app.get('/environ.html')
40
assert_true('The keys in the environment are: ' in response)
43
"""The data display demo works with HTML"""
44
response = self.app.get('/data.html?a=1&b=2')
45
expected1 = """<td>a</td>
47
expected2 = """<td>b</td>
50
assert expected1 in response, response
51
assert expected2 in response, response
53
def test_data_json(self):
54
"""The data display demo works with JSON"""
55
resp = self.app.get('/data.json?a=1&b=2')
56
assert '"a": "1", "b": "2"' in resp, resp
58
def test_secc_with_manager(self):
59
"""The manager can access the secure controller"""
60
# Note how authentication is forged:
61
environ = {'REMOTE_USER': 'manager'}
62
resp = self.app.get('/secc', extra_environ=environ, status=200)
63
assert 'Secure Controller here' in resp.body, resp.body
65
def test_secc_with_editor(self):
66
"""The editor cannot access the secure controller"""
67
environ = {'REMOTE_USER': 'editor'}
68
self.app.get('/secc', extra_environ=environ, status=403)
69
# It's enough to know that authorization was denied with a 403 status
71
def test_secc_with_anonymous(self):
72
"""Anonymous users must not access the secure controller"""
73
self.app.get('/secc', status=401)
74
# It's enough to know that authorization was denied with a 401 status