-
-
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
1 changed file
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
|
||
from esmerald import Esmerald, Redirect, Request, Template | ||
from esmerald.config.template import TemplateConfig | ||
from esmerald.responses.base import RedirectResponse | ||
from esmerald.routing.gateways import Gateway | ||
from esmerald.routing.handlers import get | ||
from esmerald.testclient import EsmeraldTestClient | ||
|
||
|
||
def test_issue1(template_dir, test_client_factory): | ||
path = os.path.join(template_dir, "start.html") | ||
with open(path, "w") as file: | ||
file.write("<html>Hello, <a href='{{ url_for('homepage') }}'>world</a></html>") | ||
|
||
@get() | ||
async def start(request: Request) -> Template: | ||
return Redirect(path="/home", status_code=301) | ||
|
||
app = Esmerald( | ||
debug=True, | ||
routes=[Gateway("/", handler=start)], | ||
template_config=TemplateConfig( | ||
directory=template_dir, | ||
), | ||
) | ||
client = EsmeraldTestClient(app) | ||
response = client.get("/") | ||
assert response.status_code == 301 | ||
|
||
|
||
def test_issue2(template_dir, test_client_factory): | ||
path = os.path.join(template_dir, "start.html") | ||
with open(path, "w") as file: | ||
file.write("<html>Hello, <a href='{{ url_for('homepage') }}'>world</a></html>") | ||
|
||
@get() | ||
async def start(request: Request) -> Template: | ||
return RedirectResponse(url="/home", status_code=301) | ||
|
||
app = Esmerald( | ||
debug=True, | ||
routes=[Gateway("/", handler=start)], | ||
template_config=TemplateConfig( | ||
directory=template_dir, | ||
), | ||
) | ||
client = EsmeraldTestClient(app) | ||
response = client.get("/") | ||
assert response.status_code == 301 |