mirror of
https://github.com/apache/superset.git
synced 2026-04-17 15:15:20 +00:00
chore: split CLI into multiple files (#18082)
* chore: split CLI into multiple files * Update tests * Who fixes the fixtures? * Add subcommands dynamically * Rebase
This commit is contained in:
@@ -26,7 +26,7 @@ import pytest
|
||||
import yaml
|
||||
from freezegun import freeze_time
|
||||
|
||||
import superset.cli
|
||||
import superset.cli.importexport
|
||||
from superset import app
|
||||
from tests.integration_tests.fixtures.birth_names_dashboard import (
|
||||
load_birth_names_dashboard_with_slices,
|
||||
@@ -53,14 +53,16 @@ def test_export_dashboards_original(app_context, fs):
|
||||
Test that a JSON file is exported.
|
||||
"""
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_dashboards correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(superset.cli.export_dashboards, ("-f", "dashboards.json"))
|
||||
response = runner.invoke(
|
||||
superset.cli.importexport.export_dashboards, ("-f", "dashboards.json")
|
||||
)
|
||||
|
||||
assert response.exit_code == 0
|
||||
assert Path("dashboards.json").exists()
|
||||
@@ -77,15 +79,15 @@ def test_export_datasources_original(app_context, fs):
|
||||
Test that a YAML file is exported.
|
||||
"""
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_dashboards correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(
|
||||
superset.cli.export_datasources, ("-f", "datasources.yaml")
|
||||
superset.cli.importexport.export_datasources, ("-f", "datasources.yaml")
|
||||
)
|
||||
|
||||
assert response.exit_code == 0
|
||||
@@ -99,22 +101,22 @@ def test_export_datasources_original(app_context, fs):
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
@mock.patch.dict(
|
||||
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
|
||||
"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.
|
||||
"""
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_dashboards correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
with freeze_time("2021-01-01T00:00:00Z"):
|
||||
response = runner.invoke(superset.cli.export_dashboards, ())
|
||||
response = runner.invoke(superset.cli.importexport.export_dashboards, ())
|
||||
|
||||
assert response.exit_code == 0
|
||||
assert Path("dashboard_export_20210101T000000.zip").exists()
|
||||
@@ -123,7 +125,7 @@ def test_export_dashboards_versioned_export(app_context, fs):
|
||||
|
||||
|
||||
@mock.patch.dict(
|
||||
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
|
||||
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
|
||||
)
|
||||
@mock.patch(
|
||||
"superset.dashboards.commands.export.ExportDashboardsCommand.run",
|
||||
@@ -138,37 +140,37 @@ def test_failing_export_dashboards_versioned_export(
|
||||
caplog.set_level(logging.DEBUG)
|
||||
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_dashboards correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
with freeze_time("2021-01-01T00:00:00Z"):
|
||||
response = runner.invoke(superset.cli.export_dashboards, ())
|
||||
response = runner.invoke(superset.cli.importexport.export_dashboards, ())
|
||||
|
||||
assert_cli_fails_properly(response, caplog)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
@mock.patch.dict(
|
||||
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
|
||||
"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.
|
||||
"""
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_dashboards correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
with freeze_time("2021-01-01T00:00:00Z"):
|
||||
response = runner.invoke(superset.cli.export_datasources, ())
|
||||
response = runner.invoke(superset.cli.importexport.export_datasources, ())
|
||||
|
||||
assert response.exit_code == 0
|
||||
assert Path("dataset_export_20210101T000000.zip").exists()
|
||||
@@ -177,7 +179,7 @@ def test_export_datasources_versioned_export(app_context, fs):
|
||||
|
||||
|
||||
@mock.patch.dict(
|
||||
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
|
||||
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
|
||||
)
|
||||
@mock.patch(
|
||||
"superset.dashboards.commands.export.ExportDatasetsCommand.run",
|
||||
@@ -190,21 +192,21 @@ def test_failing_export_datasources_versioned_export(
|
||||
Test that failing to export ZIP file is done elegantly.
|
||||
"""
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_dashboards correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
with freeze_time("2021-01-01T00:00:00Z"):
|
||||
response = runner.invoke(superset.cli.export_datasources, ())
|
||||
response = runner.invoke(superset.cli.importexport.export_datasources, ())
|
||||
|
||||
assert_cli_fails_properly(response, caplog)
|
||||
|
||||
|
||||
@mock.patch.dict(
|
||||
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
|
||||
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
|
||||
)
|
||||
@mock.patch("superset.dashboards.commands.importers.dispatcher.ImportDashboardsCommand")
|
||||
def test_import_dashboards_versioned_export(import_dashboards_command, app_context, fs):
|
||||
@@ -212,18 +214,20 @@ def test_import_dashboards_versioned_export(import_dashboards_command, app_conte
|
||||
Test that both ZIP and JSON can be imported.
|
||||
"""
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_dashboards correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
# write JSON file
|
||||
with open("dashboards.json", "w") as fp:
|
||||
fp.write('{"hello": "world"}')
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(superset.cli.import_dashboards, ("-p", "dashboards.json"))
|
||||
response = runner.invoke(
|
||||
superset.cli.importexport.import_dashboards, ("-p", "dashboards.json")
|
||||
)
|
||||
|
||||
assert response.exit_code == 0
|
||||
expected_contents = {"dashboards.json": '{"hello": "world"}'}
|
||||
@@ -235,7 +239,9 @@ def test_import_dashboards_versioned_export(import_dashboards_command, app_conte
|
||||
fp.write(b"hello: world")
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(superset.cli.import_dashboards, ("-p", "dashboards.zip"))
|
||||
response = runner.invoke(
|
||||
superset.cli.importexport.import_dashboards, ("-p", "dashboards.zip")
|
||||
)
|
||||
|
||||
assert response.exit_code == 0
|
||||
expected_contents = {"dashboard.yaml": "hello: world"}
|
||||
@@ -243,7 +249,7 @@ def test_import_dashboards_versioned_export(import_dashboards_command, app_conte
|
||||
|
||||
|
||||
@mock.patch.dict(
|
||||
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
|
||||
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
|
||||
)
|
||||
@mock.patch(
|
||||
"superset.dashboards.commands.importers.dispatcher.ImportDashboardsCommand.run",
|
||||
@@ -256,18 +262,20 @@ def test_failing_import_dashboards_versioned_export(
|
||||
Test that failing to import either ZIP and JSON is done elegantly.
|
||||
"""
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_dashboards correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
# write JSON file
|
||||
with open("dashboards.json", "w") as fp:
|
||||
fp.write('{"hello": "world"}')
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(superset.cli.import_dashboards, ("-p", "dashboards.json"))
|
||||
response = runner.invoke(
|
||||
superset.cli.importexport.import_dashboards, ("-p", "dashboards.json")
|
||||
)
|
||||
|
||||
assert_cli_fails_properly(response, caplog)
|
||||
|
||||
@@ -277,13 +285,15 @@ def test_failing_import_dashboards_versioned_export(
|
||||
fp.write(b"hello: world")
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(superset.cli.import_dashboards, ("-p", "dashboards.zip"))
|
||||
response = runner.invoke(
|
||||
superset.cli.importexport.import_dashboards, ("-p", "dashboards.zip")
|
||||
)
|
||||
|
||||
assert_cli_fails_properly(response, caplog)
|
||||
|
||||
|
||||
@mock.patch.dict(
|
||||
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
|
||||
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
|
||||
)
|
||||
@mock.patch("superset.datasets.commands.importers.dispatcher.ImportDatasetsCommand")
|
||||
def test_import_datasets_versioned_export(import_datasets_command, app_context, fs):
|
||||
@@ -291,18 +301,20 @@ def test_import_datasets_versioned_export(import_datasets_command, app_context,
|
||||
Test that both ZIP and YAML can be imported.
|
||||
"""
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_datasets correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
# write YAML file
|
||||
with open("datasets.yaml", "w") as fp:
|
||||
fp.write("hello: world")
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(superset.cli.import_datasources, ("-p", "datasets.yaml"))
|
||||
response = runner.invoke(
|
||||
superset.cli.importexport.import_datasources, ("-p", "datasets.yaml")
|
||||
)
|
||||
|
||||
assert response.exit_code == 0
|
||||
expected_contents = {"datasets.yaml": "hello: world"}
|
||||
@@ -314,7 +326,9 @@ def test_import_datasets_versioned_export(import_datasets_command, app_context,
|
||||
fp.write(b"hello: world")
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(superset.cli.import_datasources, ("-p", "datasets.zip"))
|
||||
response = runner.invoke(
|
||||
superset.cli.importexport.import_datasources, ("-p", "datasets.zip")
|
||||
)
|
||||
|
||||
assert response.exit_code == 0
|
||||
expected_contents = {"dataset.yaml": "hello: world"}
|
||||
@@ -322,7 +336,7 @@ def test_import_datasets_versioned_export(import_datasets_command, app_context,
|
||||
|
||||
|
||||
@mock.patch.dict(
|
||||
"superset.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": True}, clear=True
|
||||
"superset.cli.lib.feature_flags", {"VERSIONED_EXPORT": True}, clear=True
|
||||
)
|
||||
@mock.patch(
|
||||
"superset.datasets.commands.importers.dispatcher.ImportDatasetsCommand.run",
|
||||
@@ -335,18 +349,20 @@ def test_failing_import_datasets_versioned_export(
|
||||
Test that failing to import either ZIP or YAML is done elegantly.
|
||||
"""
|
||||
# pylint: disable=reimported, redefined-outer-name
|
||||
import superset.cli # noqa: F811
|
||||
import superset.cli.importexport # noqa: F811
|
||||
|
||||
# reload to define export_datasets correctly based on the
|
||||
# feature flags
|
||||
importlib.reload(superset.cli)
|
||||
importlib.reload(superset.cli.importexport)
|
||||
|
||||
# write YAML file
|
||||
with open("datasets.yaml", "w") as fp:
|
||||
fp.write("hello: world")
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(superset.cli.import_datasources, ("-p", "datasets.yaml"))
|
||||
response = runner.invoke(
|
||||
superset.cli.importexport.import_datasources, ("-p", "datasets.yaml")
|
||||
)
|
||||
|
||||
assert_cli_fails_properly(response, caplog)
|
||||
|
||||
@@ -356,6 +372,8 @@ def test_failing_import_datasets_versioned_export(
|
||||
fp.write(b"hello: world")
|
||||
|
||||
runner = app.test_cli_runner()
|
||||
response = runner.invoke(superset.cli.import_datasources, ("-p", "datasets.zip"))
|
||||
response = runner.invoke(
|
||||
superset.cli.importexport.import_datasources, ("-p", "datasets.zip")
|
||||
)
|
||||
|
||||
assert_cli_fails_properly(response, caplog)
|
||||
|
||||
Reference in New Issue
Block a user