diff options
-rwxr-xr-x | bottle.py | 10 | ||||
-rw-r--r-- | test/test_mount.py | 18 |
2 files changed, 28 insertions, 0 deletions
@@ -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() |