Skip to content

Commit

Permalink
Adding test and fixing default type
Browse files Browse the repository at this point in the history
  • Loading branch information
swish-gweisang committed Oct 24, 2024
1 parent 4fe576c commit 0175ce4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/preset_cli/cli/superset/sync/native/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def get_dataset_filter_uuids(config: AssetConfig) -> Set[str]:
"""
dataset_uuids = set()
for filter_config in config["metadata"].get("native_filter_configuration", []):
for target in filter_config.get("targets", dict()):
for target in filter_config.get("targets", {}):
if uuid := target.get("datasetUuid"):
if uuid not in dataset_uuids:
dataset_uuids.add(uuid)
Expand Down Expand Up @@ -378,6 +378,7 @@ def import_resources(
"""
Import a bundle of assets.
"""

contents["bundle/metadata.yaml"] = yaml.dump(
dict(
version="1.0.0",
Expand Down
65 changes: 62 additions & 3 deletions tests/cli/superset/sync/native/command_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests for the native import command.
"""

# pylint: disable=redefined-outer-name, invalid-name, too-many-lines

import json
Expand Down Expand Up @@ -516,9 +517,9 @@ def test_native_external_url(mocker: MockerFixture, fs: FakeFilesystem) -> None:
)
assert result.exit_code == 0
database_config["external_url"] = "https://repo.example.com/databases/gsheets.yaml"
dataset_config[
"external_url"
] = "https://repo.example.com/datasets/gsheets/test.yaml"
dataset_config["external_url"] = (
"https://repo.example.com/datasets/gsheets/test.yaml"
)
contents = {
"bundle/databases/gsheets.yaml": yaml.dump(database_config),
"bundle/datasets/gsheets/test.yaml": yaml.dump(dataset_config),
Expand Down Expand Up @@ -817,6 +818,7 @@ def test_native_split( # pylint: disable=too-many-locals
},
"uuid": "6",
}

dashboard_with_temporal_filter = {
"dashboard_title": "Some dashboard",
"is_managed_externally": False,
Expand Down Expand Up @@ -849,6 +851,45 @@ def test_native_split( # pylint: disable=too-many-locals
},
"uuid": "6",
}

dashboard_with_filter_divider_config = {
"dashboard_title": "Some dashboard",
"is_managed_externally": False,
"position": {},
"metadata": {
"native_filter_configuration": [
{
"type": "NATIVE_FILTER",
"targets": [
{
"column": "some_column",
"datasetUuid": "5",
},
],
},
{"type": "DIVIDER", "targets": {}},
{
"type": "NATIVE_FILTER",
"targets": [
{
"column": "other_column",
"datasetUuid": "5",
},
],
},
{
"type": "NATIVE_FILTER",
"targets": [
{
"column": "blah",
"datasetUuid": "2",
},
],
},
],
},
"uuid": "7",
}
fs.create_file(
root / "databases/gsheets.yaml",
contents=yaml.dump(database_config),
Expand Down Expand Up @@ -881,6 +922,10 @@ def test_native_split( # pylint: disable=too-many-locals
root / "dashboards/dashboard_deleted_dataset.yaml",
contents=yaml.dump(dashboard_deleted_dataset),
)
fs.create_file(
root / "dashboards/dashboard_with_filter_divider_config.yaml",
contents=yaml.dump(dashboard_deleted_dataset),
)

SupersetClient = mocker.patch(
"preset_cli.cli.superset.sync.native.command.SupersetClient",
Expand Down Expand Up @@ -976,6 +1021,20 @@ def test_native_split( # pylint: disable=too-many-locals
client,
False,
),
mock.call(
{
"bundle/dashboards/dashboard_with_filter_divider_config.yaml": yaml.dump(
dashboard_with_filter_divider_config,
),
"bundle/datasets/gsheets/filter_test.yaml": yaml.dump(
dataset_filter_config,
),
"bundle/datasets/gsheets/test.yaml": yaml.dump(dataset_config),
"bundle/databases/gsheets.yaml": yaml.dump(database_config),
},
client,
False,
),
],
)

Expand Down

0 comments on commit 0175ce4

Please sign in to comment.