-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_app.py
138 lines (107 loc) · 4.11 KB
/
test_app.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import unittest
import meep_example_app
import meeplib
class TestApp(unittest.TestCase):
def setUp(self):
meep_example_app.initialize()
app = meep_example_app.MeepExampleApp()
self.app = app
meeplib._reset()
def test_index(self):
environ = {} # make a fake dict
environ['PATH_INFO'] = '/'
def fake_start_response(status, headers):
assert status == '200 OK'
assert ('Content-type', 'text/html') in headers
data = self.app(environ, fake_start_response)
#print data
#assert 'Username:' in data
#assert 'Password:' in data
#assert 'Create a user' in data
def test_create_user(self):
environ = {} # make a fake dict
environ['PATH_INFO'] = '/create_user'
def fake_start_response(status, headers):
assert status == '302 Found'
assert ('Content-type', 'text/html') in headers
data = self.app(environ, fake_start_response)
#print data
assert 'Username:' in data
assert 'Password:' in data
def test_list_messages(self):
environ = {} # make a fake dict
environ['PATH_INFO'] = '/m/list'
u = meeplib.User('user', 'name')
m = meeplib.Message('init title', 'init message', u ,'!')
def fake_start_response(status, headers):
assert status == '200 OK'
assert ('Content-type', 'text/html') in headers
data = self.app(environ, fake_start_response)
index = 0
for m in data:
if "Title: init title" in m:
index += 1
if 'Message: init message' in m:
index += 1
if 'Author: user' in m:
index += 1
if 'ID: 0' in m:
index += 1
print index
assert index is 4
def test_main_page(self):
environ = {} # make a fake dict
environ['PATH_INFO'] = '/main_page'
u = meeplib.User('user', 'name')
meeplib.set_curr_user(u.username)
m = meeplib.Message('init title', 'init message', u ,'!')
def fake_start_response(status, headers):
assert status == '200 OK'
assert ('Content-type', 'text/html') in headers
data = self.app(environ, fake_start_response)
index = 0
for m in data:
if "Add Message" in m:
index += 1
if 'Create User' in m:
index += 1
if 'Logout' in m:
index += 1
if 'Show Messages' in m:
index += 1
#print m
assert index is 4
def test_add_reply(self):
environ = {} # make a fake dict
environ['PATH_INFO'] = '/m/list'
u = meeplib.User('foo', 'bar')
m = meeplib.Message('the title', 'the content', u ,'!')
n = meeplib.Message('the reply title', 'the reply', u, m.id)
o = meeplib.Message('the 2nd title', 'the 2nd reply', u, n.id)
assert n.id in m.replies
assert o.id in n.replies
meeplib.set_curr_user(u.username)
def fake_start_response(status, headers):
assert status == '200 OK'
assert ('Content-type', 'text/html') in headers
data = self.app(environ, fake_start_response)
index = 0
'''print data[0]
for m in data:
#print m
if 'Delete Post' in m:
index += 1
print 'INDEX: '
print index'''
def test_recursive_delete(self):
u = meeplib.User('foo', 'bar')
m = meeplib.Message('the title', 'the content', u ,'!')
n = meeplib.Message('the reply title', 'the reply', u, m.id)
o = meeplib.Message('the second tier title', 'the second reply', u, n.id)
meeplib.delete_message(m)
assert n not in meeplib._messages.values()
assert o not in meeplib._messages.values()
def tearDown(self):
pass
if __name__ == '__main__':
unittest.main()