Skip to content
Open
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
10 changes: 6 additions & 4 deletions cosmotech/coal/store/output/channel_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ def delete(self) -> bool:

def is_available(self) -> bool:
try:
return all(
all(key in self.configuration[section] for key in self.required_keys[section])
for section in self.required_keys.keys()
)
for section in self.required_keys.keys():
for key in self.required_keys[section]:
if key not in self.configuration[section]:
# if key not in conf get global conf value else KeyError is raised
self.configuration[section][key] = self.configuration.root[section][key]
return True
except KeyError:
return False

Expand Down
2 changes: 2 additions & 0 deletions cosmotech/coal/utils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def __getattr__(self, key):
except (KeyError, AttributeError):
LOGGER.warning(f"dotdict Ref {_v} doesn't exist")
raise ReferenceKeyError(_v)
if isinstance(_v, str) and _v.startswith("env."):
return os.getenv(_v[4:])
return _v

__delattr__ = dict.__delitem__
Expand Down
1 change: 0 additions & 1 deletion tests/unit/coal/test_postgresql/test_postgresql_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def test_get_postgresql_table_schema_not_found(self, mock_connect, base_configur
# Arrange
target_table_name = "test_table"
_psql = PostgresUtils(base_configuration)
print(base_configuration.postgres)

# Mock connection and cursor
mock_conn = MagicMock()
Expand Down
11 changes: 5 additions & 6 deletions tests/unit/coal/test_store/test_output/test_channel_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def test_is_available_with_required_keys_present(self):
def test_is_available_with_missing_keys(self):
"""Test is_available when required keys are missing."""
# Arrange
channel = ChannelInterface()
configuration = {"section1": {"key1": "value1"}, "section2": {"key3": "value3"}} # missing key2
channel = ChannelInterface(configuration)
channel.required_keys = {"section1": ["key1", "key2"], "section2": ["key3"]}
channel.configuration = {"section1": {"key1": "value1"}, "section2": {"key3": "value3"}} # missing key2

# Act
result = channel.is_available()
Expand All @@ -82,13 +82,12 @@ def test_is_available_with_missing_keys(self):
def test_is_available_with_missing_section(self):
"""Test is_available when a required section is missing."""
# Arrange
channel = ChannelInterface()
channel.required_keys = {"section1": ["key1", "key2"], "section2": ["key3"]}
channel.configuration = {
configuration = {
"section1": {"key1": "value1", "key2": "value2"}
# section2 is missing
}

channel = ChannelInterface(configuration)
channel.required_keys = {"section1": ["key1", "key2"], "section2": ["key3"]}
# Act & Assert
# The is_available method will raise KeyError when section is missing
# This is the actual behavior of the current implementation
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/coal/test_utils/conf.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ test = 1
[section.sub]
TEST = 2

[bar]
alors = 'env.faismoinlmalin'

[secrets.section]
secval = "sec"

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/coal/test_utils/test_utils_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def test_no_config_file_with_env_var(self):
c.secrets
assert c.log_level == "test_value"

def test_config_file_with_env_var_prefix(self):
os.environ["CONFIG_FILE_PATH"] = os.path.abspath(os.path.join(os.path.dirname(__file__), "conf.ini"))
os.environ["faismoinlmalin"] = "la"

c = configuration.Configuration()

assert c.bar.alors == "la"

def test_config_file_with_secrets(self):
os.environ["CONFIG_FILE_PATH"] = os.path.abspath(os.path.join(os.path.dirname(__file__), "conf.ini"))
os.environ["faismoinlmalin"] = "la"
Expand Down
Loading