Skip to content

Commit

Permalink
chore: add missing tests and improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
CaselIT committed Sep 29, 2024
1 parent e5059ab commit 8fe56a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/_newsfragments/2023.newandimproved.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The default error serializer will now use the response media handlers
to better negotiate the response format with the client.
to better negotiate the response serialization with the client.
The implementation still default to JSON in case a client does not specify
any preference.
27 changes: 27 additions & 0 deletions tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from falcon import App
from falcon import status_codes
from falcon import testing
from falcon.util.sync import async_to_sync


class CustomCookies:
Expand Down Expand Up @@ -103,6 +104,32 @@ def on_post(self, req, resp):
assert result.text == falcon.MEDIA_JSON


@pytest.mark.parametrize('mode', ['wsgi', 'asgi', 'asgi-stream'])
def test_content_type(util, mode):
class Responder:
def on_get(self, req, resp):
resp.content_type = req.content_type

app = util.create_app('asgi' in mode)
app.add_route('/', Responder())

if 'stream' in mode:

async def go():
async with testing.ASGIConductor(app) as ac:
async with ac.simulate_get_stream(
'/', content_type='my-content-type'
) as r:
assert r.content_type == 'my-content-type'
return 1

assert async_to_sync(go) == 1
else:
client = testing.TestClient(app)
res = client.simulate_get('/', content_type='foo-content')
assert res.content_type == 'foo-content'


@pytest.mark.parametrize('cookies', [{'foo': 'bar', 'baz': 'foo'}, CustomCookies()])
def test_create_environ_cookies(cookies):
environ = testing.create_environ(cookies=cookies)
Expand Down

0 comments on commit 8fe56a9

Please sign in to comment.