mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
fix(import_datasources): --sync flag works correctly (#18046)
* Added code that properly accepts the -s flag on the import-datasources cli command. Also added unit tests for all of the edge cases (with both metrics & columns, with just columns, and with just metrics) * Files were reformated using the 'pre-commit run --all-files' command * added '*args: Any' back into v0.py as it did not need to be removed. Removing it might cause headaches for someone trying to work on this particular piece of code in the future * Fixed the merge conflict as the cli.py was moved to another directory * Modified my created unit tests to work with the new format of uni tests since the merge * Modified my created unit tests to work with the new format of uni tests since the merge * Fixed errors which were encountered while using the unit tests
This commit is contained in:
@@ -335,6 +335,111 @@ 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.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": False}, clear=True
|
||||
)
|
||||
@mock.patch("superset.datasets.commands.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.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": False}, clear=True
|
||||
)
|
||||
@mock.patch("superset.datasets.commands.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.config.DEFAULT_FEATURE_FLAGS", {"VERSIONED_EXPORT": False}, clear=True
|
||||
)
|
||||
@mock.patch("superset.datasets.commands.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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user