-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
55 lines (44 loc) · 1.66 KB
/
tests.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
import graphs as flask
import os
import unittest
import db
from settings import datadir
class FlaskrTestCase(unittest.TestCase):
def setUp(self):
flask.app.config['TESTING'] = True
self.app = flask.app.test_client()
png_dir = os.path.join(datadir, 'png')
if not os.path.isdir(png_dir):
os.makedirs(png_dir)
open(os.path.join(datadir, 'update.log'), 'a')
db.create()
def test_index(self):
rv = self.app.get('/graphs/')
assert '<h3>index</h3>' in rv.data
def test_detail(self):
rv = self.app.get('/graphs/visitors/')
assert '<h3>visitors</h3>' in rv.data
rv = self.app.get('/graphs/nonexistent/')
assert '404' in rv.data
def test_png(self):
rv = self.app.get('/graphs/visitors/1d.png')
assert rv.content_type == 'image/png'
rv = self.app.get('/graphs/nonexistent/1d.png')
assert '404' in rv.data
rv = self.app.get('/graphs/visitors/100/1d.png')
assert rv.content_type == 'image/png'
rv = self.app.get('/graphs/visitors/3000/1d.png')
assert rv.content_type == 'image/png'
rv = self.app.get('/graphs/chat/1d.png')
assert rv.content_type == 'image/png'
rv = self.app.get('/graphs/members/1d.png')
assert rv.content_type == 'image/png'
rv = self.app.get('/graphs/posts/1d.png')
assert rv.content_type == 'image/png'
rv = self.app.get('/graphs/topics/1d.png')
assert rv.content_type == 'image/png'
def test_404(self):
rv = self.app.get('/')
assert '<h1>404</h1>' in rv.data
if __name__ == '__main__':
unittest.main()