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,
)
| 1401 | [FileUploadState, ChildFileUploadState, GrandChildFileUploadState], |
| 1402 | ) |
| 1403 | async 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 |
nothing calls this directly
no test coverage detected