1
1
from dash .exceptions import PreventUpdate
2
2
from dash import Dash , Input , Output , dcc , html
3
3
import flask
4
+ import pytest
4
5
import time
5
6
6
7
7
- def test_llgo001_location_logout (dash_dcc ):
8
+ @pytest .mark .parametrize ("add_initial_logout_button" , [False , True ])
9
+ def test_llgo001_location_logout (dash_dcc , add_initial_logout_button ):
8
10
app = Dash (__name__ )
9
11
10
12
@app .server .route ("/_logout" , methods = ["POST" ])
@@ -13,9 +15,14 @@ def on_logout():
13
15
rep .set_cookie ("logout-cookie" , "" , 0 )
14
16
return rep
15
17
16
- app .layout = html .Div (
17
- [html .H2 ("Logout test" ), dcc .Location (id = "location" ), html .Div (id = "content" )]
18
- )
18
+ layout_children = [
19
+ html .H2 ("Logout test" ),
20
+ dcc .Location (id = "location" ),
21
+ html .Div (id = "content" ),
22
+ ]
23
+ if add_initial_logout_button :
24
+ layout_children .append (dcc .LogoutButton ())
25
+ app .layout = html .Div (layout_children )
19
26
20
27
@app .callback (Output ("content" , "children" ), [Input ("location" , "pathname" )])
21
28
def on_location (location_path ):
@@ -33,15 +40,19 @@ def _insert_cookie(rep):
33
40
34
41
return dcc .LogoutButton (id = "logout-btn" , logout_url = "/_logout" )
35
42
36
- dash_dcc .start_server (app )
37
- time .sleep (1 )
38
- dash_dcc .percy_snapshot ("Core Logout button" )
43
+ with pytest .warns (
44
+ DeprecationWarning ,
45
+ match = "The Logout Button is no longer used with Dash Enterprise and can be replaced with a html.Button or html.A." ,
46
+ ):
47
+ dash_dcc .start_server (app )
48
+ time .sleep (1 )
49
+ dash_dcc .percy_snapshot ("Core Logout button" )
39
50
40
- assert dash_dcc .driver .get_cookie ("logout-cookie" )["value" ] == "logged-in"
51
+ assert dash_dcc .driver .get_cookie ("logout-cookie" )["value" ] == "logged-in"
41
52
42
- dash_dcc .wait_for_element ("#logout-btn" ).click ()
43
- dash_dcc .wait_for_text_to_equal ("#content" , "Logged out" )
53
+ dash_dcc .wait_for_element ("#logout-btn" ).click ()
54
+ dash_dcc .wait_for_text_to_equal ("#content" , "Logged out" )
44
55
45
- assert not dash_dcc .driver .get_cookie ("logout-cookie" )
56
+ assert not dash_dcc .driver .get_cookie ("logout-cookie" )
46
57
47
- assert dash_dcc .get_logs () == []
58
+ assert dash_dcc .get_logs () == []
0 commit comments