-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_aic.py
45 lines (36 loc) · 1.38 KB
/
test_aic.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
import os
import sys
sys.path.append(os.path.abspath('./wsgi'))
import random
import unittest
import json
import aic.app as app
import aic.db as db
class AICTestCase(unittest.TestCase):
def setUp(self):
self.app = app.application.test_client()
session = db.Session()
self.keyword = db.Keyword("Testkeyword" + str(random.randint(0,1000000000)))
session.add(self.keyword)
session.commit()
self.project = db.Project("", "")
session.add(self.project)
session.commit()
self.task = db.Task(self.project, self.keyword, "")
self.task.answers_requested = 1
session.add(self.task)
session.commit()
def test_post_answer_bad_task(self):
data = json.dumps({'answer': 'positive', 'user': "testuser"})
response = self.app.post('/api/task/0/answers', data=data)
self.assertEquals(response.status_code, 404)
def test_post_answer_bad_data(self):
data = "bad_data"
response = self.app.post('/api/task/%s/answers' % self.task.id, data=data)
self.assertEquals(response.status_code, 400)
def test_post_answer(self):
data = json.dumps({'answer': 'positive', 'user': "testuser"})
response = self.app.post('/api/task/%s/answers' % self.task.id, data=data)
self.assertEquals(response.status_code, 200)
if __name__ == '__main__':
unittest.main()