vigiboard / vigiboard / tests / functional / test_root.py @ 57f7cb3f
History | View | Annotate | Download (1.88 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
"""
|
3 |
Functional test suite for the root controller.
|
4 |
|
5 |
This is an example of how functional tests can be written for controllers.
|
6 |
|
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.
|
9 |
|
10 |
Please read http://pythonpaste.org/webtest/ for more information.
|
11 |
|
12 |
"""
|
13 |
from nose.tools import assert_true |
14 |
|
15 |
from vigiboard.tests import TestController |
16 |
|
17 |
|
18 |
class TestRootController(TestController): |
19 |
def test_index(self): |
20 |
response = self.app.get('/') |
21 |
msg = 'TurboGears 2 is rapid web application development toolkit '\
|
22 |
'designed to make your life easier.'
|
23 |
# You can look for specific strings:
|
24 |
assert_true(msg in response)
|
25 |
|
26 |
# You can also access a BeautifulSoup'ed response in your tests
|
27 |
# (First run $ easy_install BeautifulSoup
|
28 |
# and then uncomment the next two lines)
|
29 |
|
30 |
#links = response.html.findAll('a')
|
31 |
#print links
|
32 |
#assert_true(links, "Mummy, there are no links here!")
|
33 |
def test_secc_with_manager(self): |
34 |
"""Only the manager can access the secure controller"""
|
35 |
# Note how authentication is forged:
|
36 |
environ = {'REMOTE_USER': 'manager'} |
37 |
resp = self.app.get('/secc', extra_environ=environ, status=200) |
38 |
assert 'Secure Controller here' in resp.body, resp.body |
39 |
|
40 |
def test_secc_with_editor(self): |
41 |
"""The editor shouldn't access the secure controller"""
|
42 |
environ = {'REMOTE_USER': 'editor'} |
43 |
self.app.get('/secc', extra_environ=environ, status=403) |
44 |
# It's enough to know that authorization was denied with a 403 status
|
45 |
|
46 |
def test_secc_with_anonymous(self): |
47 |
"""Anonymous users must not access the secure controller"""
|
48 |
self.app.get('/secc', status=401) |
49 |
# It's enough to know that authorization was denied with a 401 status
|