-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bigh.py
116 lines (99 loc) · 3.98 KB
/
test_bigh.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
import os
import bigh
import unittest
import tempfile
class BighTestCase(unittest.TestCase):
def setUp(self):
bigh.app.config['TESTING'] = True
bigh.app.config['DBNAME'] = 'bigh_test' # must be created first
self.app = bigh.app.test_client()
with bigh.app.app_context():
bigh.init_db()
self.db_fd, self.data_path = tempfile.mkstemp()
def tearDown(self):
os.unlink(self.data_path)
with bigh.app.app_context():
bigh.init_db()
def login(self, username, password):
return self.app.post('/login', data=dict(
username=username,
password=password
), follow_redirects=True)
def logout(self):
return self.app.get('/logout', follow_redirects=True)
def test_empty_db(self):
rv = self.app.get('/')
self.assertIn(b'Big Heart', rv.data)
self.assertIn(b'log in', rv.data)
def test_login(self):
rv = self.login('admin', 'a-sharp')
self.assertIn(b'You were logged in', rv.data)
self.assertIn(b'Patient ID', rv.data)
self.assertIn(b'Xray', rv.data)
def test_login_logout(self):
rv = self.login('admin', 'a-sharp')
self.assertIn(b'You were logged in', rv.data)
self.assertIn(b'Patient ID', rv.data)
self.assertIn(b'Xray', rv.data)
rv = self.logout()
self.assertIn(b'You were logged out', rv.data)
def test_login_invalid(self):
rv = self.login('adminx', 'a-sharp')
self.assertIn(b'Invalid username', rv.data)
rv = self.login('admin', 'defaultx')
self.assertIn(b'Invalid password', rv.data)
def test_no_patients(self):
self.login('admin', 'a-sharp')
rv = self.app.get('/patients', follow_redirects=True)
self.assertIn(b'Big Heart', rv.data)
self.assertIn(b'No patients', rv.data)
def test_new_patient(self):
self.login('admin', 'a-sharp')
rv = self.app.get('/new', follow_redirects=True)
self.assertIn(b'Big Heart', rv.data)
self.assertIn(b'Patient List', rv.data)
self.assertIn(b'Patient ID', rv.data)
self.assertIn(b'Xray', rv.data)
def test_add_severe_patient(self):
self.login('admin', 'a-sharp')
pat_id = 'abcd12'
rv = self.app.post('/add', data=dict(patient_id=pat_id,
gender='male', xray='True', double_density='True',
oblique_diameter=5.4, appendage_shape='Convex'
), follow_redirects=True)
self.assertIn(b'Big Heart', rv.data)
self.assertIn(b'New patient was successfully posted', rv.data)
self.assertIn(b'Severe', rv.data)
self.assertIn(b'Date & Time', rv.data)
def test_show_patient(self):
# setup
self.login('admin', 'a-sharp')
pat_id = 'abcd34'
self.app.post('/add', data=dict(patient_id=pat_id,
gender='male', xray='True', double_density='True',
oblique_diameter=5.4, appendage_shape='Convex'
), follow_redirects=False)
# show patient
rv = self.app.get('/patient/'+pat_id)
self.assertIn(b'Big Heart', rv.data)
self.assertIn(b'Severe', rv.data)
self.assertIn(b'Date & Time', rv.data)
def test_add_no_xray_patient(self):
self.login('admin', 'a-sharp')
pat_id = 'abcd56'
rv = self.app.post('/add', data=dict(patient_id=pat_id,
gender='male', xray='False', double_density='True',
oblique_diameter=5.4, appendage_shape='Convex'
), follow_redirects=True)
self.assertIn(b'Big Heart', rv.data)
self.assertIn(b'No Xray data', rv.data)
def test_no_patient_info(self):
self.login('admin', 'a-sharp')
rv = self.app.post('/add', data=dict(
title='BigHeart',
text='HTML allowed here'
), follow_redirects=True)
self.assertIn(u'Big Heart', rv.data)
self.assertIn(u'Patient info incomplete', rv.data)
if __name__ == '__main__':
unittest.main()