Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added unit test to query context change #17624

Merged
merged 6 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/integration_tests/charts/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_export_chart_command(self, mock_g):
metadata = yaml.safe_load(
contents[f"charts/Energy_Sankey_{example_chart.id}.yaml"]
)

assert metadata == {
"slice_name": "Energy Sankey",
"viz_type": "sankey",
Expand All @@ -85,6 +86,49 @@ def test_export_chart_command(self, mock_g):
"version": "1.0.0",
}

@patch("superset.security.manager.g")
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_export_chart_with_query_context(self, mock_g):
betodealmeida marked this conversation as resolved.
Show resolved Hide resolved
"""Test that charts that have a query_context are exported correctly"""

mock_g.user = security_manager.find_user("alpha")
example_chart = db.session.query(Slice).filter_by(slice_name="Heatmap").one()
command = ExportChartsCommand([example_chart.id])

contents = dict(command.run())

expected = [
"metadata.yaml",
f"charts/Heatmap_{example_chart.id}.yaml",
"datasets/examples/energy_usage.yaml",
"databases/examples.yaml",
]
assert expected == list(contents.keys())

metadata = yaml.safe_load(contents[f"charts/Heatmap_{example_chart.id}.yaml"])

assert metadata == {
"slice_name": "Heatmap",
"viz_type": "heatmap",
"params": {
"all_columns_x": "source",
"all_columns_y": "target",
"canvas_image_rendering": "pixelated",
"collapsed_fieldsets": "",
"linear_color_scheme": "blue_white_yellow",
"metric": "sum__value",
"normalize_across": "heatmap",
"slice_name": "Heatmap",
"viz_type": "heatmap",
"xscale_interval": "1",
"yscale_interval": "1",
},
"cache_timeout": None,
"dataset_uuid": str(example_chart.table.uuid),
"uuid": str(example_chart.uuid),
"version": "1.0.0",
}

@patch("superset.security.manager.g")
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_export_chart_command_no_access(self, mock_g):
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/fixtures/energy_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,6 @@ def _get_energy_slices():
"xscale_interval": "1",
"yscale_interval": "1",
},
"query_context": '{"datasource":{"id":12,"type":"table"},"force":false,"queries":[{"time_range":" : ","filters":[],"extras":{"time_grain_sqla":null,"having":"","having_druid":[],"where":""},"applied_time_extras":{},"columns":[],"metrics":[],"annotation_layers":[],"row_limit":5000,"timeseries_limit":0,"order_desc":true,"url_params":{},"custom_params":{},"custom_form_data":{}}],"result_format":"json","result_type":"full"}',
},
]