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

Function test_upload_file_multiple

tests/integration/test_upload.py:636–681  ·  view source on GitHub ↗

Submit several file uploads and check that they arrived on the backend. Args: tmp_path: pytest tmp_path fixture upload_file: harness for UploadFile app. driver: WebDriver instance.

(tmp_path, upload_file: AppHarness, driver)

Source from the content-addressed store, hash-verified

634
635@pytest.mark.asyncio
636async def test_upload_file_multiple(tmp_path, upload_file: AppHarness, driver):
637 """Submit several file uploads and check that they arrived on the backend.
638
639 Args:
640 tmp_path: pytest tmp_path fixture
641 upload_file: harness for UploadFile app.
642 driver: WebDriver instance.
643 """
644 assert upload_file.app_instance is not None
645 poll_for_token(driver, upload_file)
646 clear_btn = driver.find_element(By.ID, "clear_uploads")
647 clear_btn.click()
648
649 upload_box = get_upload_box(driver)
650 assert upload_box
651 upload_button = driver.find_element(By.ID, "upload_button")
652 assert upload_button
653
654 exp_files = {
655 "test1.txt": "test file contents!",
656 "test2.txt": "this is test file number 2!",
657 "reflex.txt": "reflex is awesome!",
658 }
659 for exp_name, exp_contents in exp_files.items():
660 target_file = tmp_path / exp_name
661 target_file.write_text(exp_contents)
662 upload_box.send_keys(str(target_file))
663
664 await asyncio.sleep(0.2)
665
666 # check that the selected files are displayed
667 selected_files = driver.find_element(By.ID, "selected_files")
668 assert [Path(name).name for name in selected_files.text.split("\n")] == [
669 Path(name).name for name in exp_files
670 ]
671
672 # do the upload
673 upload_button.click()
674
675 # Wait for the upload to complete.
676 upload_done = driver.find_element(By.ID, "upload_done")
677 assert upload_file.poll_for_value(upload_done, exp_not_equal="false") == "true"
678
679 for exp_name, exp_content in exp_files.items():
680 actual_contents = (rx.get_upload_dir() / exp_name).read_text()
681 assert actual_contents == exp_content
682
683
684def test_upload_file_with_bound_arg(

Callers

nothing calls this directly

Calls 6

get_upload_boxFunction · 0.85
PathClass · 0.85
itemsMethod · 0.80
splitMethod · 0.80
poll_for_valueMethod · 0.80
poll_for_tokenFunction · 0.70

Tested by

no test coverage detected