Skip to content

Commit 03d3da5

Browse files
committed
make tests aware of difference in status codes when using async page builder
1 parent dd30a03 commit 03d3da5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_sub_pages.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
from typing import List, Optional
33

4+
import httpx
45
import pytest
56

67
from nicegui import PageArguments, background_tasks, ui
@@ -1087,6 +1088,24 @@ def main():
10871088

10881089
screen.open('/bad_path')
10891090
screen.should_contain('HTTPException: 404: /bad_path not found')
1091+
assert httpx.get(f'http://localhost:{Screen.PORT}/bad_path').status_code == 404
1092+
1093+
1094+
def test_http_404_on_initial_request_with_async_page_builder(screen: Screen):
1095+
@ui.page('/')
1096+
@ui.page('/{_:path}')
1097+
async def index():
1098+
ui.sub_pages({
1099+
'/': main,
1100+
})
1101+
1102+
def main():
1103+
ui.label('main page')
1104+
1105+
screen.open('/bad_path')
1106+
# NOTE: due to the async page builder, sub pages can not determine 404 status on initial request (see https://github.com/zauberzeug/nicegui/pull/5089)
1107+
screen.should_contain('404: sub page /bad_path not found')
1108+
assert httpx.get(f'http://localhost:{Screen.PORT}/bad_path').status_code == 200
10901109

10911110

10921111
def test_clearing_sub_pages_element(screen: Screen):

0 commit comments

Comments
 (0)