MCPcopy
hub / github.com/reflex-dev/reflex / test_upload_file_without_annotation

Function test_upload_file_without_annotation

tests/units/test_app.py:1403–1438  ·  view source on GitHub ↗

Test that an error is thrown when there's no param annotated with rx.UploadFile or list[UploadFile]. Args: state: The state class. tmp_path: Temporary path. token: a Token.

(
    state: FileUploadState | ChildFileUploadState | GrandChildFileUploadState,
    tmp_path: Path,
    token: str,
)

Source from the content-addressed store, hash-verified

1401 [FileUploadState, ChildFileUploadState, GrandChildFileUploadState],
1402)
1403async def test_upload_file_without_annotation(
1404 state: FileUploadState | ChildFileUploadState | GrandChildFileUploadState,
1405 tmp_path: Path,
1406 token: str,
1407):
1408 """Test that an error is thrown when there's no param annotated with rx.UploadFile or list[UploadFile].
1409
1410 Args:
1411 state: The state class.
1412 tmp_path: Temporary path.
1413 token: a Token.
1414 """
1415 app = App(_state=State)
1416
1417 request_mock = unittest.mock.Mock()
1418 request_mock.headers = {
1419 "reflex-client-token": token,
1420 "reflex-event-handler": f"{state.get_full_name()}.handle_upload2",
1421 }
1422
1423 file1 = UploadFile(filename="image1.jpg", file=io.BytesIO(b"data"))
1424
1425 async def form(): # noqa: RUF029
1426 return FormData([("files", file1)])
1427
1428 request_mock.form = form
1429
1430 fn = upload(app)
1431 with pytest.raises(ValueError) as err:
1432 await fn(request_mock)
1433 assert (
1434 err.value.args[0]
1435 == f"`{state.get_full_name()}.handle_upload2` handler should have a parameter annotated as list[rx.UploadFile]"
1436 )
1437
1438 await app.state_manager.close()
1439
1440
1441@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 6

AppClass · 0.90
uploadFunction · 0.90
get_full_nameMethod · 0.80
UploadFileFunction · 0.50
fnFunction · 0.50
closeMethod · 0.45

Tested by

no test coverage detected