Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion airflow_code_editor/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# Modified 2026-10-24: create the configuration parent directory.
#
# Copyright 2019 Andrea Bonomi <andrea.bonomi@gmail.com>
#
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# Modified 2026-10-24: cover first-run configuration creation.

import contextlib
import os
Expand All @@ -20,6 +21,7 @@
get_root_folder,
normalize_path,
read_mount_points_config,
read_config_file,
)


Expand Down Expand Up @@ -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"))
Loading