1
-
2
1
from dash import (
3
2
Dash ,
4
3
Input ,
10
9
import json
11
10
from flask import jsonify
12
11
13
- test_string = ('{"step_0": "Data fetched - 1", "step_1": "Data fetched - 1", "step_2": "Data fetched - 1", '
14
- '"step_3": "Data fetched - 1", "step_4": "Data fetched - 1"}' )
12
+ test_string = (
13
+ '{"step_0": "Data fetched - 1", "step_1": "Data fetched - 1", "step_2": "Data fetched - 1", '
14
+ '"step_3": "Data fetched - 1", "step_4": "Data fetched - 1"}'
15
+ )
16
+
15
17
16
18
def test_apib001_api_callback (dash_duo ):
17
19
18
20
app = Dash (__name__ )
19
- app .layout = html .Div ([
20
- html .Button ("Slow Callback" , id = "slow-btn" ),
21
- html .Div (id = "slow-output" ),
22
- ])
21
+ app .layout = html .Div (
22
+ [
23
+ html .Button ("Slow Callback" , id = "slow-btn" ),
24
+ html .Div (id = "slow-output" ),
25
+ ]
26
+ )
23
27
24
28
def get_data (n_clicks ):
25
29
# Simulate an async data fetch
@@ -29,12 +33,12 @@ def get_data(n_clicks):
29
33
Output ("slow-output" , "children" ),
30
34
Input ("slow-btn" , "n_clicks" ),
31
35
prevent_initial_call = True ,
32
- api_endpoint = ' /api/slow_callback' , # Example API path for the slow callback
36
+ api_endpoint = " /api/slow_callback" , # Example API path for the slow callback
33
37
)
34
38
def slow_callback (n_clicks ):
35
39
data = {}
36
40
for i in range (5 ):
37
- data [f' step_{ i } ' ] = get_data (n_clicks )
41
+ data [f" step_{ i } " ] = get_data (n_clicks )
38
42
ret = f"{ json .dumps (data )} "
39
43
if ctx :
40
44
return ret
@@ -46,8 +50,10 @@ def slow_callback(n_clicks):
46
50
47
51
dash_duo .wait_for_element ("#slow-btn" ).click ()
48
52
dash_duo .wait_for_text_to_equal ("#slow-output" , test_string )
49
- r = requests .post (dash_duo .server_url + '/api/slow_callback' ,
50
- json = {'n_clicks' : 1 },
51
- headers = {'Content-Type' : 'application/json' })
53
+ r = requests .post (
54
+ dash_duo .server_url + "/api/slow_callback" ,
55
+ json = {"n_clicks" : 1 },
56
+ headers = {"Content-Type" : "application/json" },
57
+ )
52
58
assert r .status_code == 200
53
59
assert r .json () == test_string
0 commit comments