vigiboard / vigiboard / tests / functional / test_root.py @ f70865a8
History | View | Annotate | Download (1.79 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('/', status=401) |
21 |
msg = 'Unauthorized'
|
22 |
# You can look for specific strings:
|
23 |
assert_true(msg in response)
|
24 |
|
25 |
# You can also access a BeautifulSoup'ed response in your tests
|
26 |
# (First run $ easy_install BeautifulSoup
|
27 |
# and then uncomment the next two lines)
|
28 |
|
29 |
#links = response.html.findAll('a')
|
30 |
#print links
|
31 |
#assert_true(links, "Mummy, there are no links here!")
|
32 |
def test_secc_with_manager(self): |
33 |
"""Only the manager can access the secure controller"""
|
34 |
# Note how authentication is forged:
|
35 |
environ = {'REMOTE_USER': 'manager'} |
36 |
resp = self.app.get('/secc', extra_environ=environ, status=200) |
37 |
assert 'Secure Controller here' in resp.body, resp.body |
38 |
|
39 |
def test_secc_with_editor(self): |
40 |
"""The editor shouldn't access the secure controller"""
|
41 |
environ = {'REMOTE_USER': 'editor'} |
42 |
self.app.get('/secc', extra_environ=environ, status=403) |
43 |
# It's enough to know that authorization was denied with a 403 status
|
44 |
|
45 |
def test_secc_with_anonymous(self): |
46 |
"""Anonymous users must not access the secure controller"""
|
47 |
self.app.get('/secc', status=401) |
48 |
# It's enough to know that authorization was denied with a 401 status
|