Test that an error is thrown handler is a background task. Args: state: The state class. tmp_path: Temporary path. token: a Token.
(state, tmp_path, token)
| 836 | [FileUploadState, ChildFileUploadState, GrandChildFileUploadState], |
| 837 | ) |
| 838 | async def test_upload_file_background(state, tmp_path, token): |
| 839 | """Test that an error is thrown handler is a background task. |
| 840 | |
| 841 | Args: |
| 842 | state: The state class. |
| 843 | tmp_path: Temporary path. |
| 844 | token: a Token. |
| 845 | """ |
| 846 | state._tmp_path = tmp_path |
| 847 | # The App state must be the "root" of the state tree |
| 848 | app = App(state=state if state is FileUploadState else FileStateBase1) |
| 849 | |
| 850 | state_name = state.get_full_name().partition(".")[2] or state.get_name() |
| 851 | request_mock = unittest.mock.Mock() |
| 852 | request_mock.headers = { |
| 853 | "nextpy-client-token": token, |
| 854 | "nextpy-event-handler": f"{state_name}.bg_upload", |
| 855 | } |
| 856 | file_mock = unittest.mock.Mock(filename="image1.jpg") |
| 857 | fn = upload(app) |
| 858 | with pytest.raises(TypeError) as err: |
| 859 | await fn(request_mock, [file_mock]) |
| 860 | assert ( |
| 861 | err.value.args[0] |
| 862 | == f"@xt.background is not supported for upload handler `{state_name}.bg_upload`." |
| 863 | ) |
| 864 | |
| 865 | if isinstance(app.state_manager, StateManagerRedis): |
| 866 | await app.state_manager.close() |
| 867 | |
| 868 | |
| 869 | class DynamicState(BaseState): |