diff --git a/secureli/actions/action.py b/secureli/actions/action.py index c97f7018..e58b0fd8 100644 --- a/secureli/actions/action.py +++ b/secureli/actions/action.py @@ -98,6 +98,7 @@ def verify_install( if not self.action_deps.scanner.pre_commit.get_preferred_pre_commit_config_path( folder_path ).exists(): + self.action_deps.echo.print("bingo") update_result: VerifyResult = ( self._update_secureli_pre_commit_config_location( folder_path, always_yes diff --git a/tests/abstractions/test_pre_commit.py b/tests/abstractions/test_pre_commit.py index c0e88bfa..7d7f7ce0 100644 --- a/tests/abstractions/test_pre_commit.py +++ b/tests/abstractions/test_pre_commit.py @@ -13,6 +13,7 @@ InstallResult, PreCommitAbstraction, ) +from secureli.abstractions.echo import EchoAbstraction from secureli.repositories.settings import ( PreCommitSettings, PreCommitRepo, @@ -81,12 +82,12 @@ def mock_subprocess(mocker: MockerFixture) -> MagicMock: @pytest.fixture() def mock_echo(mocker: MockerFixture) -> MagicMock: mock_echo = MagicMock() - mocker.patch("secureli.abstractions.echo", mock_echo) return mock_echo @pytest.fixture() def pre_commit( + mock_echo: mock_echo, mock_hashlib: MagicMock, mock_open: MagicMock, mock_subprocess: MagicMock, @@ -558,9 +559,9 @@ def test_migrate_config_file_moves_pre_commit_conig( um.patch.object(Path, "exists", return_value=True), ): pre_commit.migrate_config_file(test_folder_path) - old_location = test_folder_path / ".pre-commit-config.yaml" + old_location = test_folder_path / ".secureli" / ".pre-commit-config.yaml" new_location = test_folder_path / ".secureli" / ".pre-commit-config.yaml" - mock_echo.print.assert_called_with( + mock_echo.print.assert_called_once_with( f"Moving {old_location} to {new_location}..." ) mock_move.assert_called_once() diff --git a/tests/actions/test_action.py b/tests/actions/test_action.py index 280641cd..c3c26651 100644 --- a/tests/actions/test_action.py +++ b/tests/actions/test_action.py @@ -1,5 +1,6 @@ from pathlib import Path from unittest.mock import MagicMock +import unittest.mock as um import pytest from secureli.abstractions.pre_commit import InstallResult @@ -407,31 +408,23 @@ def test_that_verify_install_returns_success_result_newly_detected_language_inst assert verify_result.outcome == VerifyOutcome.INSTALL_SUCCEEDED -def my_side_effect(): - raise Exception("Test") - - -def test_that_verify_install_returns_failure_result( +def test_that_verify_install_returns_failure_result_without_file_path( action: Action, mock_scanner: MagicMock, mock_echo: MagicMock, ): - mock_scanner.pre_commit.get_preferred_pre_commit_config_path.return_value = ( - test_folder_path / ".secureli" / ".pre-commit-config.yaml" - ) - # not properly mocking this? - mock_scanner.pre_commit.migrate_config_file.return_value.raiseError = my_side_effect - update_result = action._update_secureli_pre_commit_config_location( - test_folder_path, True - ) - mock_echo.print.assert_called_once_with( - "seCureLI's .pre-commit-config.yaml is in a deprecated location." - ) - assert update_result.outcome == VerifyOutcome.UPDATE_FAILED + with (um.patch.object(Path, "exists", return_value=False),): + mock_scanner.pre_commit.get_preferred_pre_commit_config_path.return_value = ( + Path(None) + ) + update_result = action.verify_install( + test_folder_path, reset=False, always_yes=True + ) -# BINGO BONGO BINGO BONGO BINGO BONGO BINGO BONGO BINGO BONGO BINGO BONGO BINGO BONGO -# BINGO BONGO BINGO BONGO BINGO BONGO BINGO BONGO BINGO BONGO BINGO BONGO BINGO BONGO + mock_echo.print.assert_called_with("bingo") + assert mock_scanner.pre_commit.migrate_config_file.assert_called_once() + assert update_result.outcome == VerifyOutcome.UPDATE_FAILED def test_that_update_secureli_pre_commit_config_location_moves_file( @@ -453,17 +446,15 @@ def test_that_update_secureli_pre_commit_config_location_moves_file( def test_that_update_secureli_pre_commit_config_fails_on_exception( action: Action, mock_scanner: MagicMock, - mock_echo: MagicMock, ): - update_file_location = test_folder_path / ".secureli" / ".pre-commit-config.yaml" - update_result = action._update_secureli_pre_commit_config_location( - update_file_location, True - ) - mock_echo.print.assert_called_once_with( - "seCureLI's .pre-commit-config.yaml is in a deprecated location." - ) - mock_scanner.pre_commit.migrate_config_file.raiseError.side_effect = my_side_effect - assert update_result.outcome == VerifyOutcome.UPDATE_FAILED + with pytest.raises(Exception): + mock_scanner.pre_commit.get_preferred_pre_commit_config_path.return_value = ( + test_folder_path / ".secureli" / ".pre-commit-config.yaml" + ) + update_result = action._update_secureli_pre_commit_config_location( + test_folder_path, True + ) + assert update_result.outcome == VerifyOutcome.UPDATE_FAILED def test_that_update_secureli_pre_commit_config_location_does_not_move_file( diff --git a/tests/actions/test_initializer_action.py b/tests/actions/test_initializer_action.py index dcc1df05..f46b53de 100644 --- a/tests/actions/test_initializer_action.py +++ b/tests/actions/test_initializer_action.py @@ -5,11 +5,8 @@ from secureli.actions.action import ActionDependencies from secureli.actions.initializer import InitializerAction -from secureli.repositories.secureli_config import SecureliConfig -from secureli.repositories.settings import SecureliFile, TelemetrySettings from secureli.services.language_config import LanguageNotSupportedError from secureli.services.logging import LogAction -from secureli.settings import Settings test_folder_path = Path("does-not-matter")