mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix(mcp): Chart schema followups - DRY extraction, template fix, alias and test gaps (#38746)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
committed by
Michael S. Molina
parent
c2b3d36435
commit
d7633752bd
@@ -286,6 +286,74 @@ class TestXYChartConfig:
|
||||
assert config.group_by is not None
|
||||
assert len(config.group_by) == 2
|
||||
|
||||
def test_group_by_bare_string(self) -> None:
|
||||
"""Test that group_by accepts a bare string (auto-wrapped)."""
|
||||
config = XYChartConfig(
|
||||
chart_type="xy",
|
||||
x=ColumnRef(name="territory"),
|
||||
y=[ColumnRef(name="sales", aggregate="SUM")],
|
||||
kind="bar",
|
||||
group_by="region",
|
||||
)
|
||||
assert config.group_by is not None
|
||||
assert len(config.group_by) == 1
|
||||
assert config.group_by[0].name == "region"
|
||||
|
||||
def test_orientation_horizontal_accepted(self) -> None:
|
||||
"""Test that orientation='horizontal' is accepted for bar charts."""
|
||||
config = XYChartConfig(
|
||||
chart_type="xy",
|
||||
x=ColumnRef(name="department"),
|
||||
y=[ColumnRef(name="headcount", aggregate="SUM")],
|
||||
kind="bar",
|
||||
orientation="horizontal",
|
||||
)
|
||||
assert config.orientation == "horizontal"
|
||||
|
||||
def test_orientation_vertical_accepted(self) -> None:
|
||||
"""Test that orientation='vertical' is accepted for bar charts."""
|
||||
config = XYChartConfig(
|
||||
chart_type="xy",
|
||||
x=ColumnRef(name="category"),
|
||||
y=[ColumnRef(name="sales", aggregate="SUM")],
|
||||
kind="bar",
|
||||
orientation="vertical",
|
||||
)
|
||||
assert config.orientation == "vertical"
|
||||
|
||||
def test_orientation_none_by_default(self) -> None:
|
||||
"""Test that orientation defaults to None when not specified."""
|
||||
config = XYChartConfig(
|
||||
chart_type="xy",
|
||||
x=ColumnRef(name="category"),
|
||||
y=[ColumnRef(name="sales", aggregate="SUM")],
|
||||
kind="bar",
|
||||
)
|
||||
assert config.orientation is None
|
||||
|
||||
def test_orientation_invalid_value_rejected(self) -> None:
|
||||
"""Test that invalid orientation values are rejected."""
|
||||
with pytest.raises(ValidationError):
|
||||
XYChartConfig(
|
||||
chart_type="xy",
|
||||
x=ColumnRef(name="category"),
|
||||
y=[ColumnRef(name="sales", aggregate="SUM")],
|
||||
kind="bar",
|
||||
orientation="diagonal",
|
||||
)
|
||||
|
||||
def test_orientation_with_non_bar_chart(self) -> None:
|
||||
"""Test that orientation field is accepted on non-bar charts at schema level."""
|
||||
config = XYChartConfig(
|
||||
chart_type="xy",
|
||||
x=ColumnRef(name="date"),
|
||||
y=[ColumnRef(name="revenue", aggregate="SUM")],
|
||||
kind="line",
|
||||
orientation="horizontal",
|
||||
)
|
||||
# Schema allows it; the chart_utils layer decides whether to apply it
|
||||
assert config.orientation == "horizontal"
|
||||
|
||||
|
||||
class TestRowLimit:
|
||||
"""Test row_limit field on chart configs."""
|
||||
|
||||
Reference in New Issue
Block a user