zhaoyongjie commented on code in PR #22196: URL: https://github.com/apache/superset/pull/22196#discussion_r1032731414
########## tests/integration_tests/charts/data/api_tests.py: ########## @@ -862,6 +862,59 @@ def test_chart_data_get(self): assert data["result"][0]["status"] == "success" assert data["result"][0]["rowcount"] == 2 + @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") + def test_chart_data_get_forced(self): + """ + Chart data API: Test GET endpoint with force cache parameter + """ + chart = db.session.query(Slice).filter_by(slice_name="Genders").one() + chart.query_context = json.dumps( + { + "datasource": {"id": chart.table.id, "type": "table"}, + "force": False, + "queries": [ + { + "time_range": "1900-01-01T00:00:00 : 2000-01-01T00:00:00", + "granularity": "ds", + "filters": [], + "extras": { + "having": "", + "having_druid": [], + "where": "", + }, + "applied_time_extras": {}, + "columns": ["gender"], + "metrics": ["sum__num"], + "orderby": [["sum__num", False]], + "annotation_layers": [], + "row_limit": 50000, + "timeseries_limit": 0, + "order_desc": True, + "url_params": {}, + "custom_params": {}, + "custom_form_data": {}, + } + ], + "result_format": "json", + "result_type": "full", + } + ) + + # wrapping original class, so we can test output too. + with mock.patch( + "superset.charts.data.api.ChartDataCommand", wraps=ChartDataCommand + ) as command: + rv = self.get_assert_metric( + f"api/v1/chart/{chart.id}/data/?force=true", "get_data" + ) + data = json.loads(rv.data.decode("utf-8")) + query_context = command.call_args.args[0] Review Comment: we should verify the `is_cached` field in the response. ```Python test_client.post(f"api/v1/chart/{chart.id}/data/?force=true") # should through cache rv = test_client.post(f"api/v1/chart/{chart.id}/data/?force=true") assert rv.json["result"][0]["is_cached"] is None test_client.post(f"api/v1/chart/{chart.id}/data") # should get response from the cache rv = test_client.post(f"api/v1/chart/{chart.id}/data/?force=true") assert rv.json["result"][0]["is_cached"] is not None ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org