mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-09 12:27:46 +00:00
Bugfix/basepath (#1716)
Working towards #1709 I think we're almost there, some tests I did are now working properly. Would love to get some feedback/ideas on the implementation and the tests :)
This commit is contained in:
@@ -72,3 +72,74 @@ def test_is_json_mimetype():
|
||||
"application/vnd.com.myEntreprise.v6+json; charset=UTF-8"
|
||||
)
|
||||
assert not utils.is_json_mimetype("text/html")
|
||||
|
||||
|
||||
def test_sort_routes():
|
||||
routes = ["/users/me", "/users/{username}"]
|
||||
expected = ["/users/me", "/users/{username}"]
|
||||
assert utils.sort_routes(routes) == expected
|
||||
|
||||
routes = ["/{path:path}", "/basepath/{path:path}"]
|
||||
expected = ["/basepath/{path:path}", "/{path:path}"]
|
||||
assert utils.sort_routes(routes) == expected
|
||||
|
||||
routes = ["/", "/basepath"]
|
||||
expected = ["/basepath", "/"]
|
||||
assert utils.sort_routes(routes) == expected
|
||||
|
||||
routes = ["/basepath/{path:path}", "/basepath/v2/{path:path}"]
|
||||
expected = ["/basepath/v2/{path:path}", "/basepath/{path:path}"]
|
||||
assert utils.sort_routes(routes) == expected
|
||||
|
||||
routes = ["/basepath", "/basepath/v2"]
|
||||
expected = ["/basepath/v2", "/basepath"]
|
||||
assert utils.sort_routes(routes) == expected
|
||||
|
||||
routes = ["/users/{username}", "/users/me"]
|
||||
expected = ["/users/me", "/users/{username}"]
|
||||
assert utils.sort_routes(routes) == expected
|
||||
|
||||
routes = [
|
||||
"/users/{username}",
|
||||
"/users/me",
|
||||
"/users/{username}/items",
|
||||
"/users/{username}/items/{item}",
|
||||
]
|
||||
expected = [
|
||||
"/users/me",
|
||||
"/users/{username}/items/{item}",
|
||||
"/users/{username}/items",
|
||||
"/users/{username}",
|
||||
]
|
||||
assert utils.sort_routes(routes) == expected
|
||||
|
||||
routes = [
|
||||
"/users/{username}",
|
||||
"/users/me",
|
||||
"/users/{username}/items/{item}",
|
||||
"/users/{username}/items/special",
|
||||
]
|
||||
expected = [
|
||||
"/users/me",
|
||||
"/users/{username}/items/special",
|
||||
"/users/{username}/items/{item}",
|
||||
"/users/{username}",
|
||||
]
|
||||
assert utils.sort_routes(routes) == expected
|
||||
|
||||
|
||||
def test_sort_apis_by_basepath():
|
||||
api1 = MagicMock(base_path="/")
|
||||
api2 = MagicMock(base_path="/basepath")
|
||||
assert utils.sort_apis_by_basepath([api1, api2]) == [api2, api1]
|
||||
|
||||
api3 = MagicMock(base_path="/basepath/v2")
|
||||
assert utils.sort_apis_by_basepath([api1, api2, api3]) == [api3, api2, api1]
|
||||
|
||||
api4 = MagicMock(base_path="/healthz")
|
||||
assert utils.sort_apis_by_basepath([api1, api2, api3, api4]) == [
|
||||
api3,
|
||||
api2,
|
||||
api4,
|
||||
api1,
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user