diff --git a/airflow_code_editor/utils.py b/airflow_code_editor/utils.py index 90bf9f9..45e2be7 100644 --- a/airflow_code_editor/utils.py +++ b/airflow_code_editor/utils.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# Modified 2026-10-24: create the configuration parent directory. # # Copyright 2019 Andrea Bonomi # @@ -253,7 +254,7 @@ def read_config_file(path: Path) -> None: conf.add_section(PLUGIN_NAME) if "fernet_key" not in conf["core"]: - path.mkdir(parents=True, exist_ok=True) + path.parent.mkdir(parents=True, exist_ok=True) conf["core"]["fernet_key"] = os.urandom(16).hex() with open(path, "w") as f: conf.write(f) diff --git a/tests/test_utils.py b/tests/test_utils.py index 9dce055..b8d1609 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# Modified 2026-10-24: cover first-run configuration creation. import contextlib import os @@ -20,6 +21,7 @@ get_root_folder, normalize_path, read_mount_points_config, + read_config_file, ) @@ -239,3 +241,18 @@ def test_mount_points(self): assert str(m['test'].path) == '/tmp/test' assert str(m['test1'].path) == '/tmp/test1' assert str(m['test2'].path) == '/tmp/test2' + + +class TestReadConfigFile(TestCase): + def test_creates_file_in_missing_parent_directory(self): + from configparser import ConfigParser + + with tempfile.TemporaryDirectory() as directory: + path = Path(directory) / "new" / "config.ini" + config = ConfigParser() + with mock.patch("airflow_code_editor.utils.conf", config): + read_config_file(path) + self.assertTrue(path.is_file()) + saved = ConfigParser() + saved.read(path) + self.assertTrue(saved.has_option("core", "fernet_key"))