test_download.py 756 B

123456789101112131415161718192021222324252627282930313233
  1. from typing import Generator
  2. import pytest
  3. from fastapi import HTTPException
  4. from nicegui import app, ui
  5. from .screen import Screen
  6. @pytest.fixture
  7. def test_route() -> Generator[str, None, None]:
  8. TEST_ROUTE = '/static/test.py'
  9. yield TEST_ROUTE
  10. app.remove_route(TEST_ROUTE)
  11. def test_download(screen: Screen, test_route: str):
  12. success = False
  13. @app.get(test_route)
  14. def test():
  15. nonlocal success
  16. success = True
  17. raise HTTPException(404, 'Not found')
  18. ui.button('Download', on_click=lambda: ui.download(test_route))
  19. screen.open('/')
  20. screen.click('Download')
  21. screen.wait(0.5)
  22. assert success
  23. screen.assert_py_logger('WARNING', f'http://localhost:{Screen.PORT}{test_route} not found')