From 9c52557c97cc17199adf38116864c6632bdb0a47 Mon Sep 17 00:00:00 2001 From: Arash Date: Wed, 24 Nov 2021 11:03:24 -0700 Subject: [PATCH 1/2] a lot of console logs --- superset-frontend/src/SqlLab/components/App/index.jsx | 2 ++ superset-frontend/src/SqlLab/components/SqlEditor/index.jsx | 1 + .../src/SqlLab/components/TabbedSqlEditors/index.jsx | 4 ++++ superset-frontend/src/SqlLab/reducers/getInitialState.js | 1 + 4 files changed, 8 insertions(+) diff --git a/superset-frontend/src/SqlLab/components/App/index.jsx b/superset-frontend/src/SqlLab/components/App/index.jsx index bce43f477800e..8e6a70fc6b9d5 100644 --- a/superset-frontend/src/SqlLab/components/App/index.jsx +++ b/superset-frontend/src/SqlLab/components/App/index.jsx @@ -37,6 +37,8 @@ import QuerySearch from '../QuerySearch'; class App extends React.PureComponent { constructor(props) { super(props); + console.log('this is App'); + console.log(props); this.state = { hash: window.location.hash, }; diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx b/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx index 6197256666361..632788641b087 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx @@ -616,6 +616,7 @@ class SqlEditor extends React.PureComponent { )} ); + return (
diff --git a/superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx b/superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx index 090d4b740461d..708cc9f97270b 100644 --- a/superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx +++ b/superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx @@ -75,6 +75,7 @@ const userOS = detectOS(); class TabbedSqlEditors extends React.PureComponent { constructor(props) { super(props); + console.log('this is the tabbed', props); const sqlLabUrl = '/superset/sqllab'; this.state = { sqlLabUrl, @@ -93,6 +94,8 @@ class TabbedSqlEditors extends React.PureComponent { componentDidMount() { // migrate query editor and associated tables state to server + console.log('we here boys'); + console.log(this.props); if (isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)) { const localStorageTables = this.props.tables.filter( table => table.inLocalStorage, @@ -434,6 +437,7 @@ TabbedSqlEditors.propTypes = propTypes; TabbedSqlEditors.defaultProps = defaultProps; function mapStateToProps({ sqlLab, common, requestedQuery }) { + console.log(sqlLab); return { databases: sqlLab.databases, queryEditors: sqlLab.queryEditors, diff --git a/superset-frontend/src/SqlLab/reducers/getInitialState.js b/superset-frontend/src/SqlLab/reducers/getInitialState.js index 0eceebfa3ad2b..b6931045d6e85 100644 --- a/superset-frontend/src/SqlLab/reducers/getInitialState.js +++ b/superset-frontend/src/SqlLab/reducers/getInitialState.js @@ -85,6 +85,7 @@ export default function getInitialState({ functionNames: [], schema: activeTab.schema, queryLimit: activeTab.query_limit, + remoteId: activeTab.remoteId, validationResult: { id: null, errors: [], From 2ea85806f89b98cb871ad357918779de625db7e1 Mon Sep 17 00:00:00 2001 From: Arash Date: Wed, 1 Dec 2021 17:27:14 -0500 Subject: [PATCH 2/2] added unit test --- .../src/SqlLab/components/App/index.jsx | 2 - .../src/SqlLab/components/SqlEditor/index.jsx | 1 - .../components/TabbedSqlEditors/index.jsx | 4 -- .../src/SqlLab/reducers/getInitialState.js | 1 - .../charts/commands_tests.py | 44 +++++++++++++++++++ .../fixtures/energy_dashboard.py | 1 + 6 files changed, 45 insertions(+), 8 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/App/index.jsx b/superset-frontend/src/SqlLab/components/App/index.jsx index 8e6a70fc6b9d5..bce43f477800e 100644 --- a/superset-frontend/src/SqlLab/components/App/index.jsx +++ b/superset-frontend/src/SqlLab/components/App/index.jsx @@ -37,8 +37,6 @@ import QuerySearch from '../QuerySearch'; class App extends React.PureComponent { constructor(props) { super(props); - console.log('this is App'); - console.log(props); this.state = { hash: window.location.hash, }; diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx b/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx index 632788641b087..6197256666361 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/index.jsx @@ -616,7 +616,6 @@ class SqlEditor extends React.PureComponent { )} ); - return (
diff --git a/superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx b/superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx index c164bfce316b7..ea400b8b91c73 100644 --- a/superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx +++ b/superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx @@ -75,7 +75,6 @@ const userOS = detectOS(); class TabbedSqlEditors extends React.PureComponent { constructor(props) { super(props); - console.log('this is the tabbed', props); const sqlLabUrl = '/superset/sqllab'; this.state = { sqlLabUrl, @@ -94,8 +93,6 @@ class TabbedSqlEditors extends React.PureComponent { componentDidMount() { // migrate query editor and associated tables state to server - console.log('we here boys'); - console.log(this.props); if (isFeatureEnabled(FeatureFlag.SQLLAB_BACKEND_PERSISTENCE)) { const localStorageTables = this.props.tables.filter( table => table.inLocalStorage, @@ -437,7 +434,6 @@ TabbedSqlEditors.propTypes = propTypes; TabbedSqlEditors.defaultProps = defaultProps; function mapStateToProps({ sqlLab, common, requestedQuery }) { - console.log(sqlLab); return { databases: sqlLab.databases, queryEditors: sqlLab.queryEditors, diff --git a/superset-frontend/src/SqlLab/reducers/getInitialState.js b/superset-frontend/src/SqlLab/reducers/getInitialState.js index b6931045d6e85..0eceebfa3ad2b 100644 --- a/superset-frontend/src/SqlLab/reducers/getInitialState.js +++ b/superset-frontend/src/SqlLab/reducers/getInitialState.js @@ -85,7 +85,6 @@ export default function getInitialState({ functionNames: [], schema: activeTab.schema, queryLimit: activeTab.query_limit, - remoteId: activeTab.remoteId, validationResult: { id: null, errors: [], diff --git a/tests/integration_tests/charts/commands_tests.py b/tests/integration_tests/charts/commands_tests.py index 6d578b88aae43..caedb6a0b3d54 100644 --- a/tests/integration_tests/charts/commands_tests.py +++ b/tests/integration_tests/charts/commands_tests.py @@ -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", @@ -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): + """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): diff --git a/tests/integration_tests/fixtures/energy_dashboard.py b/tests/integration_tests/fixtures/energy_dashboard.py index 2c25eecdc26e5..14471052543c7 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"}', }, ]