You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2021/12/02 16:48:18 UTC

[superset] branch master updated: chore: Added unit test to query context change (#17624)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new b13d953  chore: Added unit test to query context change (#17624)
b13d953 is described below

commit b13d953b34d6591850f1197fe4e17cb345d4cc0b
Author: AAfghahi <48...@users.noreply.github.com>
AuthorDate: Thu Dec 2 11:46:25 2021 -0500

    chore: Added unit test to query context change (#17624)
    
    * a lot of console logs
    
    * added unit test
---
 tests/integration_tests/charts/commands_tests.py   | 44 ++++++++++++++++++++++
 .../integration_tests/fixtures/energy_dashboard.py |  1 +
 2 files changed, 45 insertions(+)

diff --git a/tests/integration_tests/charts/commands_tests.py b/tests/integration_tests/charts/commands_tests.py
index 6d578b8..caedb6a 100644
--- a/tests/integration_tests/charts/commands_tests.py
+++ b/tests/integration_tests/charts/commands_tests.py
@@ -68,6 +68,7 @@ class TestExportChartsCommand(SupersetTestCase):
         metadata = yaml.safe_load(
             contents[f"charts/Energy_Sankey_{example_chart.id}.yaml"]
         )
+
         assert metadata == {
             "slice_name": "Energy Sankey",
             "viz_type": "sankey",
@@ -87,6 +88,49 @@ class TestExportChartsCommand(SupersetTestCase):
 
     @patch("superset.security.manager.g")
     @pytest.mark.usefixtures("load_energy_table_with_slice")
+    def test_export_chart_with_query_context(self, mock_g):
+        """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):
         """Test that users can't export datasets they don't have access to"""
         mock_g.user = security_manager.find_user("gamma")
diff --git a/tests/integration_tests/fixtures/energy_dashboard.py b/tests/integration_tests/fixtures/energy_dashboard.py
index 2c25eec..1447105 100644
--- a/tests/integration_tests/fixtures/energy_dashboard.py
+++ b/tests/integration_tests/fixtures/energy_dashboard.py
@@ -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"}',
         },
     ]