Replies: 6 comments 6 replies
-
Also with: from typing import Callable
import time
async def test_login(create_user: Callable[[], User]) -> None:
startup()
user = create_user() And the same test code I am getting the same issue. |
Beta Was this translation helpful? Give feedback.
-
On nicegui/tests/test_user_simulation.py Line 82 in 5032ca4 In my case also the code should just return that is not logged because the data is not found... @pytest.mark.parametrize('storage_builder', [lambda: app.storage.user])
async def test_login(user: User, storage_builder: Callable[[], Dict]) -> None:
startup()
storage_builder()
await user.open('/')
# print(user.client.layout)
user.find('Username').type('admin')
user.find('Password').type('password').trigger('keydown.enter')
time.sleep(2)
await user.should_see('Tasks') I get |
Beta Was this translation helpful? Give feedback.
-
What is |
Beta Was this translation helpful? Give feedback.
-
The minimal example: from nicegui.testing import User
from nicegui import ui, app
async def get_userid():
return app.storage.user.get('user_id', False)
async def test_minimal_login(user: User) -> None:
from fastapi.responses import RedirectResponse
@ui.page("/")
async def index():
if not await get_userid():
ui.navigate.to("/login")
@ui.page("/login")
async def login() -> RedirectResponse | None:
async def try_login() -> None:
ui.notify('logged')
if await get_userid():
ui.navigate.to("/dashboard")
with ui.card().classes("p-8 border-none flex flex-col items-center shadow-none absolute-center"):
ui.image("../static/images/logo-dark.png").classes("w-40")
username = (
ui.input("Username")
.classes("w-full")
.props('input-class="font-semibold"')
.on("keydown.enter", try_login)
)
password = (
ui.input("Password", password=True, password_toggle_button=True)
.classes("w-full")
.props('input-class="font-semibold"')
.on("keydown.enter", try_login)
)
ui.button("Log in", on_click=try_login).classes("font-extrabold")
await user.open('/')
user.find('Username').type('admin') With this minimal example I was able to see that the Changing the ui.navigate.to to At same time if I use |
Beta Was this translation helpful? Give feedback.
-
Thanks for trying to make the code minimal @Mte90. Still you have images, style definitions and more in the example which obscured the code. I boiled it down to this: """
Before running the test with pytest, install nicegui (pip install nicegui)
and create a pytest.ini beside this file with the following content:
[pytest]
asyncio_mode = auto
"""
from nicegui import ui
from nicegui.testing import User
pytest_plugins = ['nicegui.testing.user_plugin']
def startup():
@ui.page('/')
def index() -> None:
ui.label('Main Page')
ui.navigate.to('/login')
@ui.page('/login')
def login() -> None:
ui.input('Username')
async def test_navigate_to(user: User) -> None:
startup()
await user.open('/')
# await user.should_see('Username')
user.find('Username').type('admin')
if __name__ in ('__mp_main__', '__main__'):
startup()
ui.run() The problem is quite obvious and can be seen if you run the file to actually start the server: when accessing Your test has used |
Beta Was this translation helpful? Give feedback.
-
minimal code: async def test_navigate_to(user: User) -> None:
@ui.page('/')
def index() -> None:
ui.label('Main Page')
ui.navigate.to('/login')
@ui.page('/login')
def login() -> None:
print(321)
ui.input('Username')
await user.open('/')
# await user.should_see('Username')
user.find('Username').type('admin') In pytest with |
Beta Was this translation helpful? Give feedback.
-
Question
So I am trying to use https://nicegui.io/documentation/user but with this code something doesn't work.
login.py:
The tests stops at the first find:
I tried to add a
print
in the login.py but is not getting printed on pytest also with-s
parameter so maybe it is executed in another thread?Anyway I think that the login code get blocked at the
is_logged
function that is:But there is no error about what is happening, maybe there are no mocking functions for the
app
module?Beta Was this translation helpful? Give feedback.
All reactions