semantics
This commit is contained in:
@@ -3,9 +3,7 @@
|
||||
# @SEMANTICS: tests, superset, preview, chart_data, network, 404-mapping
|
||||
# @PURPOSE: Verify explicit chart-data preview compilation and ensure non-dashboard 404 errors remain generic across sync and async clients.
|
||||
# @LAYER: Domain
|
||||
# @RELATION: [BINDS_TO] ->[SupersetClient]
|
||||
# @RELATION: [BINDS_TO] ->[APIClient]
|
||||
# @RELATION: [BINDS_TO] ->[AsyncAPIClient]
|
||||
# @RELATION: [BINDS_TO] ->[AsyncNetworkModule]
|
||||
|
||||
import json
|
||||
from unittest.mock import MagicMock
|
||||
@@ -29,11 +27,15 @@ def _make_environment() -> Environment:
|
||||
username="demo",
|
||||
password="secret",
|
||||
)
|
||||
|
||||
|
||||
# [/DEF:_make_environment:Function]
|
||||
|
||||
|
||||
# [DEF:_make_requests_http_error:Function]
|
||||
def _make_requests_http_error(status_code: int, url: str) -> requests.exceptions.HTTPError:
|
||||
def _make_requests_http_error(
|
||||
status_code: int, url: str
|
||||
) -> requests.exceptions.HTTPError:
|
||||
response = requests.Response()
|
||||
response.status_code = status_code
|
||||
response.url = url
|
||||
@@ -41,14 +43,20 @@ def _make_requests_http_error(status_code: int, url: str) -> requests.exceptions
|
||||
request = requests.Request("GET", url).prepare()
|
||||
response.request = request
|
||||
return requests.exceptions.HTTPError(response=response, request=request)
|
||||
|
||||
|
||||
# [/DEF:_make_requests_http_error:Function]
|
||||
|
||||
|
||||
# [DEF:_make_httpx_status_error:Function]
|
||||
def _make_httpx_status_error(status_code: int, url: str) -> httpx.HTTPStatusError:
|
||||
request = httpx.Request("GET", url)
|
||||
response = httpx.Response(status_code=status_code, request=request, text='{"message":"not found"}')
|
||||
response = httpx.Response(
|
||||
status_code=status_code, request=request, text='{"message":"not found"}'
|
||||
)
|
||||
return httpx.HTTPStatusError("upstream error", request=request, response=response)
|
||||
|
||||
|
||||
# [/DEF:_make_httpx_status_error:Function]
|
||||
|
||||
|
||||
@@ -80,7 +88,10 @@ def test_compile_dataset_preview_prefers_legacy_explore_form_data_strategy():
|
||||
effective_filters=[{"filter_name": "country", "effective_value": ["DE"]}],
|
||||
)
|
||||
|
||||
assert result["compiled_sql"] == "SELECT count(*) FROM public.sales WHERE country IN ('DE')"
|
||||
assert (
|
||||
result["compiled_sql"]
|
||||
== "SELECT count(*) FROM public.sales WHERE country IN ('DE')"
|
||||
)
|
||||
client.network.request.assert_called_once()
|
||||
request_call = client.network.request.call_args
|
||||
assert request_call.kwargs["method"] == "POST"
|
||||
@@ -129,8 +140,11 @@ def test_compile_dataset_preview_prefers_legacy_explore_form_data_strategy():
|
||||
"success": True,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
# [/DEF:test_compile_dataset_preview_prefers_legacy_explore_form_data_strategy:Function]
|
||||
|
||||
|
||||
# [DEF:test_compile_dataset_preview_falls_back_to_chart_data_after_legacy_failures:Function]
|
||||
# @PURPOSE: Superset preview compilation should fall back to chart-data when legacy form_data strategies are rejected.
|
||||
def test_compile_dataset_preview_falls_back_to_chart_data_after_legacy_failures():
|
||||
@@ -180,7 +194,9 @@ def test_compile_dataset_preview_falls_back_to_chart_data_after_legacy_failures(
|
||||
assert len(result["strategy_attempts"]) == 3
|
||||
assert result["strategy_attempts"][0]["endpoint"] == "/explore_json/form_data"
|
||||
assert result["strategy_attempts"][0]["endpoint_kind"] == "legacy_explore_form_data"
|
||||
assert result["strategy_attempts"][0]["request_transport"] == "query_param_form_data"
|
||||
assert (
|
||||
result["strategy_attempts"][0]["request_transport"] == "query_param_form_data"
|
||||
)
|
||||
assert result["strategy_attempts"][0]["contains_root_datasource"] is False
|
||||
assert result["strategy_attempts"][0]["contains_form_datasource"] is False
|
||||
assert result["strategy_attempts"][0]["contains_query_object_datasource"] is False
|
||||
@@ -191,7 +207,9 @@ def test_compile_dataset_preview_falls_back_to_chart_data_after_legacy_failures(
|
||||
|
||||
assert result["strategy_attempts"][1]["endpoint"] == "/data"
|
||||
assert result["strategy_attempts"][1]["endpoint_kind"] == "legacy_data_form_data"
|
||||
assert result["strategy_attempts"][1]["request_transport"] == "query_param_form_data"
|
||||
assert (
|
||||
result["strategy_attempts"][1]["request_transport"] == "query_param_form_data"
|
||||
)
|
||||
assert result["strategy_attempts"][1]["contains_root_datasource"] is False
|
||||
assert result["strategy_attempts"][1]["contains_form_datasource"] is False
|
||||
assert result["strategy_attempts"][1]["contains_query_object_datasource"] is False
|
||||
@@ -208,9 +226,18 @@ def test_compile_dataset_preview_falls_back_to_chart_data_after_legacy_failures(
|
||||
"contains_form_datasource": False,
|
||||
"contains_query_object_datasource": False,
|
||||
"request_param_keys": [],
|
||||
"request_payload_keys": ["datasource", "force", "form_data", "queries", "result_format", "result_type"],
|
||||
"request_payload_keys": [
|
||||
"datasource",
|
||||
"force",
|
||||
"form_data",
|
||||
"queries",
|
||||
"result_format",
|
||||
"result_type",
|
||||
],
|
||||
"success": True,
|
||||
}
|
||||
|
||||
|
||||
# [/DEF:test_compile_dataset_preview_falls_back_to_chart_data_after_legacy_failures:Function]
|
||||
|
||||
|
||||
@@ -234,8 +261,12 @@ def test_build_dataset_preview_query_context_places_recovered_filters_in_chart_s
|
||||
"display_name": "Country",
|
||||
"effective_value": ["DE"],
|
||||
"normalized_filter_payload": {
|
||||
"filter_clauses": [{"col": "country_code", "op": "IN", "val": ["DE"]}],
|
||||
"extra_form_data": {"filters": [{"col": "country_code", "op": "IN", "val": ["DE"]}]},
|
||||
"filter_clauses": [
|
||||
{"col": "country_code", "op": "IN", "val": ["DE"]}
|
||||
],
|
||||
"extra_form_data": {
|
||||
"filters": [{"col": "country_code", "op": "IN", "val": ["DE"]}]
|
||||
},
|
||||
"value_origin": "extra_form_data.filters",
|
||||
},
|
||||
},
|
||||
@@ -267,6 +298,8 @@ def test_build_dataset_preview_query_context_places_recovered_filters_in_chart_s
|
||||
"time_range": "Last year",
|
||||
}
|
||||
assert query_context["form_data"]["url_params"] == {"country": "DE"}
|
||||
|
||||
|
||||
# [/DEF:test_build_dataset_preview_query_context_places_recovered_filters_in_chart_style_form_data:Function]
|
||||
|
||||
|
||||
@@ -287,8 +320,16 @@ def test_build_dataset_preview_query_context_merges_dataset_template_params_and_
|
||||
effective_filters=[],
|
||||
)
|
||||
|
||||
assert query_context["queries"][0]["url_params"] == {"region": "EMEA", "country": "DE"}
|
||||
assert query_context["form_data"]["url_params"] == {"region": "EMEA", "country": "DE"}
|
||||
assert query_context["queries"][0]["url_params"] == {
|
||||
"region": "EMEA",
|
||||
"country": "DE",
|
||||
}
|
||||
assert query_context["form_data"]["url_params"] == {
|
||||
"region": "EMEA",
|
||||
"country": "DE",
|
||||
}
|
||||
|
||||
|
||||
# [/DEF:test_build_dataset_preview_query_context_merges_dataset_template_params_and_preserves_user_values:Function]
|
||||
|
||||
|
||||
@@ -325,6 +366,8 @@ def test_build_dataset_preview_query_context_preserves_time_range_from_native_fi
|
||||
"time_range": "2020-01-01 : 2020-12-31"
|
||||
}
|
||||
assert query_context["queries"][0]["filters"] == []
|
||||
|
||||
|
||||
# [/DEF:test_build_dataset_preview_query_context_preserves_time_range_from_native_filter_payload:Function]
|
||||
|
||||
|
||||
@@ -348,9 +391,13 @@ def test_build_dataset_preview_legacy_form_data_preserves_native_filter_clauses(
|
||||
"display_name": "Country",
|
||||
"effective_value": ["DE", "FR"],
|
||||
"normalized_filter_payload": {
|
||||
"filter_clauses": [{"col": "country_code", "op": "IN", "val": ["DE", "FR"]}],
|
||||
"filter_clauses": [
|
||||
{"col": "country_code", "op": "IN", "val": ["DE", "FR"]}
|
||||
],
|
||||
"extra_form_data": {
|
||||
"filters": [{"col": "country_code", "op": "IN", "val": ["DE", "FR"]}],
|
||||
"filters": [
|
||||
{"col": "country_code", "op": "IN", "val": ["DE", "FR"]}
|
||||
],
|
||||
"time_range": "Last quarter",
|
||||
},
|
||||
"value_origin": "extra_form_data.filters",
|
||||
@@ -372,6 +419,8 @@ def test_build_dataset_preview_legacy_form_data_preserves_native_filter_clauses(
|
||||
assert legacy_form_data["time_range"] == "Last quarter"
|
||||
assert legacy_form_data["url_params"] == {"country": "DE"}
|
||||
assert legacy_form_data["result_type"] == "query"
|
||||
|
||||
|
||||
# [/DEF:test_build_dataset_preview_legacy_form_data_preserves_native_filter_clauses:Function]
|
||||
|
||||
|
||||
@@ -393,6 +442,8 @@ def test_sync_network_404_mapping_keeps_non_dashboard_endpoints_generic():
|
||||
|
||||
assert not isinstance(exc_info.value, DashboardNotFoundError)
|
||||
assert "API resource not found at endpoint '/chart/data'" in str(exc_info.value)
|
||||
|
||||
|
||||
# [/DEF:test_sync_network_404_mapping_keeps_non_dashboard_endpoints_generic:Function]
|
||||
|
||||
|
||||
@@ -413,6 +464,8 @@ def test_sync_network_404_mapping_translates_dashboard_endpoints():
|
||||
)
|
||||
|
||||
assert "Dashboard '/dashboard/10' Dashboard not found" in str(exc_info.value)
|
||||
|
||||
|
||||
# [/DEF:test_sync_network_404_mapping_translates_dashboard_endpoints:Function]
|
||||
|
||||
|
||||
@@ -430,7 +483,9 @@ async def test_async_network_404_mapping_keeps_non_dashboard_endpoints_generic()
|
||||
try:
|
||||
with pytest.raises(SupersetAPIError) as exc_info:
|
||||
client._handle_http_error(
|
||||
_make_httpx_status_error(404, "http://superset.local/api/v1/chart/data"),
|
||||
_make_httpx_status_error(
|
||||
404, "http://superset.local/api/v1/chart/data"
|
||||
),
|
||||
"/chart/data",
|
||||
)
|
||||
|
||||
@@ -438,6 +493,8 @@ async def test_async_network_404_mapping_keeps_non_dashboard_endpoints_generic()
|
||||
assert "API resource not found at endpoint '/chart/data'" in str(exc_info.value)
|
||||
finally:
|
||||
await client.aclose()
|
||||
|
||||
|
||||
# [/DEF:test_async_network_404_mapping_keeps_non_dashboard_endpoints_generic:Function]
|
||||
|
||||
|
||||
@@ -455,14 +512,18 @@ async def test_async_network_404_mapping_translates_dashboard_endpoints():
|
||||
try:
|
||||
with pytest.raises(DashboardNotFoundError) as exc_info:
|
||||
client._handle_http_error(
|
||||
_make_httpx_status_error(404, "http://superset.local/api/v1/dashboard/10"),
|
||||
_make_httpx_status_error(
|
||||
404, "http://superset.local/api/v1/dashboard/10"
|
||||
),
|
||||
"/dashboard/10",
|
||||
)
|
||||
|
||||
assert "Dashboard '/dashboard/10' Dashboard not found" in str(exc_info.value)
|
||||
finally:
|
||||
await client.aclose()
|
||||
|
||||
|
||||
# [/DEF:test_async_network_404_mapping_translates_dashboard_endpoints:Function]
|
||||
|
||||
|
||||
# [/DEF:SupersetPreviewPipelineTests:Module]
|
||||
# [/DEF:SupersetPreviewPipelineTests:Module]
|
||||
|
||||
Reference in New Issue
Block a user