diff --git a/secureli/modules/language_analyzer/language_support.py b/secureli/modules/language_analyzer/language_support.py index 429ae99c..43afa827 100644 --- a/secureli/modules/language_analyzer/language_support.py +++ b/secureli/modules/language_analyzer/language_support.py @@ -211,8 +211,8 @@ def build_pre_commit_config( else None ) data = yaml.safe_load(result.config_data) + config_repos += data["repos"] or [] - config_repos += data["repos"] or [] config = {**existing_data, "repos": config_repos} version = hash_config(yaml.dump(config)) diff --git a/tests/modules/language_analyzer/test_language_support.py b/tests/modules/language_analyzer/test_language_support.py index 0c3df395..a3cbc4d2 100644 --- a/tests/modules/language_analyzer/test_language_support.py +++ b/tests/modules/language_analyzer/test_language_support.py @@ -401,7 +401,7 @@ def test_write_pre_commit_configs_writes_successfully( def test_build_pre_commit_displays_error_parsing_existing_config( - language_support_service: LanguageSupportService, + language_support_service: language_support.LanguageSupportService, mock_language_config_service: MagicMock, mock_open: MagicMock, mock_echo: MagicMock, @@ -410,10 +410,10 @@ def test_build_pre_commit_displays_error_parsing_existing_config( patch("builtins.open", mock_open(read_data="data")), patch.object(yaml, "safe_load", side_effect=yaml.YAMLError), ): - mock_language_config_service.get_language_config.return_value = LanguagePreCommitResult( + mock_language_config_service.get_language_config.return_value = language.LanguagePreCommitResult( language="Python", version="abc123", - linter_config=LoadLinterConfigsResult( + linter_config=language.LoadLinterConfigsResult( successful=True, linter_data=[{"filename": "test.txt", "settings": {}}], ), diff --git a/tests/modules/shared/abstractions/test_pre_commit.py b/tests/modules/shared/abstractions/test_pre_commit.py index b51010a8..4c05d777 100644 --- a/tests/modules/shared/abstractions/test_pre_commit.py +++ b/tests/modules/shared/abstractions/test_pre_commit.py @@ -9,15 +9,12 @@ import pytest from pytest_mock import MockerFixture -from secureli.abstractions.pre_commit import ( +from secureli.modules.shared.abstractions.pre_commit import ( InstallResult, PreCommitAbstraction, ) -from secureli.repositories.settings import ( - PreCommitSettings, - PreCommitRepo, - PreCommitHook, -) +from secureli.repositories import repo_settings + test_folder_path = Path("does-not-matter") example_git_sha = "a" * 40 @@ -25,13 +22,13 @@ @pytest.fixture() def settings_dict() -> dict: - return PreCommitSettings( + return repo_settings.PreCommitSettings( repos=[ - PreCommitRepo( + repo_settings.PreCommitRepo( repo="http://example-repo.com/", rev="master", hooks=[ - PreCommitHook( + repo_settings.PreCommitHook( id="hook-id", arguments=None, additional_args=None, @@ -48,7 +45,7 @@ def mock_hashlib(mocker: MockerFixture) -> MagicMock: mock_md5 = MagicMock() mock_hashlib.md5.return_value = mock_md5 mock_md5.hexdigest.return_value = "mock-hash-code" - mocker.patch("secureli.utilities.hash.hashlib", mock_hashlib) + mocker.patch("secureli.modules.shared.utilities.hashlib", mock_hashlib) return mock_hashlib @@ -58,7 +55,7 @@ def mock_hashlib_no_match(mocker: MockerFixture) -> MagicMock: mock_md5 = MagicMock() mock_hashlib.md5.return_value = mock_md5 mock_md5.hexdigest.side_effect = ["first-hash-code", "second-hash-code"] - mocker.patch("secureli.utilities.hash.hashlib", mock_hashlib) + mocker.patch("secureli.modules.shared.utilities.hashlib", mock_hashlib) return mock_hashlib @@ -73,7 +70,9 @@ def mock_data_loader() -> MagicMock: def mock_subprocess(mocker: MockerFixture) -> MagicMock: mock_subprocess = MagicMock() mock_subprocess.run.return_value = CompletedProcess(args=[], returncode=0) - mocker.patch("secureli.abstractions.pre_commit.subprocess", mock_subprocess) + mocker.patch( + "secureli.modules.shared.abstractions.pre_commit.subprocess", mock_subprocess + ) return mock_subprocess @@ -431,14 +430,16 @@ def test_check_for_hook_updates_infers_freeze_param_when_not_provided( rev_is_sha: bool, ): with um.patch( - "secureli.abstractions.pre_commit.HookRepoRevInfo.from_config" + "secureli.modules.shared.abstractions.pre_commit.HookRepoRevInfo.from_config" ) as mock_hook_repo_rev_info: - pre_commit_config_repo = PreCommitRepo( + pre_commit_config_repo = repo_settings.PreCommitRepo( repo="http://example-repo.com/", rev=rev, - hooks=[PreCommitHook(id="hook-id")], + hooks=[repo_settings.PreCommitHook(id="hook-id")], + ) + pre_commit_config = repo_settings.PreCommitSettings( + repos=[pre_commit_config_repo] ) - pre_commit_config = PreCommitSettings(repos=[pre_commit_config_repo]) rev_info_mock = MagicMock(rev=pre_commit_config_repo.rev) mock_hook_repo_rev_info.return_value = rev_info_mock rev_info_mock.update.return_value = rev_info_mock # Returning the same revision info on update means the hook will be considered up to date @@ -454,14 +455,16 @@ def test_check_for_hook_updates_respects_freeze_param_when_false( regardless of whether the existing rev is a tag or a commit hash. """ with um.patch( - "secureli.abstractions.pre_commit.HookRepoRevInfo.from_config" + "secureli.modules.shared.abstractions.pre_commit.HookRepoRevInfo.from_config" ) as mock_hook_repo_rev_info: - pre_commit_config_repo = PreCommitRepo( + pre_commit_config_repo = repo_settings.PreCommitRepo( repo="http://example-repo.com/", rev=example_git_sha, - hooks=[PreCommitHook(id="hook-id")], + hooks=[repo_settings.PreCommitHook(id="hook-id")], + ) + pre_commit_config = repo_settings.PreCommitSettings( + repos=[pre_commit_config_repo] ) - pre_commit_config = PreCommitSettings(repos=[pre_commit_config_repo]) rev_info_mock = MagicMock(rev=pre_commit_config_repo.rev) mock_hook_repo_rev_info.return_value = rev_info_mock rev_info_mock.update.return_value = rev_info_mock # Returning the same revision info on update means the hook will be considered up to date @@ -473,14 +476,16 @@ def test_check_for_hook_updates_respects_freeze_param_when_true( pre_commit: PreCommitAbstraction, ): with um.patch( - "secureli.abstractions.pre_commit.HookRepoRevInfo.from_config" + "secureli.modules.shared.abstractions.pre_commit.HookRepoRevInfo.from_config" ) as mock_hook_repo_rev_info: - pre_commit_config_repo = PreCommitRepo( + pre_commit_config_repo = repo_settings.PreCommitRepo( repo="http://example-repo.com/", rev="tag1", - hooks=[PreCommitHook(id="hook-id")], + hooks=[repo_settings.PreCommitHook(id="hook-id")], + ) + pre_commit_config = repo_settings.PreCommitSettings( + repos=[pre_commit_config_repo] ) - pre_commit_config = PreCommitSettings(repos=[pre_commit_config_repo]) rev_info_mock = MagicMock(rev=pre_commit_config_repo.rev) mock_hook_repo_rev_info.return_value = rev_info_mock rev_info_mock.update.return_value = rev_info_mock # Returning the same revision info on update means the hook will be considered up to date @@ -492,15 +497,17 @@ def test_check_for_hook_updates_returns_repos_with_new_revs( pre_commit: PreCommitAbstraction, ): with um.patch( - "secureli.abstractions.pre_commit.HookRepoRevInfo" + "secureli.modules.shared.abstractions.pre_commit.HookRepoRevInfo" ) as mock_hook_repo_rev_info: repo_urls = ["http://example-repo.com/", "http://example-repo-2.com/"] old_rev = "tag1" repo_1_new_rev = "tag2" - pre_commit_config = PreCommitSettings( + pre_commit_config = repo_settings.PreCommitSettings( repos=[ - PreCommitRepo( - repo=repo_url, rev=old_rev, hooks=[PreCommitHook(id="hook-id")] + repo_settings.PreCommitRepo( + repo=repo_url, + rev=old_rev, + hooks=[repo_settings.PreCommitHook(id="hook-id")], ) for repo_url in repo_urls ]