-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_module_router.py
More file actions
73 lines (52 loc) · 1.94 KB
/
Copy pathtest_module_router.py
File metadata and controls
73 lines (52 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import pytest
from ellar.common.routing import ModuleRouter
from ellar.core.routing import ModuleRouterFactory
from .sample import router
another_router = ModuleRouter("/prefix/another", name="arouter")
@another_router.get("/sample")
def some_example(self):
pass
@another_router.get("/sample")
def some_example_3():
# some_example_3 overrides `sample_example` OPERATION since its the same 'path' and 'method'
pass
@another_router.http_route("/sample", methods=["get"])
def some_example_4():
# some_example_4 overrides `sample_example_3` OPERATION since its the same 'path' and 'method'
pass
@another_router.http_route("/sample", methods=["get", "post"])
def some_example_5():
# `sample_example_4 - get` overrides `sample_example_5 - get` RUNTIME CALL in that order
# And '/sample' POST call will be handled here
pass
@another_router.ws_route("/sample")
def some_example_ws():
pass
@another_router.ws_route("/sample")
def some_example_ws_2():
# `some_example_ws_2` overrides `some_example_ws` OPERATION
pass
@pytest.mark.parametrize(
"router_instance, prefix, tag, name",
[
(router, "/prefix", "mr", "mr"),
(another_router, "/prefix/another", "another_router", "arouter"),
],
)
def test_build_routes(router_instance, prefix, tag, name):
for route in router_instance.routes:
reversed_path = router_instance.url_path_for(f"{name}:{route.name}")
assert reversed_path == router_instance.path_format.replace(
"/{path}", route.path
)
def test_module_router_url_reverse():
new_router = ModuleRouter("/items/{orgID:int}", name="has_name")
@new_router.get
def some_route():
pass
ModuleRouterFactory.build(new_router)
reversed_path = new_router.url_path_for(
f"{new_router.name}:{new_router.routes[0].name}"
)
path = new_router.path_format.replace("/{path}", new_router.routes[0].path)
assert reversed_path == path