diff --git a/superset/dashboards/api.py b/superset/dashboards/api.py index a1062ef91c..d156a34ecf 100644 --- a/superset/dashboards/api.py +++ b/superset/dashboards/api.py @@ -136,7 +136,7 @@ def with_dashboard( return functools.update_wrapper(wraps, f) -class DashboardRestApi(BaseSupersetModelRestApi): +class DashboardRestApi(BaseSupersetModelRestApi): # pylint: disable=too-many-public-methods datamodel = SQLAInterface(Dashboard) @before_request(only=["thumbnail"]) diff --git a/tests/integration_tests/dashboards/api_tests.py b/tests/integration_tests/dashboards/api_tests.py index aaf07a8780..99a784e95f 100644 --- a/tests/integration_tests/dashboards/api_tests.py +++ b/tests/integration_tests/dashboards/api_tests.py @@ -1,4 +1,3 @@ - # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information @@ -2720,12 +2719,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas def _cache_screenshot(self, dashboard_id, payload=None): if payload is None: - payload = { - "dataMask": {}, - "activeTabs": [], - "anchor": "", - "urlParams": [] - } + payload = {"dataMask": {}, "activeTabs": [], "anchor": "", "urlParams": []} uri = f"/api/v1/dashboard/{dashboard_id}/cache_dashboard_screenshot/" return self.client.post(uri, json=payload) @@ -2756,7 +2750,7 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas "dataMask": ["should be a dict"], "activeTabs": "should be a list", "anchor": 1, - "urlParams": "should be a list" + "urlParams": "should be a list", } response = self._cache_screenshot(dashboard.id, invalid_payload) self.assertEqual(response.status_code, 400) @@ -2768,15 +2762,15 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas self.assertEqual(response.status_code, 404) @pytest.mark.usefixtures("create_dashboard_with_tag") - @patch('superset.dashboards.api.cache_dashboard_screenshot') - @patch('superset.dashboards.api.DashboardScreenshot.get_from_cache_key') - def test_screenshot_success_png(self, mock_get_cache, mock_cache_task): + @patch("superset.dashboards.api.cache_dashboard_screenshot") + @patch("superset.dashboards.api.DashboardScreenshot.get_from_cache_key") + def test_screenshot_success_png(self, mock_get_cache, mock_cache_task): """ Validate screenshot returns png """ self.login(ADMIN_USERNAME) mock_cache_task.return_value = None - mock_get_cache.return_value = BytesIO(b'fake image data') + mock_get_cache.return_value = BytesIO(b"fake image data") dashboard = ( db.session.query(Dashboard) @@ -2789,21 +2783,23 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas response = self._get_screenshot(dashboard.id, cache_key, "png") self.assertEqual(response.status_code, 200) - self.assertEqual(response.mimetype, 'image/png') - self.assertEqual(response.data, b'fake image data') + self.assertEqual(response.mimetype, "image/png") + self.assertEqual(response.data, b"fake image data") @pytest.mark.usefixtures("create_dashboard_with_tag") - @patch('superset.dashboards.api.cache_dashboard_screenshot') - @patch('superset.dashboards.api.build_pdf_from_screenshots') - @patch('superset.dashboards.api.DashboardScreenshot.get_from_cache_key') - def test_screenshot_success_pdf(self, mock_get_from_cache, mock_build_pdf, mock_cache_task): + @patch("superset.dashboards.api.cache_dashboard_screenshot") + @patch("superset.dashboards.api.build_pdf_from_screenshots") + @patch("superset.dashboards.api.DashboardScreenshot.get_from_cache_key") + def test_screenshot_success_pdf( + self, mock_get_from_cache, mock_build_pdf, mock_cache_task + ): """ Validate screenshot can return pdf. """ self.login(ADMIN_USERNAME) mock_cache_task.return_value = None - mock_get_from_cache.return_value = BytesIO(b'fake image data') - mock_build_pdf.return_value = b'fake pdf data' + mock_get_from_cache.return_value = BytesIO(b"fake image data") + mock_build_pdf.return_value = b"fake pdf data" dashboard = ( db.session.query(Dashboard) @@ -2816,12 +2812,12 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas response = self._get_screenshot(dashboard.id, cache_key, "pdf") self.assertEqual(response.status_code, 200) - self.assertEqual(response.mimetype, 'application/pdf') - self.assertEqual(response.data, b'fake pdf data') + self.assertEqual(response.mimetype, "application/pdf") + self.assertEqual(response.data, b"fake pdf data") @pytest.mark.usefixtures("create_dashboard_with_tag") - @patch('superset.dashboards.api.cache_dashboard_screenshot') - @patch('superset.dashboards.api.DashboardScreenshot.get_from_cache_key') + @patch("superset.dashboards.api.cache_dashboard_screenshot") + @patch("superset.dashboards.api.DashboardScreenshot.get_from_cache_key") def test_screenshot_not_in_cache(self, mock_get_cache, mock_cache_task): self.login(ADMIN_USERNAME) mock_cache_task.return_value = None @@ -2846,12 +2842,12 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas self.assertEqual(response.status_code, 404) @pytest.mark.usefixtures("create_dashboard_with_tag") - @patch('superset.dashboards.api.cache_dashboard_screenshot') - @patch('superset.dashboards.api.DashboardScreenshot.get_from_cache_key') + @patch("superset.dashboards.api.cache_dashboard_screenshot") + @patch("superset.dashboards.api.DashboardScreenshot.get_from_cache_key") def test_screenshot_invalid_download_format(self, mock_get_cache, mock_cache_task): self.login(ADMIN_USERNAME) mock_cache_task.return_value = None - mock_get_cache.return_value = BytesIO(b'fake png data') + mock_get_cache.return_value = BytesIO(b"fake png data") dashboard = ( db.session.query(Dashboard) @@ -2865,4 +2861,3 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas response = self._get_screenshot(dashboard.id, cache_key, "invalid") self.assertEqual(response.status_code, 404) - \ No newline at end of file