Skip to content

Commit

Permalink
renamed file repository classes to just repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Bowden committed Jun 13, 2024
1 parent 533bbdc commit cb03ff2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 39 deletions.
6 changes: 3 additions & 3 deletions secureli/actions/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from secureli.modules.shared.abstractions.echo import EchoAbstraction
from secureli.actions import action
from secureli.modules.shared.abstractions.version_control_file_repository import (
VersionControlFileRepositoryAbstraction,
from secureli.modules.shared.abstractions.version_control_repo import (
VersionControlRepoAbstraction,
)
from secureli.modules.shared.models.exit_codes import ExitCode
from secureli.modules.shared.models import install
Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(
hooks_scanner: HooksScannerService,
pii_scanner: PiiScannerService,
custom_regex_scanner: CustomRegexScannerService,
file_repo: VersionControlFileRepositoryAbstraction,
file_repo: VersionControlRepoAbstraction,
):
super().__init__(action_deps)
self.hooks_scanner = hooks_scanner
Expand Down
12 changes: 5 additions & 7 deletions secureli/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from secureli.actions.scan import ScanAction
from secureli.actions.build import BuildAction
from secureli.actions.update import UpdateAction
from secureli.modules.shared.abstractions.version_control_file_repository import (
VersionControlFileRepositoryAbstraction,
from secureli.modules.shared.abstractions.version_control_repo import (
VersionControlRepoAbstraction,
)
from secureli.repositories.git_file_repository import GitFileRepository
from secureli.repositories.git_repo import GitRepo
from secureli.repositories.secureli_config import SecureliConfigRepository
from secureli.repositories.repo_settings import SecureliRepository
from secureli.modules.shared.resources import read_resource
Expand Down Expand Up @@ -55,13 +55,11 @@ class Container(containers.DeclarativeContainer):

# Repositories
"""Abstraction for interacting with a version control file repo"""
version_control_file_repository = providers.Factory(
VersionControlFileRepositoryAbstraction
)
version_control_file_repository = providers.Factory(VersionControlRepoAbstraction)

"""Git implementation of version control file repo"""
git_files_repository = providers.Factory(
GitFileRepository,
GitRepo,
max_file_size=config.repo_files.max_file_size.as_int(),
ignored_file_extensions=config.repo_files.ignored_file_extensions,
ignored_file_patterns=combined_ignored_file_patterns,
Expand Down
6 changes: 3 additions & 3 deletions secureli/modules/custom_regex_scanner/custom_regex_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import secureli.modules.shared.models.scan as scan
from secureli.modules.shared.abstractions.echo import EchoAbstraction
from secureli.modules.shared.abstractions.version_control_file_repository import (
VersionControlFileRepositoryAbstraction,
from secureli.modules.shared.abstractions.version_control_repo import (
VersionControlRepoAbstraction,
)


Expand All @@ -32,7 +32,7 @@ class CustomRegexScannerService:

def __init__(
self,
repo_files: VersionControlFileRepositoryAbstraction,
repo_files: VersionControlRepoAbstraction,
echo: EchoAbstraction,
):
self.repo_files = repo_files
Expand Down
6 changes: 3 additions & 3 deletions secureli/modules/language_analyzer/language_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from secureli.modules.shared.abstractions.lexer_guesser import LexerGuesser
from secureli.modules.shared.models.language import AnalyzeResult, SkippedFile
from secureli.modules.shared.abstractions.version_control_file_repository import (
VersionControlFileRepositoryAbstraction,
from secureli.modules.shared.abstractions.version_control_repo import (
VersionControlRepoAbstraction,
)
from secureli.modules.shared.consts.language import supported_languages

Expand All @@ -16,7 +16,7 @@ class LanguageAnalyzerService:

def __init__(
self,
repo_files: VersionControlFileRepositoryAbstraction,
repo_files: VersionControlRepoAbstraction,
lexer_guesser: LexerGuesser,
):
self.repo_files = repo_files
Expand Down
6 changes: 3 additions & 3 deletions secureli/modules/pii_scanner/pii_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import secureli.modules.shared.models.scan as scan
from secureli.modules.shared.abstractions.echo import EchoAbstraction
from secureli.modules.shared.abstractions.version_control_file_repository import (
VersionControlFileRepositoryAbstraction,
from secureli.modules.shared.abstractions.version_control_repo import (
VersionControlRepoAbstraction,
)


Expand All @@ -35,7 +35,7 @@ class PiiScannerService:

def __init__(
self,
repo_files: VersionControlFileRepositoryAbstraction,
repo_files: VersionControlRepoAbstraction,
echo: EchoAbstraction,
ignored_extensions: list[str],
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path


class VersionControlFileRepositoryAbstraction(ABC):
class VersionControlRepoAbstraction(ABC):
"""
Abstracts common version control repository functions
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import subprocess
import chardet

from secureli.modules.shared.abstractions.version_control_file_repository import (
VersionControlFileRepositoryAbstraction,
from secureli.modules.shared.abstractions.version_control_repo import (
VersionControlRepoAbstraction,
)
from secureli.modules.shared.utilities import combine_patterns

Expand All @@ -19,7 +19,7 @@ def __init__(self, message):
super().__init__(self.message)


class GitFileRepository(VersionControlFileRepositoryAbstraction):
class GitRepo(VersionControlRepoAbstraction):
"""
The Git implementation of a version control file repository.
Lists staged files and all files in repository. Reads a file by path to a utf-8 string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
from pytest_mock import MockerFixture
from subprocess import CompletedProcess

from secureli.repositories.git_file_repository import GitFileRepository
from secureli.repositories.git_repo import GitRepo


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


Expand Down Expand Up @@ -139,24 +137,24 @@ def binary_file_with_size_file_path(mock_open_resource_with_binary_file) -> Magi


@pytest.fixture()
def repo_files_repository() -> GitFileRepository:
def repo_files_repository() -> GitRepo:
all_mov_files = "^(?:.+/)?[^/]*\\.mov(?:(?P<ps_d>/).*)?$"
return GitFileRepository(
return GitRepo(
max_file_size=10000,
ignored_file_extensions="",
ignored_file_patterns=[all_mov_files],
)


def test_that_list_repo_files_raises_value_error_without_git_repo(
repo_files_repository: GitFileRepository, git_not_exists_folder_path: MagicMock
repo_files_repository: GitRepo, git_not_exists_folder_path: MagicMock
):
with pytest.raises(ValueError):
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: GitFileRepository,
repo_files_repository: GitRepo,
mock_subprocess: MagicMock,
):
fake_file_1 = "i/am/staged"
Expand All @@ -172,15 +170,15 @@ def test_that_list_staged_files_returns_list_of_staged_files(


def test_that_list_repo_files_raises_value_error_if_dot_git_is_a_file_somehow(
repo_files_repository: GitFileRepository,
repo_files_repository: GitRepo,
git_a_file_for_some_reason_folder_path: MagicMock,
):
with pytest.raises(ValueError):
repo_files_repository.list_repo_files(git_a_file_for_some_reason_folder_path)


def test_that_list_repo_files_filters_out_invisible_files_and_folders(
repo_files_repository: GitFileRepository, good_folder_path: MagicMock
repo_files_repository: GitRepo, good_folder_path: MagicMock
):
files = repo_files_repository.list_repo_files(good_folder_path)

Expand All @@ -189,43 +187,43 @@ def test_that_list_repo_files_filters_out_invisible_files_and_folders(


def test_that_load_file_loads_data(
repo_files_repository: GitFileRepository, good_file_path: MagicMock
repo_files_repository: GitRepo, good_file_path: MagicMock
):
data = repo_files_repository.load_file(good_file_path)

assert data == "sample_data"


def test_that_load_file_raises_value_error_for_nonexistent_file(
repo_files_repository: GitFileRepository, nonexistent_file_path: MagicMock
repo_files_repository: GitRepo, nonexistent_file_path: MagicMock
):
with pytest.raises(ValueError):
repo_files_repository.load_file(nonexistent_file_path)


def test_that_load_file_raises_value_error_for_file_that_is_too_big(
repo_files_repository: GitFileRepository, too_big_file_path: MagicMock
repo_files_repository: GitRepo, too_big_file_path: MagicMock
):
with pytest.raises(ValueError):
repo_files_repository.load_file(too_big_file_path)


def test_that_load_file_raises_value_error_for_file_if_io_error_occurs(
repo_files_repository: GitFileRepository, io_error_occurs_file_path: MagicMock
repo_files_repository: GitRepo, io_error_occurs_file_path: MagicMock
):
with pytest.raises(ValueError):
repo_files_repository.load_file(io_error_occurs_file_path)


def test_that_load_file_raises_value_error_for_file_if_value_error_occurs(
repo_files_repository: GitFileRepository, value_error_occurs_file_path: MagicMock
repo_files_repository: GitRepo, value_error_occurs_file_path: MagicMock
):
with pytest.raises(ValueError):
repo_files_repository.load_file(value_error_occurs_file_path)


def test_that_load_file_raises_value_error_for_binary_file_with_size(
repo_files_repository: GitFileRepository,
repo_files_repository: GitRepo,
binary_file_with_size_file_path: MagicMock,
):
with pytest.raises(
Expand Down

0 comments on commit cb03ff2

Please sign in to comment.