Skip to content

Commit 230a40c

Browse files
committed
fix test config
1 parent 535b6b7 commit 230a40c

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

tests/unit/codegen/shared/configs/test_config.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,30 @@ def test_merge_configs_none_values():
3434

3535

3636
def test_merge_configs_empty_string():
37-
base = {"repository": {"organization_name": "org1"}}
38-
override = {"repository": {"organization_name": ""}}
37+
base = {"repository": {"full_name": "org1/test-repo"}}
38+
override = {"repository": {"full_name": ""}}
3939
result = _merge_configs(base, override)
40-
assert result == {"repository": {"organization_name": "org1"}}
40+
assert result == {"repository": {"full_name": "org1/test-repo"}}
4141

4242

4343
# Test _load_from_toml
4444
def test_load_from_toml_existing_file(temp_config_file):
4545
config = _load_from_toml(temp_config_file)
4646
assert isinstance(config, SessionConfig)
4747
assert config.secrets.github_token == "gh_token123"
48-
assert config.repository.organization_name == "test-org"
48+
assert config.repository.repo_name == "test-repo"
4949
assert config.feature_flags.codebase.debug is True
5050
assert config.feature_flags.codebase.typescript.ts_dependency_manager is True
5151
assert config.feature_flags.codebase.import_resolution_overrides == {"@org/pkg": "./local/path"}
5252

5353

54+
@patch.dict("os.environ", {})
5455
@patch("codegen.shared.configs.models.SecretsConfig.model_config", {"env_file": "nonexistent.env"})
5556
def test_load_from_toml_nonexistent_file():
5657
config = _load_from_toml(Path("nonexistent.toml"))
5758
assert isinstance(config, SessionConfig)
5859
assert config.secrets.github_token is None
59-
assert config.repository.organization_name is None
60+
assert config.repository.full_name is None
6061
assert config.feature_flags.codebase.debug is None
6162

6263

@@ -76,15 +77,15 @@ def test_load_from_env():
7677
@patch("codegen.shared.configs.models.SecretsConfig.model_config", {"env_file": None, "env_prefix": "CODEGEN_SECRETS__"})
7778
def test_load_with_both_configs(mock_toml, mock_env):
7879
# Setup mock returns
79-
mock_env.return_value = SessionConfig(secrets=SecretsConfig(github_token="env_token"), feature_flags=FeatureFlagsConfig(codebase=CodebaseFeatureFlags(debug=True)))
80-
mock_toml.return_value = SessionConfig(secrets={"openai_api_key": "openai_key"}, repository={"organization_name": "codegen-org"})
80+
mock_env.return_value = Config(secrets=SecretsConfig(github_token="env_token"), feature_flags=FeatureFlagsConfig(codebase=CodebaseFeatureFlags(debug=True)))
81+
mock_toml.return_value = Config(secrets={"openai_api_key": "openai_key"}, repository={"full_name": "codegen-org/test-repo"})
8182

8283
config = load_session_config(CONFIG_PATH)
8384

8485
assert isinstance(config, SessionConfig)
8586
assert config.secrets.github_token == "env_token"
8687
assert config.secrets.openai_api_key == "openai_key"
87-
assert config.repository.organization_name == "codegen-org"
88+
assert config.repository.full_name == "codegen-org/test-repo"
8889
assert config.feature_flags.codebase.debug is True
8990

9091

tests/unit/codegen/shared/configs/test_models.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@pytest.fixture
1313
def sample_config(tmpdir):
1414
codebase_flags = CodebaseFeatureFlags(debug=True, verify_graph=False)
15-
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))
15+
return Config(repository=RepositoryConfig(full_name="test-org/test-repo", repo_name="test-repo"), feature_flags=FeatureFlagsConfig(codebase=codebase_flags))
1616

1717

1818
def test_config_initialization(tmpdir):
@@ -22,9 +22,9 @@ def test_config_initialization(tmpdir):
2222
assert config.secrets is not None
2323

2424

25-
def test_config_with_values(tmpdir):
26-
config = SessionConfig(file_path=f"{tmpdir}/test_config.toml", repository={"full_name": "test-org", "repo_name": "test-repo"})
27-
assert config.repository.full_name == "test-org"
25+
def test_config_with_values():
26+
config = Config(repository={"full_name": "test-org/test-repo", "repo_name": "test-repo"})
27+
assert config.repository.full_name == "test-org/test-repo"
2828
assert config.repository.repo_name == "test-repo"
2929

3030

@@ -39,12 +39,12 @@ def test_save_config(mock_mkdir, mock_file, sample_config):
3939
# Verify the content being written
4040
written_data = mock_file().write.call_args[0][0]
4141
parsed_data = toml.loads(written_data)
42-
assert parsed_data["repository"]["full_name"] == "test-org"
42+
assert parsed_data["repository"]["full_name"] == "test-org/test-repo"
4343

4444

4545
def test_get_config_value(sample_config):
4646
# Test getting a simple value
47-
assert json.loads(sample_config.get("repository.full_name")) == "test-org"
47+
assert json.loads(sample_config.get("repository.full_name")) == "test-org/test-repo"
4848

4949
# Test getting a nested value
5050
assert json.loads(sample_config.get("feature_flags.codebase.debug")) is True
@@ -57,8 +57,8 @@ def test_set_config_value(sample_config):
5757
# Instead of mocking save, we'll mock the open function used within save
5858
with patch("builtins.open", new_callable=mock_open) as mock_file:
5959
# Test setting a simple string value
60-
sample_config.set("repository.full_name", "new-org")
61-
assert sample_config.repository.full_name == "new-org"
60+
sample_config.set("repository.full_name", "new-org/test-repo")
61+
assert sample_config.repository.full_name == "new-org/test-repo"
6262

6363
# Test setting a boolean value
6464
sample_config.set("feature_flags.codebase.debug", "false")
@@ -83,7 +83,7 @@ def test_config_str_representation(sample_config):
8383
assert isinstance(config_str, str)
8484
# Verify it's valid JSON
8585
parsed = json.loads(config_str)
86-
assert parsed["repository"]["full_name"] == "test-org"
86+
assert parsed["repository"]["full_name"] == "test-org/test-repo"
8787

8888

8989
def test_set_config_new_override_key(sample_config):

0 commit comments

Comments
 (0)