diff options
author | Marcel Hellkamp <marc@gsites.de> | 2011-12-28 18:33:48 +0100 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2011-12-28 18:43:32 +0100 |
commit | 794f119109d7aaff6defb65fd952d9a96fed6671 (patch) | |
tree | 9aaf71968ba43829e1a91fa903ad248146f70370 | |
parent | a45f67ec27c953f1ef6df534159540ca52098811 (diff) | |
download | bottle-794f119109d7aaff6defb65fd952d9a96fed6671.tar.gz |
Added a Bottle.merge() method.
-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() |