Skip to content

Commit

Permalink
secureli-435: add repo_files test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathleen Hogan committed Mar 22, 2024
1 parent 192b2ce commit f2899f5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion secureli/modules/pii_scanner/pii_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def scan_repo(
:param scan_mode: Whether to scan the staged files (i.e., the files about to be
committed) or the entire repository
:param files: A specified list of files to scan
:return: A ScanResult object containing whether we succeeded and any error
:return: A ScanResult object with details of whether the scan succeeded and, if not, details of the failures
"""

file_paths = self._get_files_list(
Expand Down
24 changes: 24 additions & 0 deletions tests/repositories/test_repo_files_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@

import pytest
from pytest_mock import MockerFixture
from subprocess import CompletedProcess

from secureli.repositories.repo_files import RepoFilesRepository


@pytest.fixture()
def mock_subprocess(mocker: MockerFixture) -> MagicMock:
mock_subprocess = MagicMock()
mocker.patch("secureli.repositories.repo_files.subprocess", mock_subprocess)
return mock_subprocess


@pytest.fixture()
def git_not_exists_folder_path() -> MagicMock:
git_folder_path = MagicMock()
Expand Down Expand Up @@ -145,6 +153,22 @@ def test_that_list_repo_files_raises_value_error_without_git_repo(
repo_files_repository.list_repo_files(git_not_exists_folder_path)


def test_that_list_staged_files_returns_list_of_staged_files(
repo_files_repository: RepoFilesRepository,
mock_subprocess: MagicMock,
):
fake_file_1 = "i/am/staged"
fake_file_2 = "also/staged"
mock_subprocess.run.return_value = CompletedProcess(
args=[],
returncode=0,
stdout=f"{fake_file_1}\n{fake_file_2}\n".encode("utf8"),
)

result = repo_files_repository.list_staged_files(Path("."))
assert result == [fake_file_1, fake_file_2]


def test_that_list_repo_files_raises_value_error_if_dot_git_is_a_file_somehow(
repo_files_repository: RepoFilesRepository,
git_a_file_for_some_reason_folder_path: MagicMock,
Expand Down

0 comments on commit f2899f5

Please sign in to comment.