Allow blueprints and groups to be infinitely reusable (#2150)
* Allow blueprints and groups to be infinitely reusable
This commit is contained in:
@@ -200,7 +200,7 @@ def test_bp_group_as_nested_group():
|
||||
blueprint_group_1 = Blueprint.group(
|
||||
Blueprint.group(blueprint_1, blueprint_2)
|
||||
)
|
||||
assert len(blueprint_group_1) == 2
|
||||
assert len(blueprint_group_1) == 1
|
||||
|
||||
|
||||
def test_blueprint_group_insert():
|
||||
@@ -215,9 +215,29 @@ def test_blueprint_group_insert():
|
||||
group.insert(0, blueprint_1)
|
||||
group.insert(0, blueprint_2)
|
||||
group.insert(0, blueprint_3)
|
||||
assert group.blueprints[1].strict_slashes is False
|
||||
assert group.blueprints[2].strict_slashes is True
|
||||
assert group.blueprints[0].url_prefix == "/test"
|
||||
|
||||
@blueprint_1.route("/")
|
||||
def blueprint_1_default_route(request):
|
||||
return text("BP1_OK")
|
||||
|
||||
@blueprint_2.route("/")
|
||||
def blueprint_2_default_route(request):
|
||||
return text("BP2_OK")
|
||||
|
||||
@blueprint_3.route("/")
|
||||
def blueprint_3_default_route(request):
|
||||
return text("BP3_OK")
|
||||
|
||||
app = Sanic("PropTest")
|
||||
app.blueprint(group)
|
||||
app.router.finalize()
|
||||
|
||||
routes = [(route.path, route.strict) for route in app.router.routes]
|
||||
|
||||
assert len(routes) == 3
|
||||
assert ("v1/test/bp1/", True) in routes
|
||||
assert ("v1.3/test/bp2", False) in routes
|
||||
assert ("v1.3/test", False) in routes
|
||||
|
||||
|
||||
def test_bp_group_properties():
|
||||
@@ -231,19 +251,25 @@ def test_bp_group_properties():
|
||||
url_prefix="/grouped",
|
||||
strict_slashes=True,
|
||||
)
|
||||
primary = Blueprint.group(group, url_prefix="/primary")
|
||||
|
||||
assert group.version_prefix == "/api/v"
|
||||
assert blueprint_1.version_prefix == "/api/v"
|
||||
assert blueprint_2.version_prefix == "/api/v"
|
||||
@blueprint_1.route("/")
|
||||
def blueprint_1_default_route(request):
|
||||
return text("BP1_OK")
|
||||
|
||||
assert group.version == 1
|
||||
assert blueprint_1.version == 1
|
||||
assert blueprint_2.version == 1
|
||||
@blueprint_2.route("/")
|
||||
def blueprint_2_default_route(request):
|
||||
return text("BP2_OK")
|
||||
|
||||
assert group.strict_slashes
|
||||
assert blueprint_1.strict_slashes
|
||||
assert blueprint_2.strict_slashes
|
||||
app = Sanic("PropTest")
|
||||
app.blueprint(group)
|
||||
app.blueprint(primary)
|
||||
app.router.finalize()
|
||||
|
||||
assert group.url_prefix == "/grouped"
|
||||
assert blueprint_1.url_prefix == "/grouped/bp1"
|
||||
assert blueprint_2.url_prefix == "/grouped/bp2"
|
||||
routes = [route.path for route in app.router.routes]
|
||||
|
||||
assert len(routes) == 4
|
||||
assert "api/v1/grouped/bp1/" in routes
|
||||
assert "api/v1/grouped/bp2/" in routes
|
||||
assert "api/v1/primary/grouped/bp1" in routes
|
||||
assert "api/v1/primary/grouped/bp2" in routes
|
||||
|
||||
Reference in New Issue
Block a user