refactor: Removes the deprecated VERSIONED_EXPORT feature flag (#26347)

This commit is contained in:
Michael S. Molina
2024-01-19 15:21:14 -03:00
committed by GitHub
parent 649ff4dd61
commit f63e66be01
18 changed files with 417 additions and 742 deletions

View File

@@ -16,7 +16,6 @@
# under the License.
import importlib
import json
import logging
from pathlib import Path
from unittest import mock
@@ -49,69 +48,7 @@ def assert_cli_fails_properly(response, caplog):
assert caplog.records[-1].levelname == "ERROR"
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": False}, clear=True
)
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_export_dashboards_original(app_context, fs):
"""
Test that a JSON file is exported.
"""
# pylint: disable=reimported, redefined-outer-name
import superset.cli.importexport # noqa: F811
# reload to define export_dashboards correctly based on the
# feature flags
importlib.reload(superset.cli.importexport)
runner = app.test_cli_runner()
response = runner.invoke(
superset.cli.importexport.export_dashboards, ("-f", "dashboards.json")
)
assert response.exit_code == 0
assert Path("dashboards.json").exists()
# check that file is valid JSON
with open("dashboards.json") as fp:
contents = fp.read()
json.loads(contents)
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": False}, clear=True
)
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_export_datasources_original(app_context, fs):
"""
Test that a YAML file is exported.
"""
# pylint: disable=reimported, redefined-outer-name
import superset.cli.importexport # noqa: F811
# reload to define export_dashboards correctly based on the
# feature flags
importlib.reload(superset.cli.importexport)
runner = app.test_cli_runner()
response = runner.invoke(
superset.cli.importexport.export_datasources, ("-f", "datasources.yaml")
)
assert response.exit_code == 0
assert Path("datasources.yaml").exists()
# check that file is valid JSON
with open("datasources.yaml") as fp:
contents = fp.read()
yaml.safe_load(contents)
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
)
def test_export_dashboards_versioned_export(app_context, fs):
"""
Test that a ZIP file is exported.
@@ -133,9 +70,6 @@ def test_export_dashboards_versioned_export(app_context, fs):
assert is_zipfile("dashboard_export_20210101T000000.zip")
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
)
@mock.patch(
"superset.commands.dashboard.export.ExportDashboardsCommand.run",
side_effect=Exception(),
@@ -163,9 +97,6 @@ def test_failing_export_dashboards_versioned_export(
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
)
def test_export_datasources_versioned_export(app_context, fs):
"""
Test that a ZIP file is exported.
@@ -187,9 +118,6 @@ def test_export_datasources_versioned_export(app_context, fs):
assert is_zipfile("dataset_export_20210101T000000.zip")
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
)
@mock.patch(
"superset.commands.dashboard.export.ExportDatasetsCommand.run",
side_effect=Exception(),
@@ -214,9 +142,6 @@ def test_failing_export_datasources_versioned_export(
assert_cli_fails_properly(response, caplog)
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
)
@mock.patch("superset.commands.dashboard.importers.dispatcher.ImportDashboardsCommand")
def test_import_dashboards_versioned_export(import_dashboards_command, app_context, fs):
"""
@@ -257,9 +182,6 @@ def test_import_dashboards_versioned_export(import_dashboards_command, app_conte
import_dashboards_command.assert_called_with(expected_contents, overwrite=True)
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
)
@mock.patch(
"superset.commands.dashboard.importers.dispatcher.ImportDashboardsCommand.run",
side_effect=Exception(),
@@ -301,9 +223,6 @@ def test_failing_import_dashboards_versioned_export(
assert_cli_fails_properly(response, caplog)
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
)
@mock.patch("superset.commands.dataset.importers.dispatcher.ImportDatasetsCommand")
def test_import_datasets_versioned_export(import_datasets_command, app_context, fs):
"""
@@ -344,120 +263,6 @@ def test_import_datasets_versioned_export(import_datasets_command, app_context,
import_datasets_command.assert_called_with(expected_contents, overwrite=True)
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": False}, clear=True
)
@mock.patch("superset.commands.dataset.importers.v0.ImportDatasetsCommand")
def test_import_datasets_sync_argument_columns_metrics(
import_datasets_command, app_context, fs
):
"""
Test that the --sync command line argument syncs dataset in superset
with YAML file. Using both columns and metrics with the --sync flag
"""
# pylint: disable=reimported, redefined-outer-name
import superset.cli.importexport # noqa: F811
# reload to define export_datasets correctly based on the
# feature flags
importlib.reload(superset.cli.importexport)
# write YAML file
with open("dataset.yaml", "w") as fp:
fp.write("hello: world")
runner = app.test_cli_runner()
response = runner.invoke(
superset.cli.importexport.import_datasources,
["-p", "dataset.yaml", "-s", "metrics,columns"],
)
assert response.exit_code == 0
expected_contents = {"dataset.yaml": "hello: world"}
import_datasets_command.assert_called_with(
expected_contents,
sync_columns=True,
sync_metrics=True,
)
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": False}, clear=True
)
@mock.patch("superset.commands.dataset.importers.v0.ImportDatasetsCommand")
def test_import_datasets_sync_argument_columns(
import_datasets_command, app_context, fs
):
"""
Test that the --sync command line argument syncs dataset in superset
with YAML file. Using only columns with the --sync flag
"""
# pylint: disable=reimported, redefined-outer-name
import superset.cli.importexport # noqa: F811
# reload to define export_datasets correctly based on the
# feature flags
importlib.reload(superset.cli.importexport)
# write YAML file
with open("dataset.yaml", "w") as fp:
fp.write("hello: world")
runner = app.test_cli_runner()
response = runner.invoke(
superset.cli.importexport.import_datasources,
["-p", "dataset.yaml", "-s", "columns"],
)
assert response.exit_code == 0
expected_contents = {"dataset.yaml": "hello: world"}
import_datasets_command.assert_called_with(
expected_contents,
sync_columns=True,
sync_metrics=False,
)
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": False}, clear=True
)
@mock.patch("superset.commands.dataset.importers.v0.ImportDatasetsCommand")
def test_import_datasets_sync_argument_metrics(
import_datasets_command, app_context, fs
):
"""
Test that the --sync command line argument syncs dataset in superset
with YAML file. Using only metrics with the --sync flag
"""
# pylint: disable=reimported, redefined-outer-name
import superset.cli.importexport # noqa: F811
# reload to define export_datasets correctly based on the
# feature flags
importlib.reload(superset.cli.importexport)
# write YAML file
with open("dataset.yaml", "w") as fp:
fp.write("hello: world")
runner = app.test_cli_runner()
response = runner.invoke(
superset.cli.importexport.import_datasources,
["-p", "dataset.yaml", "-s", "metrics"],
)
assert response.exit_code == 0
expected_contents = {"dataset.yaml": "hello: world"}
import_datasets_command.assert_called_with(
expected_contents,
sync_columns=False,
sync_metrics=True,
)
@mock.patch.dict(
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
)
@mock.patch(
"superset.commands.dataset.importers.dispatcher.ImportDatasetsCommand.run",
side_effect=Exception(),