Submit a file upload and check that it arrived on the backend. Args: tmp_path: pytest tmp_path fixture upload_file: harness for UploadFile app. driver: WebDriver instance. progress_dicts: callable to retrieve progress dictionary elements. upload_root_id:
(
tmp_path,
upload_file: AppHarness,
driver: WebDriver,
progress_dicts: Callable[[], list[WebElement]],
upload_root_id: str | None,
)
| 577 | |
| 578 | @pytest.mark.parametrize("upload_root_id", [None, "secondary"]) |
| 579 | def test_upload_file( |
| 580 | tmp_path, |
| 581 | upload_file: AppHarness, |
| 582 | driver: WebDriver, |
| 583 | progress_dicts: Callable[[], list[WebElement]], |
| 584 | upload_root_id: str | None, |
| 585 | ): |
| 586 | """Submit a file upload and check that it arrived on the backend. |
| 587 | |
| 588 | Args: |
| 589 | tmp_path: pytest tmp_path fixture |
| 590 | upload_file: harness for UploadFile app. |
| 591 | driver: WebDriver instance. |
| 592 | progress_dicts: callable to retrieve progress dictionary elements. |
| 593 | upload_root_id: ID of the upload root element, or None for the default. |
| 594 | """ |
| 595 | assert upload_file.app_instance is not None |
| 596 | poll_for_token(driver, upload_file) |
| 597 | clear_btn = driver.find_element(By.ID, "clear_uploads") |
| 598 | clear_btn.click() |
| 599 | |
| 600 | suffix = f"_{upload_root_id}" if upload_root_id else "" |
| 601 | |
| 602 | upload_box = get_upload_box(driver, upload_root_id=upload_root_id) |
| 603 | assert upload_box |
| 604 | upload_button = driver.find_element(By.ID, f"upload_button{suffix}") |
| 605 | assert upload_button |
| 606 | |
| 607 | exp_name = "test.txt" |
| 608 | exp_contents = "test file contents!" |
| 609 | target_file = tmp_path / exp_name |
| 610 | target_file.write_text(exp_contents) |
| 611 | |
| 612 | upload_box.send_keys(str(target_file)) |
| 613 | upload_button.click() |
| 614 | |
| 615 | # check that the selected files are displayed |
| 616 | selected_files = driver.find_element(By.ID, f"selected_files{suffix}") |
| 617 | assert Path(selected_files.text).name == Path(exp_name).name |
| 618 | |
| 619 | # Wait for the upload to complete. |
| 620 | upload_done = driver.find_element(By.ID, "upload_done") |
| 621 | assert upload_file.poll_for_value(upload_done, exp_not_equal="false") == "true" |
| 622 | |
| 623 | if upload_root_id == "secondary": |
| 624 | event_order_displayed = driver.find_element(By.ID, "event-order") |
| 625 | AppHarness.expect(lambda: "chain_event" in event_order_displayed.text) |
| 626 | final_progress = progress_dicts() |
| 627 | assert len(final_progress) > 0 |
| 628 | assert json.loads(final_progress[-1].text)["progress"] == 1 |
| 629 | |
| 630 | # look up the backend state and assert on uploaded contents |
| 631 | actual_contents = (rx.get_upload_dir() / exp_name).read_text() |
| 632 | assert actual_contents == exp_contents |
| 633 | |
| 634 | |
| 635 | @pytest.mark.asyncio |
nothing calls this directly
no test coverage detected