Skip to content

Commit

Permalink
re-export shared bot exceptions instead of redefine them
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-codecov committed Aug 7, 2024
1 parent 1357214 commit 755f415
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
29 changes: 8 additions & 21 deletions helpers/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import shared.bots.exceptions

RepositoryWithoutValidBotError = shared.bots.exceptions.RepositoryWithoutValidBotError
OwnerWithoutValidBotError = shared.bots.exceptions.OwnerWithoutValidBotError
RequestedGithubAppNotFound = shared.bots.exceptions.RequestedGithubAppNotFound
NoConfiguredAppsAvailable = shared.bots.exceptions.NoConfiguredAppsAvailable


class ReportExpiredException(Exception):
def __init__(self, message=None, filename=None) -> None:
super().__init__(message)
Expand All @@ -8,27 +16,6 @@ class ReportEmptyError(Exception):
pass


class RepositoryWithoutValidBotError(Exception):
pass


class RequestedGithubAppNotFound(Exception):
pass


class OwnerWithoutValidBotError(Exception):
pass


class NoConfiguredAppsAvailable(Exception):
def __init__(
self, apps_count: int, rate_limited_count: int, suspended_count: int
) -> None:
self.apps_count = apps_count
self.rate_limited_count = rate_limited_count
self.suspended_count = suspended_count


class CorruptRawReportError(Exception):
"""Error indicated that report is somehow different than it should be
Expand Down
25 changes: 24 additions & 1 deletion tasks/tests/unit/test_preprocess_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ReportFactory,
RepositoryFactory,
)
from helpers.exceptions import RepositoryWithoutValidBotError
from helpers.exceptions import OwnerWithoutValidBotError, RepositoryWithoutValidBotError
from services.report import ReportService
from tasks.preprocess_upload import PreProcessUpload

Expand Down Expand Up @@ -216,6 +216,29 @@ def test_run_impl_unobtainable_lock(self, dbsession, mocker, mock_redis):
"reason": "unable_to_acquire_lock",
}

def test_get_repo_service_repo_and_owner_lack_bot(self, dbsession, mocker):
def mock_owner(foo):
print("in mock owner", foo)
raise OwnerWithoutValidBotError()

Check warning on line 222 in tasks/tests/unit/test_preprocess_upload.py

View check run for this annotation

Codecov Notifications / codecov/patch

tasks/tests/unit/test_preprocess_upload.py#L221-L222

Added lines #L221 - L222 were not covered by tests

mock_owner_bot = mocker.patch(
"shared.bots.repo_bots.get_owner_or_appropriate_bot"
)
mock_owner_bot.side_effect = OwnerWithoutValidBotError()

mock_github_installations = mocker.patch(
"shared.bots.github_apps.get_github_app_info_for_owner"
)
mock_github_installations.return_value = []

mock_save_error = mocker.patch("tasks.preprocess_upload.save_commit_error")

commit = CommitFactory.create(repository__private=True, repository__bot=None)
repo_service = PreProcessUpload().get_repo_service(commit, None)

assert repo_service is None
mock_save_error.assert_called()

def test_get_repo_provider_service_no_bot(self, dbsession, mocker):
mocker.patch("tasks.preprocess_upload.save_commit_error")
mock_get_repo_service = mocker.patch(
Expand Down

0 comments on commit 755f415

Please sign in to comment.