예제 #1
0
def test_blueprint_group_insert():
    blueprint_1 = Blueprint(
        "blueprint_1", url_prefix="/bp1", strict_slashes=True, version=1
    )
    blueprint_2 = Blueprint("blueprint_2", url_prefix="/bp2")
    blueprint_3 = Blueprint("blueprint_3", url_prefix=None)
    group = BlueprintGroup(
        url_prefix="/test", version=1.3, strict_slashes=False
    )
    group.insert(0, blueprint_1)
    group.insert(0, blueprint_2)
    group.insert(0, blueprint_3)

    @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
예제 #2
0
def test_blueprint_group_insert():
    blueprint_1 = Blueprint(
        "blueprint_1", url_prefix="/bp1", strict_slashes=True, version=1
    )
    blueprint_2 = Blueprint("blueprint_2", url_prefix="/bp2")
    blueprint_3 = Blueprint("blueprint_3", url_prefix=None)
    group = BlueprintGroup(
        url_prefix="/test", version=1.3, strict_slashes=False
    )
    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"