64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
# [DEF:test_update_yamls:Module]
|
|
#
|
|
# @SEMANTICS: test, yaml, update, script
|
|
# @PURPOSE: Test script to verify update_yamls behavior.
|
|
# @LAYER: Test
|
|
# @RELATION: DEPENDS_ON -> superset_tool.utils.fileio
|
|
# @PUBLIC_API: main
|
|
|
|
# [SECTION: IMPORTS]
|
|
import tempfile
|
|
import os
|
|
from pathlib import Path
|
|
import yaml
|
|
from superset_tool.utils.fileio import update_yamls
|
|
# [/SECTION]
|
|
|
|
# [DEF:main:Function]
|
|
# @PURPOSE: Main test function.
|
|
# @RELATION: CALLS -> update_yamls
|
|
def main():
|
|
# Create a temporary directory structure
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
tmp_path = Path(tmpdir)
|
|
|
|
# Create a mock dashboard directory structure
|
|
dash_dir = tmp_path / "dashboard"
|
|
dash_dir.mkdir()
|
|
|
|
# Create a mock metadata.yaml file
|
|
metadata_file = dash_dir / "metadata.yaml"
|
|
metadata_content = {
|
|
"dashboard_uuid": "12345",
|
|
"database_name": "Prod Clickhouse",
|
|
"slug": "test-dashboard"
|
|
}
|
|
with open(metadata_file, 'w') as f:
|
|
yaml.dump(metadata_content, f)
|
|
|
|
print("Original metadata.yaml:")
|
|
with open(metadata_file, 'r') as f:
|
|
print(f.read())
|
|
|
|
# Test update_yamls
|
|
db_configs = [
|
|
{
|
|
"old": {"database_name": "Prod Clickhouse"},
|
|
"new": {"database_name": "DEV Clickhouse"}
|
|
}
|
|
]
|
|
|
|
update_yamls(db_configs=db_configs, path=str(dash_dir))
|
|
|
|
print("\nAfter update_yamls:")
|
|
with open(metadata_file, 'r') as f:
|
|
print(f.read())
|
|
|
|
print("Test completed.")
|
|
# [/DEF:main]
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# [/DEF:test_update_yamls]
|