From 4ebb773e1af07792d36a9fba568fe32893867d5d Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Mon, 9 Aug 2021 02:46:04 -0500 Subject: [PATCH] Update copy blueprint tests --- tests/test_blueprint_copy.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/test_blueprint_copy.py b/tests/test_blueprint_copy.py index 9d87b412..bad2c852 100644 --- a/tests/test_blueprint_copy.py +++ b/tests/test_blueprint_copy.py @@ -6,6 +6,8 @@ from sanic.response import text def test_bp_copy(app: Sanic): bp1 = Blueprint("test_bp1", version=1) + bp1.ctx.test = 1 + assert hasattr(bp1.ctx, "test") @bp1.route("/page") def handle_request(request): @@ -13,15 +15,26 @@ def test_bp_copy(app: Sanic): bp2 = bp1.copy(name="test_bp2", version=2) assert id(bp1) != id(bp2) + assert bp1._apps == bp2._apps == set() + assert not hasattr(bp2.ctx, "test") app.blueprint(bp1) app.blueprint(bp2) + bp3 = bp1.copy(name="test_bp3", version=3, with_registration=True) + assert id(bp1) != id(bp3) + assert bp1._apps == bp3._apps and bp3._apps + assert not hasattr(bp3.ctx, "test") + bp4 = bp1.copy(name="test_bp4", version=4, with_ctx=True) + assert id(bp1) != id(bp4) + assert bp4.ctx.test == 1 + bp5 = bp1.copy(name="test_bp5", version=5, with_registration=False) - assert id(bp2) != id(bp3) - assert id(bp3) != id(bp4) - assert id(bp4) != id(bp5) + assert id(bp1) != id(bp5) + assert not bp5._apps + assert bp1._apps != set() + app.blueprint(bp5) _, response = app.test_client.get("/v1/page")