-
Notifications
You must be signed in to change notification settings - Fork 10
/
tests.py
84 lines (65 loc) · 2.9 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
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
import bottle, unittest
from boddle import boddle
class TestBoddle(unittest.TestCase):
def testParams(self):
with boddle(params={'name':'derek'}):
self.assertEqual(bottle.request.params['name'], 'derek')
def test_no_params_no_throw(self):
with boddle():
self.assertEqual(list(bottle.request.params.items()), [])
def testGetParams(self):
with boddle(method='get', params={'name':'derek'}):
self.assertEqual(bottle.request.params['name'], 'derek')
def testPostParams(self):
with boddle(method='post', params={'name':'derek'}):
self.assertEqual(bottle.request.params['name'], 'derek')
def testPath(self):
with boddle(path='/derek'):
self.assertEqual(bottle.request.path, '/derek')
with boddle(path='/anderson'):
self.assertEqual(bottle.request.path, '/anderson')
self.assertEqual(bottle.request.path, '/derek')
def testMethod(self):
with boddle(method='post'):
self.assertEqual(bottle.request.method, 'POST')
def testHeaders(self):
with boddle(headers={'x_header':'value'}):
self.assertEqual(bottle.request.headers['X_HEADER'], 'value')
def testHyphenatedHeaders(self):
with boddle(headers={'x-header':'value'}):
self.assertEqual(bottle.request.headers['X-HEADER'], 'value')
def testExtraStuff(self):
with boddle(extra='woot'):
self.assertEqual(bottle.request.extra, 'woot')
with boddle(extra='woot2'):
self.assertEqual(bottle.request.extra, 'woot2')
self.assertFalse(hasattr(bottle.request,'extra'))
def testJSON(self):
with boddle(json={'name':'derek'}):
self.assertEqual(bottle.request.json['name'], 'derek')
def testURL(self):
with boddle(url='https://github.com/keredson/boddle'):
self.assertEqual(bottle.request.url, 'https://github.com/keredson/boddle')
self.assertEqual(bottle.request.fullpath, '/keredson/boddle')
self.assertEqual(bottle.request.path, '/keredson/boddle')
def testRevert(self):
with boddle(params={'name':'derek'}):
self.assertEqual(bottle.request.params['name'], 'derek')
with boddle(params={'name':'anderson'}):
self.assertEqual(bottle.request.params['name'], 'anderson')
self.assertEqual(bottle.request.params['name'], 'derek')
def testBody(self):
with boddle(body='body'):
self.assertEqual(bottle.request.body.read(), b'body')
self.assertEqual(bottle.request.body.readline(), b'body')
def testGetQuery(self):
with boddle(method='get', query={'name':'derek'}):
self.assertEqual(bottle.request.query['name'], 'derek')
def testRevertQuery(self):
with boddle(query={'name':'derek'}):
self.assertEqual(bottle.request.query['name'], 'derek')
with boddle(query={'name':'anderson'}):
self.assertEqual(bottle.request.query['name'], 'anderson')
self.assertEqual(bottle.request.query['name'], 'derek')
if __name__=='__main__':
unittest.main()