-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest_root.py_tmpl
More file actions
71 lines (56 loc) · 2.58 KB
/
test_root.py_tmpl
File metadata and controls
71 lines (56 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- 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 https://webtest.readthedocs.io/ for more information.
"""
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 = self.app.get('/')
msg = 'TurboGears 2 is rapid web application development toolkit '\
'designed to make your life easier.'
# You can look for specific strings:
assert msg in response
# You can also access a BeautifulSoup'ed response in your tests
# (First run `pip install beautifulsoup4`
# and then uncomment the next two lines)
# links = response.html.findAll('a')
# print(links)
# assert links, "Mummy, there are no links here!"
{{if not minimal_quickstart}}
def test_environ(self):
"""Displaying the wsgi environ works"""
response = self.app.get('/environ.html')
assert 'The keys in the environment are:' in response
def test_data(self):
"""The data display demo works with HTML"""
response = self.app.get('/data.html?a=1&b=2')
response.mustcontain("<td>a", "<td>1",
"<td>b", "<td>2")
def test_data_json(self):
"""The data display demo works with JSON"""
resp = self.app.get('/data.json?a=1&b=2')
assert dict(page='data', params={'a': '1', 'b': '2'}) == resp.json
{{if auth}}
def test_secc_with_manager(self):
"""The manager can access the secure controller"""
# Note how authentication is forged:
environ = {'REMOTE_USER': 'manager'}
resp = self.app.get('/secc', extra_environ=environ, status=200)
assert 'Secure Controller here' in resp.text, resp.text
def test_secc_with_editor(self):
"""The editor cannot access the secure controller"""
environ = {'REMOTE_USER': 'editor'}
self.app.get('/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"""
self.app.get('/secc', status=401)
# It's enough to know that authorization was denied with a 401 status
{{endif}}
{{endif}}