Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Nov 6, 2024
1 parent deb6e6b commit 3b9796c
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions tests/handlers/test_to_response_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ async def test_function(data: Individual) -> Individual:

person_instance = IndividualFactory.build()
test_function.signature_model = SignatureFactory(
test_function.fn, set() # type:ignore[arg-type]
test_function.fn,
set(), # type:ignore[arg-type]
).create_signature()

response = await test_function.to_response(
data=test_function.fn(data=person_instance), app=None # type: ignore
)
assert loads(response.body) == person_instance.model_dump()
# we need the encoders
with create_client([]):
response = await test_function.to_response(
data=test_function.fn(data=person_instance),
app=None, # type: ignore
)
assert loads(response.body) == person_instance.model_dump()


@pytest.mark.asyncio()
Expand All @@ -111,13 +115,17 @@ async def test_function(data: Individual) -> Individual:

person_instance = IndividualFactory.build()
test_function.signature_model = SignatureFactory(
test_function.fn, set() # type:ignore[arg-type]
test_function.fn,
set(), # type:ignore[arg-type]
).create_signature()

response = await test_function.to_response(
data=test_function.fn(data=person_instance), app=None # type: ignore
)
assert loads(response.body) == person_instance.model_dump()
# we need the encoders
with create_client([]):
response = await test_function.to_response(
data=test_function.fn(data=person_instance),
app=None, # type: ignore
)
assert loads(response.body) == person_instance.model_dump()


@pytest.mark.asyncio()
Expand All @@ -127,7 +135,7 @@ def test_function() -> Response:
return Response(status_code=HTTP_200_OK, media_type=MediaType.TEXT, content="ok")

with create_client(test_function) as client:
route: HTTPHandler = client.app.routes[0] # type: ignore
route: HTTPHandler = client.app.routes[0].handler # type: ignore
response = await route.to_response(data=route.fn(), app=None) # type: ignore
assert isinstance(response, Response)

Expand Down Expand Up @@ -155,7 +163,7 @@ def test_function() -> LilyaResponse:
return expected_response

with create_client(test_function) as client:
route = client.app.routes[0] # type: ignore
route = client.app.routes[0].handler # type: ignore
response = await route.to_response(data=route.fn(), app=None) # type: ignore
assert isinstance(response, LilyaResponse)
assert response is expected_response
Expand Down Expand Up @@ -183,7 +191,7 @@ def test_function() -> Redirect:
)

with create_client(test_function) as client:
route = client.app.routes[0]
route = client.app.routes[0].handler
response = await route.to_response(data=route.fn(), app=None) # type: ignore
assert isinstance(response, RedirectResponse)
assert response.headers["location"] == "/somewhere-else"
Expand Down Expand Up @@ -246,7 +254,7 @@ def test_function() -> File:
)

with create_client(test_function) as client:
route = client.app.routes[0] # type: ignore
route = client.app.routes[0].handler # type: ignore
response = await route.to_response(data=route.fn(), app=None) # type: ignore

assert isinstance(response, FileResponse)
Expand Down Expand Up @@ -301,7 +309,7 @@ def test_function() -> Stream:
)

with create_client(test_function) as client:
route = client.app.routes[0] # type: ignore
route = client.app.routes[0].handler # type: ignore
response = await route.to_response(data=route.fn(), app=None) # type: ignore
assert isinstance(response, StreamingResponse)
assert response.headers["local-header"] == "123"
Expand Down Expand Up @@ -339,7 +347,7 @@ def test_function() -> Template:
)

with create_client(test_function) as client:
route = client.app.routes[0] # type: ignore
route = client.app.routes[0].handler # type: ignore

response = await route.to_response(data=route.fn(), app=None) # type: ignore
assert isinstance(response, TemplateResponse)
Expand Down

0 comments on commit 3b9796c

Please sign in to comment.