Skip to content

Commit

Permalink
update release notes, provide tests
Browse files Browse the repository at this point in the history
Note: the tests are failing
  • Loading branch information
devkral committed Dec 29, 2024
1 parent c06012e commit e9efea2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/en/docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ hide:
- `bytes` won't be encoded as json when returned from a handler. This would unexpectly lead to a base64 encoding.
- SessionConfig has a unneccessarily heavily restricted secret_key parameter.
- Gracefully handle situations where cookies are None in `get_cookies`.
- Fix validation of parameters requiring a body.

## 3.6.1

Expand Down
14 changes: 12 additions & 2 deletions tests/forms/test_forms_data.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from dataclasses import dataclass
from typing import Any, Dict
from typing import Any, Dict, Optional

import pytest
from pydantic import BaseModel
from pydantic.dataclasses import dataclass as pydantic_dataclass

from esmerald import Form, Gateway, post
from esmerald import Form, Gateway, post, route
from esmerald.exceptions import ImproperlyConfigured
from esmerald.testclient import create_client


Expand Down Expand Up @@ -86,3 +88,11 @@ def test_send_complex_form_base_model(test_client_factory):
response = client.post("/complex-form-basemodel", data=data)
assert response.status_code == 201, response.text
assert response.json() == {"id": 1, "name": "Test"}


def test_get_and_head_data():
with pytest.raises(ImproperlyConfigured):

@route(methods=["GET", "HEAD"])
async def start(data: Optional[UserModel]) -> bytes:
return b"hello world"
14 changes: 12 additions & 2 deletions tests/forms/test_forms_payload.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from dataclasses import dataclass
from typing import Any, Dict
from typing import Any, Dict, Optional

import pytest
from pydantic import BaseModel
from pydantic.dataclasses import dataclass as pydantic_dataclass

from esmerald import Form, Gateway, post
from esmerald import Form, Gateway, post, route
from esmerald.exceptions import ImproperlyConfigured
from esmerald.testclient import create_client


Expand Down Expand Up @@ -86,3 +88,11 @@ def test_send_complex_form_base_model(test_client_factory):
response = client.post("/complex-form-basemodel", data=payload)
assert response.status_code == 201, response.text
assert response.json() == {"id": 1, "name": "Test"}


def test_get_and_head_payload():
with pytest.raises(ImproperlyConfigured):

@route(methods=["GET", "HEAD"])
async def start(payload: Optional[UserModel]) -> bytes:
return b"hello world"
28 changes: 27 additions & 1 deletion tests/forms/test_forms_route.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from typing import Optional, Union

import pytest
from pydantic import BaseModel

from esmerald import Esmerald, Form, Request
from esmerald.exceptions import ImproperlyConfigured
from esmerald.routing.gateways import Gateway
from esmerald.routing.handlers import route
from esmerald.testclient import EsmeraldTestClient
Expand All @@ -12,7 +16,21 @@ class Model(BaseModel):

def test_get_and_post():
@route(methods=["GET", "POST"])
async def start(request: Request, form: Model | None = Form()) -> bytes:
async def start(request: Request, form: Union[Model, None] = 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


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

app = Esmerald(
Expand All @@ -22,3 +40,11 @@ async def start(request: Request, form: Model | None = Form()) -> bytes:
client = EsmeraldTestClient(app)
response = client.get("/")
assert response.status_code == 200


def test_get_and_head_form():
with pytest.raises(ImproperlyConfigured):

@route(methods=["GET", "HEAD"])
async def start(form: Optional[Model] = Form()) -> bytes:
return b"hello world"

0 comments on commit e9efea2

Please sign in to comment.