-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathtest_oorouting.py
39 lines (29 loc) · 955 Bytes
/
test_oorouting.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
"""
Tests & demonstrates various OO approaches to routes
"""
import unittest
import sys
if sys.version_info >= (3, 0, 0):
from io import BytesIO
else:
from StringIO import StringIO as BytesIO
__author__ = 'atc'
from bottle import Bottle, request, tob, BaseRequest
class TestRouter(object):
"""
A test class for wrapping routes to test certain OO scenarios
"""
app = Bottle()
@app.post("/route1/<msg>")
def route_1(self, msg):
body = request.body.readline()
return {'msg': msg, 'len': len(body)}
class TestRoutes(unittest.TestCase):
def test_route1(self):
body = "abc"
request.environ['CONTENT_LENGTH'] = str(len(tob(body)))
request.environ['wsgi.input'] = BytesIO()
request.environ['wsgi.input'].write(tob(body))
request.environ['wsgi.input'].seek(0)
result = TestRouter().route_1("bob")
self.assertEqual(result, dict(msg="bob", len=3))