hughhhh commented on a change in pull request #11332: URL: https://github.com/apache/incubator-superset/pull/11332#discussion_r508928605
########## File path: tests/datasets/commands_tests.py ########## @@ -0,0 +1,185 @@ +# 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 +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from operator import itemgetter +from unittest.mock import patch + +import yaml + +from superset import security_manager +from superset.connectors.sqla.models import SqlaTable +from superset.datasets.commands.exceptions import DatasetNotFoundError +from superset.datasets.commands.export import ExportDatasetsCommand +from superset.utils.core import backend, get_example_database +from tests.base_tests import SupersetTestCase + + +class TestExportDatasetsCommand(SupersetTestCase): + @patch("superset.security.manager.g") + def test_export_dataset_command(self, mock_g): + mock_g.user = security_manager.find_user("admin") + + example_db = get_example_database() + example_dataset = example_db.tables[0] Review comment: nit: We could make `EXAMPLE_DB` global variable in the class since its being referenced multiple times into different test ########## File path: tests/datasets/api_tests.py ########## @@ -1006,6 +1008,68 @@ def test_export_dataset_gamma(self): rv = self.client.get(uri) self.assertEqual(rv.status_code, 401) + @patch.dict( + "superset.extensions.feature_flag_manager._feature_flags", + {"VERSIONED_EXPORT": True}, + clear=True, + ) + def test_export_dataset_bundle(self): + """ + Dataset API: Test export dataset + """ + birth_names_dataset = self.get_birth_names_dataset() + # TODO: fix test for presto + # debug with dump: https://github.com/apache/incubator-superset/runs/1092546855 + if birth_names_dataset.database.backend in {"presto", "hive"}: + return + + argument = [birth_names_dataset.id] + uri = f"api/v1/dataset/export/?q={prison.dumps(argument)}" + + self.login(username="admin") + rv = self.get_assert_metric(uri, "export") + + assert rv.status_code == 200 + + buf = BytesIO(rv.data) + assert is_zipfile(buf) + + @patch.dict( + "superset.extensions.feature_flag_manager._feature_flags", + {"VERSIONED_EXPORT": True}, + clear=True, + ) + def test_export_dataset_bundle_not_found(self): + """ + Dataset API: Test export dataset not found + """ + # Just one does not exist and we get 404 + argument = [-1, 1] + uri = f"api/v1/dataset/export/?q={prison.dumps(argument)}" + self.login(username="admin") + rv = self.get_assert_metric(uri, "export") + + assert rv.status_code == 404 + + @patch.dict( + "superset.extensions.feature_flag_manager._feature_flags", + {"VERSIONED_EXPORT": True}, + clear=True, + ) + def test_export_dataset_bundle_gamma(self): + """ + Dataset API: Test export dataset has gamma + """ + birth_names_dataset = self.get_birth_names_dataset() + + argument = [birth_names_dataset.id] + uri = f"api/v1/dataset/export/?q={prison.dumps(argument)}" + + self.login(username="gamma") + rv = self.client.get(uri) + + assert rv.status_code == 401 Review comment: ```suggestion self.assertEqual(rv.status_code, 401) ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
