Skip to content

Commit

Permalink
test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Dec 23, 2024
1 parent f7ff231 commit 5d6206a
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/test_edgecases_responses.py
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

0 comments on commit 5d6206a

Please sign in to comment.