MCPcopy Create free account
hub / github.com/dot-agent/nextpy / test_upload_file_multiple

Function test_upload_file_multiple

integration/test_upload.py:215–261  ·  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

213
214@pytest.mark.asyncio
215async def test_upload_file_multiple(tmp_path, upload_file: AppHarness, driver):
216 """Submit several file uploads and check that they arrived on the backend.
217
218 Args:
219 tmp_path: pytest tmp_path fixture
220 upload_file: harness for UploadFile app.
221 driver: WebDriver instance.
222 """
223 assert upload_file.app_instance is not None
224 token_input = driver.find_element(By.ID, "token")
225 assert token_input
226 # wait for the backend connection to send the token
227 token = upload_file.poll_for_value(token_input)
228 assert token is not None
229
230 upload_box = driver.find_element(By.XPATH, "//input[@type='file']")
231 assert upload_box
232 upload_button = driver.find_element(By.ID, "upload_button")
233 assert upload_button
234
235 exp_files = {
236 "test1.txt": "test file contents!",
237 "test2.txt": "this is test file number 2!",
238 "nextpy.txt": "nextpy is awesome!",
239 }
240 for exp_name, exp_contents in exp_files.items():
241 target_file = tmp_path / exp_name
242 target_file.write_text(exp_contents)
243 upload_box.send_keys(str(target_file))
244
245 time.sleep(0.2)
246
247 # check that the selected files are displayed
248 selected_files = driver.find_element(By.ID, "selected_files")
249 assert selected_files.text == "\n".join(exp_files)
250
251 # do the upload
252 upload_button.click()
253
254 # look up the backend state and assert on uploaded contents
255 async def get_file_data():
256 return (await upload_file.get_state(token)).substates["upload_state"]._file_data
257
258 file_data = await AppHarness._poll_for_async(get_file_data)
259 assert isinstance(file_data, dict)
260 for exp_name, exp_contents in exp_files.items():
261 assert file_data[exp_name] == exp_contents
262
263
264@pytest.mark.parametrize("secondary", [False, True])

Callers

nothing calls this directly

Calls 2

itemsMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected