From 623857c715846ec65109efffbdf07326d2fd0a0e Mon Sep 17 00:00:00 2001 From: Karol Kostrzewa Date: Tue, 12 Jan 2021 10:08:16 +0100 Subject: [PATCH] fixes after merge --- .github/workflows/bashlib.sh | 2 +- .../integration/dashboard/url_params.test.js | 2 +- tests/base_api_tests.py | 4 +++ tests/charts/api_tests.py | 25 +++++++++++++------ tests/core_tests.py | 9 ++++--- tests/dashboards/api_tests.py | 9 +++++-- tests/dashboards/commands_tests.py | 5 +++- 7 files changed, 40 insertions(+), 16 deletions(-) diff --git a/.github/workflows/bashlib.sh b/.github/workflows/bashlib.sh index 6a63c6bd0fd93..0d70bbd1ee7fd 100644 --- a/.github/workflows/bashlib.sh +++ b/.github/workflows/bashlib.sh @@ -188,7 +188,7 @@ cypress-run-all() { nohup flask run --no-debugger -p $port >"$flasklog" 2>&1 { it('should apply url params to slice requests', () => { const aliases = getChartAliases(dashboard.slices); // wait and verify one-by-one - cy.wait(aliases, {timeout: 15000}).then(requests => + cy.wait(aliases, {timeout: 18000}).then(requests => Promise.all( requests.map(async xhr => { expect(xhr.status).to.eq(200); diff --git a/tests/base_api_tests.py b/tests/base_api_tests.py index 1708cff51e614..3dd21dcfc8108 100644 --- a/tests/base_api_tests.py +++ b/tests/base_api_tests.py @@ -16,7 +16,9 @@ # under the License. # isort:skip_file import json +from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices +import pytest from flask_appbuilder.models.sqla.interface import SQLAInterface import prison @@ -66,6 +68,7 @@ def test_open_api_spec(self): class TestBaseModelRestApi(SupersetTestCase): + @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices") def test_default_missing_declaration_get(self): """ API: Test default missing declaration on get @@ -148,6 +151,7 @@ def test_default_missing_declaration_post(self): } self.assertEqual(response, expected_response) + @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices") def test_default_missing_declaration_put(self): """ API: Test default missing declaration on put diff --git a/tests/charts/api_tests.py b/tests/charts/api_tests.py index a20c282899d9c..f7ba39a5c92e6 100644 --- a/tests/charts/api_tests.py +++ b/tests/charts/api_tests.py @@ -436,7 +436,10 @@ def test_delete_bulk_chart_not_owned(self): db.session.delete(user_alpha2) db.session.commit() - @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices", "load_birth_names_dashboard_with_slices") + @pytest.mark.usefixtures( + "load_world_bank_dashboard_with_slices", + "load_birth_names_dashboard_with_slices", + ) def test_create_chart(self): """ Chart API: Test create chart @@ -545,15 +548,18 @@ def test_create_chart_validate_datasource(self): response, {"message": {"datasource_id": ["Datasource does not exist"]}} ) + @pytest.mark.usefixtures("load_birth_names_dashboard_with_slices") def test_update_chart(self): """ Chart API: Test update """ admin = self.get_user("admin") gamma = self.get_user("gamma") - - chart_id = self.insert_chart("title", [admin.id], 1, admin).id birth_names_table_id = SupersetTestCase.get_table_by_name("birth_names").id + chart_id = self.insert_chart( + "title", [admin.id], birth_names_table_id, admin + ).id + dash_id = db.session.query(Dashboard.id).filter_by(slug="births").first()[0] chart_data = { "slice_name": "title1_changed", "description": "description1", @@ -563,14 +569,14 @@ def test_update_chart(self): "cache_timeout": 1000, "datasource_id": birth_names_table_id, "datasource_type": "table", - "dashboards": [1], + "dashboards": [dash_id], } self.login(username="admin") uri = f"api/v1/chart/{chart_id}" rv = self.put_assert_metric(uri, chart_data, "put") self.assertEqual(rv.status_code, 200) model = db.session.query(Slice).get(chart_id) - related_dashboard = db.session.query(Dashboard).get(1) + related_dashboard = db.session.query(Dashboard).filter_by(slug="births").first() self.assertEqual(model.created_by, admin) self.assertEqual(model.slice_name, "title1_changed") self.assertEqual(model.description, "description1") @@ -582,7 +588,7 @@ def test_update_chart(self): self.assertEqual(model.datasource_id, birth_names_table_id) self.assertEqual(model.datasource_type, "table") self.assertEqual(model.datasource_name, "birth_names") - self.assertIn(related_dashboard, model.dashboards) + self.assertIn(model.id, [slice.id for slice in related_dashboard.slices]) db.session.delete(model) db.session.commit() @@ -801,7 +807,10 @@ def test_get_charts_changed_on(self): db.session.delete(chart) db.session.commit() - @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices", "load_birth_names_dashboard_with_slices") + @pytest.mark.usefixtures( + "load_world_bank_dashboard_with_slices", + "load_birth_names_dashboard_with_slices", + ) def test_get_charts_filter(self): """ Chart API: Test get charts filter @@ -1012,7 +1021,7 @@ def test_get_time_range(self): "load_unicode_dashboard_with_slice", "load_energy_table_with_slice", "load_world_bank_dashboard_with_slices", - "load_birth_names_dashboard_with_slices" + "load_birth_names_dashboard_with_slices", ) def test_get_charts_page(self): """ diff --git a/tests/core_tests.py b/tests/core_tests.py index 16620b406da24..2363ab015a636 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -66,6 +66,7 @@ from superset.views.database.views import DatabaseView from .base_tests import SupersetTestCase +from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices logger = logging.getLogger(__name__) @@ -1223,6 +1224,7 @@ def test_results_msgpack_deserialization(self): {"FOO": lambda x: 1}, clear=True, ) + @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices") def test_feature_flag_serialization(self): """ Functions in feature flags don't break bootstrap data serialization. @@ -1238,13 +1240,14 @@ def test_feature_flag_serialization(self): .replace("'", "'") .replace('"', """) ) - + dash_id = db.session.query(Dashboard.id).first()[0] + tbl_id = self.table_ids.get("wb_health_population") urls = [ "/superset/sqllab", "/superset/welcome", - "/superset/dashboard/1/", + f"/superset/dashboard/{dash_id}/", "/superset/profile/admin/", - "/superset/explore/table/1", + f"/superset/explore/table/{tbl_id}", ] for url in urls: data = self.get_resp(url) diff --git a/tests/dashboards/api_tests.py b/tests/dashboards/api_tests.py index 299dd2de64d9e..38ce1aee9522b 100644 --- a/tests/dashboards/api_tests.py +++ b/tests/dashboards/api_tests.py @@ -49,6 +49,7 @@ dataset_metadata_config, ) from tests.utils.get_dashboards import get_dashboards_ids +from tests.fixtures.world_bank_dashboard import load_world_bank_dashboard_with_slices DASHBOARDS_FIXTURE_COUNT = 10 @@ -1102,13 +1103,17 @@ def test_update_dashboard_not_owned(self): db.session.delete(user_alpha2) db.session.commit() + @pytest.mark.usefixtures( + "load_world_bank_dashboard_with_slices", + "load_birth_names_dashboard_with_slices", + ) def test_export(self): """ Dashboard API: Test dashboard export """ self.login(username="admin") - argument = [1, 2] - uri = f"api/v1/dashboard/export/?q={prison.dumps(argument)}" + dashboards_ids = get_dashboards_ids(db, ["world_health", "births"]) + uri = f"api/v1/dashboard/export/?q={prison.dumps(dashboards_ids)}" # freeze time to ensure filename is deterministic with freeze_time("2020-01-01T00:00:00Z"): diff --git a/tests/dashboards/commands_tests.py b/tests/dashboards/commands_tests.py index 0a9105ed778f9..3449c001d9826 100644 --- a/tests/dashboards/commands_tests.py +++ b/tests/dashboards/commands_tests.py @@ -232,6 +232,7 @@ def test_export_dashboard_command(self, mock_g1, mock_g2): "version": "1.0.0", } + @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices") @patch("superset.security.manager.g") @patch("superset.views.base.g") def test_export_dashboard_command_no_access(self, mock_g1, mock_g2): @@ -239,7 +240,9 @@ def test_export_dashboard_command_no_access(self, mock_g1, mock_g2): mock_g1.user = security_manager.find_user("gamma") mock_g2.user = security_manager.find_user("gamma") - example_dashboard = db.session.query(Dashboard).filter_by(id=1).one() + example_dashboard = ( + db.session.query(Dashboard).filter_by(slug="world_health").one() + ) command = ExportDashboardsCommand([example_dashboard.id]) contents = command.run() with self.assertRaises(DashboardNotFoundError):