diff --git a/tests/unit/codegen/shared/configs/test_constants.py b/tests/unit/codegen/shared/configs/test_constants.py index dc18c703a..99bdcee1f 100644 --- a/tests/unit/codegen/shared/configs/test_constants.py +++ b/tests/unit/codegen/shared/configs/test_constants.py @@ -5,8 +5,6 @@ CODEGEN_REPO_ROOT, CONFIG_FILENAME, CONFIG_PATH, - ENV_FILENAME, - ENV_PATH, ) @@ -22,9 +20,3 @@ def test_config_path_construction(): assert str(CONFIG_PATH).endswith(f"{CODEGEN_DIR_NAME}/{CONFIG_FILENAME}") assert CONFIG_PATH.exists() assert CONFIG_PATH.is_file() - - -def test_env_path_construction(): - expected_path = CODEGEN_REPO_ROOT / "src" / "codegen" / ENV_FILENAME - assert ENV_PATH == expected_path - assert str(ENV_PATH).endswith(f"src/codegen/{ENV_FILENAME}") diff --git a/tests/unit/codegen/shared/configs/test_models.py b/tests/unit/codegen/shared/configs/test_models.py index 179cdf95d..be4602126 100644 --- a/tests/unit/codegen/shared/configs/test_models.py +++ b/tests/unit/codegen/shared/configs/test_models.py @@ -1,49 +1,50 @@ import json -from pathlib import Path from unittest.mock import mock_open, patch import pytest import toml -from codegen.shared.configs.models.feature_flags import CodebaseFeatureFlags, Config, FeatureFlagsConfig, RepositoryConfig +from codegen.shared.configs.models.feature_flags import CodebaseFeatureFlags, FeatureFlagsConfig +from codegen.shared.configs.models.repository import RepositoryConfig +from codegen.shared.configs.models.session import SessionConfig @pytest.fixture -def sample_config(): +def sample_config(tmpdir): codebase_flags = CodebaseFeatureFlags(debug=True, verify_graph=False) - return Config(repository=RepositoryConfig(organization_name="test-org", repo_name="test-repo"), feature_flags=FeatureFlagsConfig(codebase=codebase_flags)) + return SessionConfig(file_path=f"{tmpdir}/test_config.toml", repository=RepositoryConfig(full_name="test-org", repo_name="test-repo"), feature_flags=FeatureFlagsConfig(codebase=codebase_flags)) -def test_config_initialization(): - config = Config() +def test_config_initialization(tmpdir): + config = SessionConfig(file_path=f"{tmpdir}/test_config.toml") assert config.repository is not None assert config.feature_flags is not None assert config.secrets is not None -def test_config_with_values(): - config = Config(repository={"organization_name": "test-org", "repo_name": "test-repo"}) - assert config.repository.organization_name == "test-org" +def test_config_with_values(tmpdir): + config = SessionConfig(file_path=f"{tmpdir}/test_config.toml", repository={"full_name": "test-org", "repo_name": "test-repo"}) + assert config.repository.full_name == "test-org" assert config.repository.repo_name == "test-repo" @patch("builtins.open", new_callable=mock_open) @patch("pathlib.Path.mkdir") def test_save_config(mock_mkdir, mock_file, sample_config): - sample_config.save(Path("test_config.toml")) + sample_config.save() mock_mkdir.assert_called_once_with(parents=True, exist_ok=True) - mock_file.assert_called_once_with(Path("test_config.toml"), "w") + mock_file.assert_called_once_with(sample_config.file_path, "w") # Verify the content being written written_data = mock_file().write.call_args[0][0] parsed_data = toml.loads(written_data) - assert parsed_data["repository"]["organization_name"] == "test-org" + assert parsed_data["repository"]["full_name"] == "test-org" def test_get_config_value(sample_config): # Test getting a simple value - assert json.loads(sample_config.get("repository.organization_name")) == "test-org" + assert json.loads(sample_config.get("repository.full_name")) == "test-org" # Test getting a nested value assert json.loads(sample_config.get("feature_flags.codebase.debug")) is True @@ -56,8 +57,8 @@ def test_set_config_value(sample_config): # Instead of mocking save, we'll mock the open function used within save with patch("builtins.open", new_callable=mock_open) as mock_file: # Test setting a simple string value - sample_config.set("repository.organization_name", "new-org") - assert sample_config.repository.organization_name == "new-org" + sample_config.set("repository.full_name", "new-org") + assert sample_config.repository.full_name == "new-org" # Test setting a boolean value sample_config.set("feature_flags.codebase.debug", "false") @@ -82,7 +83,7 @@ def test_config_str_representation(sample_config): assert isinstance(config_str, str) # Verify it's valid JSON parsed = json.loads(config_str) - assert parsed["repository"]["organization_name"] == "test-org" + assert parsed["repository"]["full_name"] == "test-org" def test_set_config_new_override_key(sample_config):