Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix direct responses #463

Merged
merged 7 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changes:
- split edge cases tests
  • Loading branch information
devkral committed Jan 17, 2025
commit 5748808e91e8d38883cd8364a30838b045beeb37
1 change: 1 addition & 0 deletions docs/en/docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ accessible via `from esmerald import Controller`.
- Fix escaped " in TemplateResponse.
- Fix TemplateResponse's auto-detection of the media-type when used directly.
- Don't mangle strings by default for other media-types than json.
- Don't mangle returned responses.

## 3.6.2

Expand Down
26 changes: 26 additions & 0 deletions tests/routing/test_routing_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Optional

from pydantic import BaseModel

from esmerald import Esmerald, Form, Request
from esmerald.routing.gateways import Gateway
from esmerald.routing.handlers import route
from esmerald.testclient import EsmeraldTestClient


class Model(BaseModel):
id: str


def test_get_and_post():
@route(methods=["GET", "POST"])
async def start(request: Request, data: Optional[Model] = Form()) -> bytes:
return b"hello world"

app = Esmerald(
debug=True,
routes=[Gateway("/", handler=start)],
)
client = EsmeraldTestClient(app)
response = client.get("/")
assert response.status_code == 200
25 changes: 2 additions & 23 deletions tests/test_edgecases.py → tests/test_direct_responses.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import os
from typing import Optional

from pydantic import BaseModel

from esmerald import Esmerald, Form, Redirect, Request, Template
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, route
from esmerald.routing.handlers import get
from esmerald.testclient import EsmeraldTestClient


class Model(BaseModel):
id: str


def test_return_response_container(template_dir):
path = os.path.join(template_dir, "start.html")
with open(path, "w") as file:
Expand Down Expand Up @@ -56,17 +49,3 @@ async def start(request: Request) -> Template:
client = EsmeraldTestClient(app)
response = client.get("/", follow_redirects=False)
assert response.status_code == 301


def test_get_and_post():
@route(methods=["GET", "POST"])
async def start(request: Request, data: Optional[Model] = Form()) -> bytes:
return b"hello world"

app = Esmerald(
debug=True,
routes=[Gateway("/", handler=start)],
)
client = EsmeraldTestClient(app)
response = client.get("/")
assert response.status_code == 200
Loading