Test that an error is thrown handler is a background task. Args: state: The state class. tmp_path: Temporary path. token: a Token.
(
state: FileUploadState | ChildFileUploadState | GrandChildFileUploadState,
tmp_path: Path,
token: str,
)
| 1444 | [FileUploadState, ChildFileUploadState, GrandChildFileUploadState], |
| 1445 | ) |
| 1446 | async def test_upload_file_background( |
| 1447 | state: FileUploadState | ChildFileUploadState | GrandChildFileUploadState, |
| 1448 | tmp_path: Path, |
| 1449 | token: str, |
| 1450 | ): |
| 1451 | """Test that an error is thrown handler is a background task. |
| 1452 | |
| 1453 | Args: |
| 1454 | state: The state class. |
| 1455 | tmp_path: Temporary path. |
| 1456 | token: a Token. |
| 1457 | """ |
| 1458 | app = App(_state=State) |
| 1459 | |
| 1460 | request_mock = unittest.mock.Mock() |
| 1461 | request_mock.headers = { |
| 1462 | "reflex-client-token": token, |
| 1463 | "reflex-event-handler": f"{state.get_full_name()}.bg_upload", |
| 1464 | } |
| 1465 | |
| 1466 | file1 = UploadFile(filename="image1.jpg", file=io.BytesIO(b"data")) |
| 1467 | |
| 1468 | async def form(): # noqa: RUF029 |
| 1469 | return FormData([("files", file1)]) |
| 1470 | |
| 1471 | request_mock.form = form |
| 1472 | |
| 1473 | fn = upload(app) |
| 1474 | with pytest.raises(TypeError) as err: |
| 1475 | await fn(request_mock) |
| 1476 | assert ( |
| 1477 | err.value.args[0] |
| 1478 | == f"@rx.event(background=True) is not supported for upload handler `{state.get_full_name()}.bg_upload`." |
| 1479 | ) |
| 1480 | |
| 1481 | await app.state_manager.close() |
| 1482 | |
| 1483 | |
| 1484 | def _build_chunk_upload_multipart_body( |
nothing calls this directly
no test coverage detected