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
|
import unittest
import sys, os.path
import bottle
import urllib2
from StringIO import StringIO
import thread
import time
from tools import ServerTestBase
from bottle import tob, touni, tonat, Bottle
class TestAppMounting(ServerTestBase):
def setUp(self):
ServerTestBase.setUp(self)
self.subapp = bottle.Bottle()
@self.subapp.route('/')
@self.subapp.route('/test/:test')
def test(test='foo'):
return test
def test_mount(self):
self.app.mount('/test/', self.subapp)
self.assertStatus(404, '/')
self.assertStatus(404, '/test')
self.assertStatus(200, '/test/')
self.assertBody('foo', '/test/')
self.assertStatus(200, '/test/test/bar')
self.assertBody('bar', '/test/test/bar')
def test_no_slash_prefix(self):
self.app.mount('/test', self.subapp)
self.assertStatus(404, '/')
self.assertStatus(200, '/test')
self.assertBody('foo', '/test')
self.assertStatus(200, '/test/')
self.assertBody('foo', '/test/')
self.assertStatus(200, '/test/test/bar')
self.assertBody('bar', '/test/test/bar')
def test_mount_no_plugins(self):
def plugin(func):
def wrapper(*a, **ka):
return 'Plugin'
return wrapper
self.app.install(plugin)
self.app.route('/foo', callback=lambda: 'baz')
self.app.mount('/test/', self.subapp)
self.assertBody('Plugin', '/foo')
self.assertBody('foo', '/test/')
def test_mount_wsgi(self):
status = {}
def app(environ, start_response):
start_response('200 OK', [('X-Test', 'WSGI')])
return 'WSGI ' + environ['PATH_INFO']
self.app.mount('/test', app)
self.assertStatus(200, '/test/')
self.assertBody('WSGI /', '/test')
self.assertBody('WSGI /', '/test/')
self.assertHeader('X-Test', 'WSGI', '/test/')
self.assertBody('WSGI /test/bar', '/test/test/bar')
if __name__ == '__main__': #pragma: no cover
unittest.main()
|