Skip to content

Commit f73cc48

Browse files
committed
test: update unit tests with a configurable config fixture
Signed-off-by: Frank Kong <frkong@redhat.com>
1 parent f6de10c commit f73cc48

2 files changed

Lines changed: 151 additions & 377 deletions

File tree

tests/conftest.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from unittest.mock import MagicMock
1010
from dotenv import dotenv_values
1111

12+
from src.rhdh_dynamic_plugin_factory.config import PluginFactoryConfig
13+
1214

1315
@pytest.fixture
1416
def mock_logger():
@@ -114,7 +116,7 @@ def temp_workspace(tmp_path: Path):
114116

115117

116118
@pytest.fixture
117-
def setup_test_env(tmp_path: Path):
119+
def setup_test_env(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
118120
"""
119121
Set up a complete test environment with all required files and environment variables.
120122
@@ -142,6 +144,10 @@ def setup_test_env(tmp_path: Path):
142144
"""
143145
(config_dir / "plugins-list.yaml").write_text(plugins_content)
144146

147+
# Set common environment variables
148+
monkeypatch.setenv("RHDH_CLI_VERSION", "1.7.2")
149+
monkeypatch.setenv("WORKSPACE_PATH", ".")
150+
145151
return {
146152
"config_dir": str(config_dir),
147153
"source_dir": str(source_dir),
@@ -169,3 +175,24 @@ def clean_env(monkeypatch: pytest.MonkeyPatch):
169175

170176
return monkeypatch
171177

178+
179+
@pytest.fixture
180+
def make_config(setup_test_env):
181+
"""Factory fixture to create PluginFactoryConfig with sensible defaults.
182+
183+
Usage:
184+
config = make_config() # All defaults
185+
config = make_config(registry_url="quay.io") # With override
186+
config = make_config(registry_url=None) # Explicitly set to None
187+
"""
188+
def _make_config(**overrides):
189+
config = PluginFactoryConfig()
190+
config.config_dir = setup_test_env["config_dir"]
191+
config.repo_path = setup_test_env["source_dir"]
192+
config.rhdh_cli_version = "1.7.2"
193+
config.workspace_path = "."
194+
for key, value in overrides.items():
195+
setattr(config, key, value)
196+
return config
197+
return _make_config
198+

0 commit comments

Comments
 (0)