(dash_duo)
| 16 | |
| 17 | |
| 18 | def test_apib001_api_callback(dash_duo): |
| 19 | |
| 20 | app = Dash(__name__) |
| 21 | app.layout = html.Div( |
| 22 | [ |
| 23 | html.Button("Slow Callback", id="slow-btn"), |
| 24 | html.Div(id="slow-output"), |
| 25 | ] |
| 26 | ) |
| 27 | |
| 28 | def get_data(n_clicks): |
| 29 | # Simulate an async data fetch |
| 30 | return f"Data fetched - {n_clicks}" |
| 31 | |
| 32 | @app.callback( |
| 33 | Output("slow-output", "children"), |
| 34 | Input("slow-btn", "n_clicks"), |
| 35 | prevent_initial_call=True, |
| 36 | api_endpoint="/api/slow_callback", # Example API path for the slow callback |
| 37 | ) |
| 38 | def slow_callback(n_clicks): |
| 39 | data = {} |
| 40 | for i in range(5): |
| 41 | data[f"step_{i}"] = get_data(n_clicks) |
| 42 | ret = f"{json.dumps(data)}" |
| 43 | if ctx: |
| 44 | return ret |
| 45 | return jsonify(ret) |
| 46 | |
| 47 | app.setup_apis() |
| 48 | |
| 49 | dash_duo.start_server(app) |
| 50 | |
| 51 | dash_duo.wait_for_element("#slow-btn").click() |
| 52 | dash_duo.wait_for_text_to_equal("#slow-output", test_string) |
| 53 | r = requests.post( |
| 54 | dash_duo.server_url + "/api/slow_callback", |
| 55 | json={"n_clicks": 1}, |
| 56 | headers={"Content-Type": "application/json"}, |
| 57 | ) |
| 58 | assert r.status_code == 200 |
| 59 | assert r.json() == test_string |
nothing calls this directly
no test coverage detected
searching dependent graphs…