summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2011-12-28 18:33:48 +0100
committerMarcel Hellkamp <marc@gsites.de>2011-12-28 18:43:32 +0100
commit794f119109d7aaff6defb65fd952d9a96fed6671 (patch)
tree9aaf71968ba43829e1a91fa903ad248146f70370
parenta45f67ec27c953f1ef6df534159540ca52098811 (diff)
downloadbottle-794f119109d7aaff6defb65fd952d9a96fed6671.tar.gz
Added a Bottle.merge() method.
-rwxr-xr-xbottle.py10
-rw-r--r--test/test_mount.py18
2 files changed, 28 insertions, 0 deletions
diff --git a/bottle.py b/bottle.py
index b732643..5143934 100755
--- a/bottle.py
+++ b/bottle.py
@@ -584,6 +584,16 @@ class Bottle(object):
if not prefix.endswith('/'):
self.route('/' + '/'.join(parts), callback=mountpoint, **options)
+ def merge(self, routes):
+ ''' Merge the routes of another :cls:`Bottle` application or a list of
+ :class:`Route` objects into this application. The routes keep their
+ 'owner', meaning that the :data:`Route.app` attribute is not
+ changed. '''
+ if isinstance(routes, Bottle):
+ routes = routes.routes
+ for route in routes:
+ self.add_route(route)
+
def install(self, plugin):
''' Add a plugin to the list of plugins and prepare it for being
applied to all routes of this application. A plugin may be a simple
diff --git a/test/test_mount.py b/test/test_mount.py
index bff6806..fc24638 100644
--- a/test/test_mount.py
+++ b/test/test_mount.py
@@ -54,5 +54,23 @@ class TestAppMounting(ServerTestBase):
self.assertBody('WSGI /test/bar', '/test/test/bar')
+class TestAppMerging(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_merge(self):
+ self.app.merge(self.subapp)
+ self.assertStatus(200, '/')
+ self.assertBody('foo', '/')
+ self.assertStatus(200, '/test/bar')
+ self.assertBody('bar', '/test/bar')
+
+
+
if __name__ == '__main__': #pragma: no cover
unittest.main()