|
| 1 | +import requests |
| 2 | + |
| 3 | + |
| 4 | +import dash_core_components as dcc |
| 5 | +import dash_html_components as html |
| 6 | +import dash |
| 7 | +from dash.dependencies import Input, Output |
| 8 | + |
| 9 | + |
| 10 | +def test_cbmf001_bad_output_outputs(dash_thread_server): |
| 11 | + app = dash.Dash(__name__) |
| 12 | + app.layout = html.Div( |
| 13 | + [ |
| 14 | + dcc.Input(id="i", value="initial value"), |
| 15 | + html.Div(html.Div([1.5, None, "string", html.Div(id="o1")])), |
| 16 | + ] |
| 17 | + ) |
| 18 | + |
| 19 | + @app.callback(Output("o1", "children"), [Input("i", "value")]) |
| 20 | + def update_output(value): |
| 21 | + return value |
| 22 | + |
| 23 | + dash_thread_server(app) |
| 24 | + |
| 25 | + # first a good request |
| 26 | + response = requests.post( |
| 27 | + dash_thread_server.url + "/_dash-update-component", |
| 28 | + json=dict( |
| 29 | + output="o1.children", |
| 30 | + outputs={"id": "o1", "property": "children"}, |
| 31 | + inputs=[{"id": "i", "property": "value", "value": 9}], |
| 32 | + changedPropIds=["i.value"], |
| 33 | + ), |
| 34 | + ) |
| 35 | + assert response.status_code == 200 |
| 36 | + assert '"o1": {"children": 9}' in response.text |
| 37 | + |
| 38 | + # now some bad ones |
| 39 | + outspecs = [ |
| 40 | + {"output": "o1.nope", "outputs": {"id": "o1", "property": "nope"}}, |
| 41 | + {"output": "o1.children", "outputs": {"id": "o1", "property": "nope"}}, |
| 42 | + {"output": "o1.nope", "outputs": {"id": "o1", "property": "children"}}, |
| 43 | + {"output": "o1.children", "outputs": {"id": "nope", "property": "children"}}, |
| 44 | + {"output": "nope.children", "outputs": {"id": "nope", "property": "children"}}, |
| 45 | + ] |
| 46 | + for outspeci in outspecs: |
| 47 | + response = requests.post( |
| 48 | + dash_thread_server.url + "/_dash-update-component", |
| 49 | + json=dict( |
| 50 | + inputs=[{"id": "i", "property": "value", "value": 9}], |
| 51 | + changedPropIds=["i.value"], |
| 52 | + **outspeci |
| 53 | + ), |
| 54 | + ) |
| 55 | + assert response.status_code == 500 |
| 56 | + assert "o1" not in response.text |
| 57 | + assert "children" not in response.text |
| 58 | + assert "nope" not in response.text |
| 59 | + assert "500 Internal Server Error" in response.text |
0 commit comments