diff --git a/codecov/commands/base.py b/codecov/commands/base.py index b451efb35c..a0ea34af6c 100644 --- a/codecov/commands/base.py +++ b/codecov/commands/base.py @@ -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 diff --git a/codecov/commands/tests/test_base.py b/codecov/commands/tests/test_base.py index 92e75858e2..c40aade3f1 100644 --- a/codecov/commands/tests/test_base.py +++ b/codecov/commands/tests/test_base.py @@ -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 @@ -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