Skip to content

Commit

Permalink
fix pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Jan 14, 2025
1 parent 55e9764 commit 44c7ec0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions nicegui/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from .app_config import AppConfig
from .range_response import get_range_response

SINGLE_USE_ROUTE_TIMEOUT = 10.0


class State(Enum):
STOPPED = 0
Expand Down Expand Up @@ -205,7 +207,7 @@ def add_static_file(self, *,
@self.get(path)
def read_item() -> FileResponse:
if single_use:
self._routes_to_remove[path] = time.time() + 10.0
self._routes_to_remove[path] = time.time() + SINGLE_USE_ROUTE_TIMEOUT
return FileResponse(file, headers={'Cache-Control': f'public, max-age={max_cache_age}'})

return urllib.parse.quote(path)
Expand Down Expand Up @@ -257,7 +259,7 @@ def add_media_file(self, *,
@self.get(path)
def read_item(request: Request, nicegui_chunk_size: int = 8192) -> Response:
if single_use:
self._routes_to_remove[path] = time.time() + 10.0
self._routes_to_remove[path] = time.time() + SINGLE_USE_ROUTE_TIMEOUT
return get_range_response(file, request, chunk_size=nicegui_chunk_size)

return urllib.parse.quote(path)
Expand Down Expand Up @@ -295,4 +297,4 @@ async def prune_single_use_routes(self) -> None:
for path in routes:
self.remove_route(path)
del self._routes_to_remove[path]
await asyncio.sleep(10.0)
await asyncio.sleep(SINGLE_USE_ROUTE_TIMEOUT)
2 changes: 2 additions & 0 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from fastapi.responses import PlainTextResponse

from nicegui import app, ui
from nicegui.app import app as app_module
from nicegui.testing import Screen, screen_plugin


Expand All @@ -31,6 +32,7 @@ def test():
def test_downloading_local_file_as_src(screen: Screen):
IMAGE_FILE = Path(__file__).parent.parent / 'examples' / 'slideshow' / 'slides' / 'slide1.jpg'
ui.button('download', on_click=lambda: ui.download(IMAGE_FILE))
app_module.SINGLE_USE_ROUTE_TIMEOUT = 0.1

screen.open('/')
route_count_before_download = len(app.routes)
Expand Down

0 comments on commit 44c7ec0

Please sign in to comment.