Skip to content

Commit d0c60b8

Browse files
committed
Handle owner user potentially null
1 parent dc30d7f commit d0c60b8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

codecov/commands/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ def __init__(self, current_owner: Owner, service: str, current_user: User = None
4242
if not self.service and self.requires_service:
4343
raise MissingService()
4444

45-
if self.current_owner:
45+
if self.current_owner and self.current_owner.user:
4646
self.current_user = self.current_owner.user

codecov/commands/tests/test_base.py

+22
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from codecov.commands.exceptions import MissingService
55
from core.commands.commit import CommitCommands
6+
from core.tests.factories import OwnerFactory
67

78
from ..base import BaseCommand, BaseInteractor
89

@@ -27,3 +28,24 @@ def test_base_interactor_with_missing_required_service():
2728
BaseInteractor(None, None)
2829

2930
assert excinfo.value.message == "Missing required service"
31+
32+
@pytest.mark.django_db
33+
def test_base_interactor_missing_user_in_owner():
34+
owner = OwnerFactory()
35+
owner.user = None
36+
command = BaseCommand(owner, "github", None)
37+
38+
interactor = command.get_interactor(BaseInteractor)
39+
assert interactor.current_user == AnonymousUser()
40+
41+
42+
@pytest.mark.django_db
43+
def test_base_interactor_with_owner():
44+
owner = OwnerFactory()
45+
command = BaseCommand(owner, "github")
46+
interactor = command.get_interactor(BaseInteractor)
47+
48+
assert interactor.current_owner == owner
49+
assert interactor.current_user == owner.user
50+
assert interactor.service == "github"
51+
assert interactor.requires_service is True

0 commit comments

Comments
 (0)