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

Function test_upload_file_background

tests/units/test_app.py:1446–1481  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

1444 [FileUploadState, ChildFileUploadState, GrandChildFileUploadState],
1445)
1446async 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
1484def _build_chunk_upload_multipart_body(

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