-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3051 from plotly/fix/bg-cookies
Add request data to callback_context
- Loading branch information
Showing
6 changed files
with
114 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from dash import Dash, Input, Output, html, callback, ctx | ||
|
||
from tests.integration.long_callback.utils import get_long_callback_manager | ||
|
||
long_callback_manager = get_long_callback_manager() | ||
handle = long_callback_manager.handle | ||
|
||
app = Dash(__name__, background_callback_manager=long_callback_manager) | ||
|
||
app.layout = html.Div( | ||
[ | ||
html.Button("set-cookies", id="set-cookies"), | ||
html.Button("use-cookies", id="use-cookies"), | ||
html.Div(id="intermediate"), | ||
html.Div("output", id="output"), | ||
] | ||
) | ||
app.test_lock = lock = long_callback_manager.test_lock | ||
|
||
|
||
@callback( | ||
Output("intermediate", "children"), | ||
Input("set-cookies", "n_clicks"), | ||
prevent_initial_call=True, | ||
) | ||
def set_cookies(_): | ||
ctx.response.set_cookie("bg-cookie", "cookie-value") | ||
return "ok" | ||
|
||
|
||
@callback( | ||
Output("output", "children"), | ||
Input("use-cookies", "n_clicks"), | ||
prevent_initial_call=True, | ||
background=True, | ||
) | ||
def use_cookies(_): | ||
value = ctx.cookies.get("bg-cookie") | ||
return value | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from tests.integration.long_callback.utils import setup_long_callback_app | ||
|
||
|
||
def test_lcbc019_ctx_cookies(dash_duo, manager): | ||
with setup_long_callback_app(manager, "app_ctx_cookies") as app: | ||
dash_duo.start_server(app) | ||
|
||
dash_duo.find_element("#set-cookies").click() | ||
dash_duo.wait_for_contains_text("#intermediate", "ok") | ||
|
||
dash_duo.find_element("#use-cookies").click() | ||
dash_duo.wait_for_contains_text("#output", "cookie-value") |