-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_forum.py
More file actions
72 lines (54 loc) · 1.99 KB
/
test_forum.py
File metadata and controls
72 lines (54 loc) · 1.99 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
72
# -*- coding: utf-8 -*-
"""
forum_tests.py
~~~~~~~~~~~~~~
Some basic tests on the forum app.
TODO: test models, authentication
:license: MIT and BSD
"""
import application
from application.models import *
ADMIN = 'admin@example.com'
USER = 'admin@example.com'
class Test(object):
def setup(self):
application.app.config.update({
'TESTING': True,
'DEBUG_TB_ENABLED': False,
'SQLALCHEMY_DATABASE_URI': 'sqlite://'
})
self.app = application.app.test_client()
application.db.create_all()
def teardown(self):
pass
def assert_code(self, path, code):
response = self.app.get(path)
assert response.status_code == code
def assert_redirect(self, path, location=None):
response = self.app.get(path)
assert response.status_code == 302
if location:
assert response.location == 'http://localhost' + location
def test_basic_response_codes(self):
self.assert_code('/', 200)
self.assert_code('/unknown', 404)
def test_auth_response_codes(self):
self.assert_code('/login', 200)
self.assert_code('/logout', 302)
self.assert_code('/register', 200)
def check_admin_endpoints(self, code):
self.assert_code('/admin/', code)
for item in ['board', 'thread', 'post', 'user', 'role']:
url = '/admin/%sview/' % item
self.assert_code(url, code)
self.assert_code(url + 'new/', code)
def test_admin_response_codes(self):
self.check_admin_endpoints(404)
def test_forum_response_codes(self):
self.assert_code('/forum/', 200)
self.assert_redirect('/forum/board/', '/forum/')
self.assert_redirect('/forum/board/1', '/forum/')
self.assert_redirect('/forum/board/1-thread', '/forum/')
# These redirect to the login page
self.assert_redirect('/forum/board/1/create')
self.assert_redirect('/forum/board/1/1/edit')