Test that an error is thrown when there's no param annotated with xt.UploadFile or List[UploadFile]. Args: state: The state class. tmp_path: Temporary path. token: a Token.
(state, tmp_path, token)
| 800 | [FileUploadState, ChildFileUploadState, GrandChildFileUploadState], |
| 801 | ) |
| 802 | async def test_upload_file_without_annotation(state, tmp_path, token): |
| 803 | """Test that an error is thrown when there's no param annotated with xt.UploadFile or List[UploadFile]. |
| 804 | |
| 805 | Args: |
| 806 | state: The state class. |
| 807 | tmp_path: Temporary path. |
| 808 | token: a Token. |
| 809 | """ |
| 810 | state._tmp_path = tmp_path |
| 811 | # The App state must be the "root" of the state tree |
| 812 | app = App(state=state if state is FileUploadState else FileStateBase1) |
| 813 | |
| 814 | state_name = state.get_full_name().partition(".")[2] or state.get_name() |
| 815 | request_mock = unittest.mock.Mock() |
| 816 | request_mock.headers = { |
| 817 | "nextpy-client-token": token, |
| 818 | "nextpy-event-handler": f"{state_name}.handle_upload2", |
| 819 | } |
| 820 | file_mock = unittest.mock.Mock(filename="image1.jpg") |
| 821 | fn = upload(app) |
| 822 | with pytest.raises(ValueError) as err: |
| 823 | await fn(request_mock, [file_mock]) |
| 824 | assert ( |
| 825 | err.value.args[0] |
| 826 | == f"`{state_name}.handle_upload2` handler should have a parameter annotated as List[xt.UploadFile]" |
| 827 | ) |
| 828 | |
| 829 | if isinstance(app.state_manager, StateManagerRedis): |
| 830 | await app.state_manager.close() |
| 831 | |
| 832 | |
| 833 | @pytest.mark.asyncio |