feat: export datasets as ZIP files (#11332)

* Export datasets as ZIP files

* Add logging when failing to parse extra

* Fix logging
This commit is contained in:
Beto Dealmeida
2020-10-22 10:32:08 -07:00
committed by GitHub
parent 64b5aae6bc
commit 00e394451f
6 changed files with 391 additions and 16 deletions

View File

@@ -16,8 +16,10 @@
# under the License.
"""Unit tests for Superset"""
import json
from io import BytesIO
from typing import List
from unittest.mock import patch
from zipfile import is_zipfile
import prison
import pytest
@@ -1006,6 +1008,68 @@ class TestDatasetApi(SupersetTestCase):
rv = self.client.get(uri)
assert 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
def test_get_dataset_related_objects(self):
"""
Dataset API: Test get chart and dashboard count related to a dataset