-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_vote.py
63 lines (48 loc) · 2.57 KB
/
test_vote.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
import poll_server
import unittest
import json
import time
class FlaskrTestCase(unittest.TestCase):
def setUp(self):
poll_server.app.config['TESTING'] = True
self.app = poll_server.app.test_client()
self.app.get('/setup')
def tearDown(self):
pass
def test_empty_vote(self):
response = self.app.post('/vote')
self.assertEqual(response.status_code, 400)
def test_empty_dict_vote(self):
response = self.app.post('/vote', data=json.dumps(dict()))
self.assertEqual(response.status_code, 400)
def test_missing_question_result_vote(self):
response = self.app.post('/vote', data=json.dumps(dict(annotation='yes', result='yes')))
self.assertEqual(response.status_code, 400)
def test_missing_result_vote(self):
response = self.app.post('/vote', data=json.dumps(dict(questionResult='yes', result='yes')))
self.assertEqual(response.status_code, 400)
def test_missing_annotation_vote(self):
response = self.app.post('/vote', data=json.dumps(dict(questionResult='yes', annotation='yes')))
self.assertEqual(response.status_code, 400)
def test_valid_vote(self):
response = self.app.post('/vote', data=json.dumps(dict(questionResult='yes', annotation='yes', result='yes')))
self.assertEqual(response.status_code, 200)
def test_valid_vote(self):
response = self.app.post('/vote', data=json.dumps(dict(questionResult='yes', annotation='yes', result='yes')))
self.assertEqual(response.status_code, 200)
def test_valid_vote_data_not_in_db_already(self):
cur_time = int(time.time())
response = self.app.post('/vote', data=json.dumps(dict(questionResult=cur_time, annotation=cur_time, result=cur_time)))
self.assertEqual(response.status_code, 200)
def test_valid_vote_data_in_db_already(self):
cur_time = int(time.time())
response = self.app.post('/vote', data=json.dumps(dict(questionResult=cur_time, annotation=cur_time, result=cur_time)))
self.assertEqual(response.status_code, 200)
response = self.app.post('/vote', data=json.dumps(dict(questionResult=cur_time, annotation=cur_time, result=cur_time)))
self.assertEqual(response.status_code, 200)
def test_valid_vote_multiple(self):
cur_time = int(time.time())
response = self.app.post('/vote', data=json.dumps(dict(questionResult=cur_time, annotation=cur_time, result=[cur_time, cur_time - 1, cur_time - 2])))
self.assertEqual(response.status_code, 200)
if __name__ == '__main__':
unittest.main()