forked from zauberzeug/nicegui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added documentation for app.storage.client
Dropped implementation client.current_client for now Added exceptions for calls to app.storage.client from auto index or w/o client connection. Added tests for changes
- Loading branch information
Showing
4 changed files
with
98 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,51 @@ | ||
from nicegui import ui, app | ||
import pytest | ||
|
||
from nicegui import ui, app, context | ||
from nicegui.testing import Screen | ||
|
||
|
||
def test_session_state(screen: Screen): | ||
app.storage.client['counter'] = 123 | ||
|
||
def increment(): | ||
app.storage.client['counter'] = app.storage.client['counter'] + 1 | ||
|
||
ui.button('Increment').on_click(increment) | ||
ui.label().bind_text(app.storage.client, 'counter') | ||
@ui.page('/') | ||
async def page(): | ||
await context.get_client().connected() | ||
app.storage.client['counter'] = 123 | ||
ui.button('Increment').on_click(increment) | ||
ui.label().bind_text(app.storage.client, 'counter') | ||
ui.button('Increment').on_click(increment) | ||
ui.label().bind_text(app.storage.client, 'counter') | ||
|
||
screen.open('/') | ||
screen.should_contain('123') | ||
screen.click('Increment') | ||
screen.wait_for('124') | ||
screen.switch_to(1) | ||
screen.open('/') | ||
screen.should_contain('123') | ||
screen.switch_to(0) | ||
screen.should_contain('124') | ||
|
||
|
||
def test_no_connection(screen: Screen): | ||
@ui.page('/') | ||
async def page(): | ||
with pytest.raises(RuntimeError): # no connection yet | ||
app.storage.client['counter'] = 123 | ||
|
||
screen.open('/') | ||
|
||
|
||
def test_clear(screen: Screen): | ||
app.storage.client['counter'] = 123 | ||
app.storage.client.clear() | ||
assert 'counter' not in app.storage.client | ||
with pytest.raises(RuntimeError): # no context (auto index) | ||
app.storage.client.clear() | ||
|
||
@ui.page('/') | ||
async def page(): | ||
await context.get_client().connected() | ||
app.storage.client['counter'] = 123 | ||
app.storage.client.clear() | ||
assert 'counter' not in app.storage.client | ||
|
||
screen.open('/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters