async def test_simple_add_nested_blueprints(self): b1 = Blueprint() b2 = Blueprint() @b2.route('/123') async def home(): return Response(b'123') b1.add_blueprint(b2) self.app.add_blueprint(b1) async with self.app.test_client() as client: response = await client.request('/123') self.assertEqual(response.content, b'123')
async def test_simple_add_nested_blueprints_with_prefixes(self): b1 = Blueprint() b2 = Blueprint() @b2.route('/123') async def home(): return Response(b'123') b1.add_blueprint(b2, prefixes={'a': '/a', 'b': '/b'}) self.app.add_blueprint(b1, prefixes={'a': '/a', 'b': '/b'}) async with self.app.test_client() as client: response = await client.request('/a/a/123') self.assertEqual(response.content, b'123') response = await self.app.test_client().request('/b/b/123') self.assertEqual(response.content, b'123')
async def test_simple_add_nested_blueprints_with_prefixes(self): b1 = Blueprint() b2 = Blueprint() @b2.route("/123") async def home(): return Response(b"123") b1.add_blueprint(b2, prefixes={"a": "/a", "b": "/b"}) self.app.add_blueprint(b1, prefixes={"a": "/a", "b": "/b"}) async with self.app.test_client() as client: response = await client.request("/a/a/123") self.assertEqual(response.content, b"123") response = await self.app.test_client().request("/b/b/123") self.assertEqual(response.content, b"123")
async def test_multiple_exceptions_at_a_single_handle(self): b1 = Blueprint() b2 = Blueprint() class ExceptionA(Exception): pass @b2.route("/") async def handle_errors(): raise ExceptionA("Vibora ;)") @self.app.handle((IOError, ExceptionA)) async def handle_errors2(): return Response(b"Correct!", status_code=500) b1.add_blueprint(b2, prefixes={"": ""}) self.app.add_blueprint(b1, prefixes={"": ""}) response = await self.app.test_client().request("/") self.assertEqual(response.status_code, 500) self.assertEqual(response.content, b"Correct!")
async def test_nested_blueprint_exception_propagation_conflicts(self): b1 = Blueprint() b2 = Blueprint() class ExceptionA(Exception): pass @b2.route("/") async def handle_errors(): raise ExceptionA("Vibora ;)") @self.app.handle(ExceptionA) async def handle_errors2(): return Response(b"Wrong!", status_code=500) b1.add_blueprint(b2, prefixes={"": ""}) self.app.add_blueprint(b1, prefixes={"": ""}) response = await self.app.test_client().request("/") self.assertEqual(response.status_code, 500) self.assertEqual(response.content, b"Wrong!")
async def test_nested_blueprint_exception_propagation(self): b1 = Blueprint() b2 = Blueprint() class ExceptionA(Exception): pass @b2.route('/') async def handle_errors(): raise ExceptionA('Vibora ;)') @self.app.handle(ExceptionA) async def handle_errors(): return Response(b'Wrong!', status_code=500) b1.add_blueprint(b2, prefixes={'': ''}) self.app.add_blueprint(b1, prefixes={'': ''}) response = await self.app.test_client().request('/') self.assertEqual(response.status_code, 500) self.assertEqual(response.content, b'Wrong!')