-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import pytest | ||
from lilya.compat import reverse | ||
|
||
from esmerald import Controller, Gateway, Include, get, post | ||
from esmerald.testclient import create_client | ||
|
||
|
||
@get("/hello") | ||
async def get_hello() -> str: | ||
return "Hello World" | ||
|
||
|
||
@post("/new") | ||
async def post_new() -> str: | ||
return "New World" | ||
|
||
|
||
class TestController(Controller): | ||
@get("/int", name="int") | ||
async def get_int(self, id: int) -> int: | ||
return id | ||
|
||
|
||
routes = [ | ||
Include( | ||
"/api", | ||
routes=[ | ||
Include( | ||
routes=[ | ||
Gateway(handler=get_hello, name="hello"), | ||
Gateway(handler=post_new, name="new"), | ||
Gateway(handler=TestController, name="test"), | ||
], | ||
name="v1", | ||
), | ||
], | ||
name="api", | ||
), | ||
] | ||
|
||
|
||
@pytest.mark.filterwarnings(r"ignore" r":UserWarning") | ||
def test_can_reverse_lookup(test_client_factory): | ||
with create_client(routes=routes) as client: | ||
app = client.app | ||
|
||
assert app.path_for("api:v1:hello") == "/api/hello" | ||
assert app.path_for("api:v1:new") == "/api/new" | ||
assert reverse("api:v1:hello") == "/api/hello" | ||
assert reverse("api:v1:new") == "/api/new" | ||
|
||
assert app.path_for("api:v1:int") == "/api/int" | ||
assert reverse("api:v1:int") == "/api/int" |