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

Function test_cancel_upload

tests/integration/test_upload.py:809–869  ·  view source on GitHub ↗

Submit a large file upload and cancel it. Covers both the standard upload form and the streaming-chunk upload form; the latter additionally writes a partial file to a subdirectory under ``rx.get_upload_dir()`` which is verified to be smaller than the source. Args: request:

(
    request: pytest.FixtureRequest,
    tmp_path,
    upload_file: AppHarness,
    driver: WebDriver,
    upload_root_id: str,
    progress_fixture: str,
    exp_name: str,
    file_size_bytes: int,
    partial_subdir: str | None,
)

Source from the content-addressed store, hash-verified

807 ],
808)
809async def test_cancel_upload(
810 request: pytest.FixtureRequest,
811 tmp_path,
812 upload_file: AppHarness,
813 driver: WebDriver,
814 upload_root_id: str,
815 progress_fixture: str,
816 exp_name: str,
817 file_size_bytes: int,
818 partial_subdir: str | None,
819):
820 """Submit a large file upload and cancel it.
821
822 Covers both the standard upload form and the streaming-chunk upload form;
823 the latter additionally writes a partial file to a subdirectory under
824 ``rx.get_upload_dir()`` which is verified to be smaller than the source.
825
826 Args:
827 request: pytest request fixture, used to resolve the parametrized progress fixture.
828 tmp_path: pytest tmp_path fixture
829 upload_file: harness for UploadFile app.
830 driver: WebDriver instance.
831 upload_root_id: id of the rx.upload.root component to drive; also the suffix used for its upload/cancel button ids.
832 progress_fixture: name of the fixture providing the progress dicts callable.
833 exp_name: name of the file to upload.
834 file_size_bytes: size of the file to create, in bytes.
835 partial_subdir: subdirectory under the upload dir where a partial file is expected, or None if no partial file is written.
836 """
837 assert upload_file.app_instance is not None
838 progress_dicts: Callable[[], list[WebElement]] = request.getfixturevalue(
839 progress_fixture
840 )
841 poll_for_token(driver, upload_file)
842
843 upload_box = get_upload_box(driver, upload_root_id=upload_root_id)
844 upload_button = driver.find_element(By.ID, f"upload_button_{upload_root_id}")
845 cancel_button = driver.find_element(By.ID, f"cancel_button_{upload_root_id}")
846
847 target_file = tmp_path / exp_name
848 with target_file.open("wb") as f:
849 f.seek(file_size_bytes)
850 f.write(b"0")
851
852 upload_box.send_keys(str(target_file))
853 upload_button.click()
854 # Check for at least 2 progress updates to ensure the upload is active.
855 AppHarness.expect(lambda: len(progress_dicts()) >= 2)
856 cancel_button.click()
857
858 # There should never be a final progress record for a cancelled upload.
859 for p in await poll_for_stopped_progress(progress_dicts):
860 assert p["progress"] != 1
861
862 assert not (rx.get_upload_dir() / exp_name).exists()
863
864 if partial_subdir is not None:
865 partial_path = rx.get_upload_dir() / partial_subdir / exp_name
866 assert partial_path.exists()

Callers

nothing calls this directly

Calls 8

get_upload_boxFunction · 0.85
progress_dictsFunction · 0.85
openMethod · 0.80
expectMethod · 0.80
existsMethod · 0.80
unlinkMethod · 0.80
poll_for_tokenFunction · 0.70

Tested by

no test coverage detected