MCPcopy
hub / github.com/sanic-org/sanic / test_blueprint_group_versioning

Function test_blueprint_group_versioning

tests/test_blueprints.py:941–982  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

939
940
941def test_blueprint_group_versioning():
942 app = Sanic(name="blueprint-group-test")
943
944 bp1 = Blueprint(name="bp1", url_prefix="/bp1")
945 bp2 = Blueprint(name="bp2", url_prefix="/bp2", version=2)
946
947 bp3 = Blueprint(name="bp3", url_prefix="/bp3")
948
949 @bp3.get("/r1")
950 async def bp3_r1(request):
951 return json({"from": "bp3/r1"})
952
953 @bp1.get("/pre-group")
954 async def pre_group(request):
955 return json({"from": "bp1/pre-group"})
956
957 group = Blueprint.group([bp1, bp2], url_prefix="/group1", version=1)
958
959 group2 = Blueprint.group([bp3])
960
961 @bp1.get("/r1")
962 async def r1(request):
963 return json({"from": "bp1/r1"})
964
965 @bp2.get("/r2")
966 async def r2(request):
967 return json({"from": "bp2/r2"})
968
969 @bp2.get("/r3", version=3)
970 async def r3(request):
971 return json({"from": "bp2/r3"})
972
973 app.blueprint([group, group2])
974
975 assert app.test_client.get("/v1/group1/bp1/r1/")[1].status == 200
976 assert app.test_client.get("/v2/group1/bp2/r2")[1].status == 200
977 assert app.test_client.get("/v1/group1/bp1/pre-group")[1].status == 200
978 assert app.test_client.get("/v3/group1/bp2/r3")[1].status == 200
979 assert app.test_client.get("/bp3/r1")[1].status == 200
980
981 assert group.version == 1
982 assert group2.strict_slashes is None
983
984
985def test_blueprint_group_strict_slashes():

Callers

nothing calls this directly

Calls 5

blueprintMethod · 0.95
SanicClass · 0.90
BlueprintClass · 0.90
groupMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…