-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
55 lines (36 loc) · 1.21 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
# project/tests.py
import unittest
from io import BytesIO
import app
class TestAll(unittest.TestCase):
def setUp(self):
app.app.testing = True
self.app = app.app.test_client()
def test_file_upload(self):
data = {
'file': (BytesIO(b'my file contents'), 'oct.txt'), # we use StringIO to simulate file object
'field':'1',
'tweetdate':'201810'
}
# note in that in the previous line you can use 'file' or whatever you want.
# flask client checks for the tuple (<FileObject>, <String>)
res = self.app.post('/upload', data=data)
assert res.status_code == 200
def test_months_start_end(self):
data = {
'start': '201812',
'end': '201810',
'field':'1'
}
#test case passes only if ValueError is raised.
with self.assertRaises(ValueError):
res = self.app.post('/testpy', data=data)
def test_months_end(self):
data = {
'end': '201810',
'topic':'1'
}
with self.assertRaises(ValueError):
res = self.app.post('/testfuturepy', data=data)
if __name__ == "__main__":
unittest.main()