-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
executable file
·69 lines (53 loc) · 2.38 KB
/
run_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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
import unittest
import argparse
import logging
from aeneas import generate_app
import json
class MaxContentLengthUnspecifiedTest(unittest.TestCase):
def setUp(self):
self.app = generate_app(db_uri='sqlite:///run_tests.db')
self.app.db.create_all()
def test_4000_should_be_ok(self):
with self.app.test_client() as tc:
resp = tc.post('/v1.0/reports', data=json.dumps(
{'product': 'a', 'version': '1.0', 'data': 'x' * 3954}),
content_type='application/json')
self.assertEqual(201, resp.status_code)
def test_4001_should_fail(self):
with self.app.test_client() as tc:
resp = tc.post('/v1.0/reports', data=json.dumps(
{'product': 'a', 'version': '1.0', 'data': 'x' * 3955}),
content_type='application/json')
self.assertEqual(413, resp.status_code)
class MaxContentLengthSpecifiedTest(unittest.TestCase):
def setUp(self):
self.app = generate_app(db_uri='sqlite:///run_tests.db',
max_content_length=100)
self.app.db.create_all()
def test_100_should_be_ok(self):
with self.app.test_client() as tc:
resp = tc.post('/v1.0/reports', data=json.dumps(
{'product': 'a', 'version': '1.0', 'data': 'x' * 54}),
content_type='application/json')
self.assertEqual(201, resp.status_code)
def test_101_should_fail(self):
with self.app.test_client() as tc:
resp = tc.post('/v1.0/reports', data=json.dumps(
{'product': 'a', 'version': '1.0', 'data': 'x' * 55}),
content_type='application/json')
self.assertEqual(413, resp.status_code)
def run():
parser = argparse.ArgumentParser()
parser.add_argument('--print-log', action='store_true',
help='Print the log.')
args = parser.parse_args()
if args.print_log:
logging.basicConfig(level=logging.DEBUG,
format=('%(asctime)s %(levelname)s:%(name)s:'
'%(funcName)s:'
'%(filename)s(%(lineno)d):'
'%(threadName)s(%(thread)d):%(message)s'))
unittest.main(argv=[''])
if __name__ == '__main__':
run()