Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle owner user potentially null in base interactor #762

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codecov/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ def __init__(self, current_owner: Owner, service: str, current_user: User = None
if not self.service and self.requires_service:
raise MissingService()

if self.current_owner:
if self.current_owner and self.current_owner.user:
self.current_user = self.current_owner.user
23 changes: 23 additions & 0 deletions codecov/commands/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from codecov.commands.exceptions import MissingService
from core.commands.commit import CommitCommands
from core.tests.factories import OwnerFactory

from ..base import BaseCommand, BaseInteractor

Expand All @@ -27,3 +28,25 @@ def test_base_interactor_with_missing_required_service():
BaseInteractor(None, None)

assert excinfo.value.message == "Missing required service"


@pytest.mark.django_db
def test_base_interactor_missing_user_in_owner():
owner = OwnerFactory()
owner.user = None
command = BaseCommand(owner, "github", None)

interactor = command.get_interactor(BaseInteractor)
assert interactor.current_user == AnonymousUser()


@pytest.mark.django_db
def test_base_interactor_with_owner():
owner = OwnerFactory()
command = BaseCommand(owner, "github")
interactor = command.get_interactor(BaseInteractor)

assert interactor.current_owner == owner
assert interactor.current_user == owner.user
assert interactor.service == "github"
assert interactor.requires_service is True
Loading