From d0c60b8ce627f8443cacf7e2780dd0d3211aa2ec Mon Sep 17 00:00:00 2001 From: Rola Date: Tue, 20 Aug 2024 11:03:18 +0200 Subject: [PATCH 1/2] Handle owner user potentially null --- codecov/commands/base.py | 2 +- codecov/commands/tests/test_base.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) 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..d26d5ed448 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,24 @@ 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 From 691d716acdfc15cff097e56f63cb456510c1f0bd Mon Sep 17 00:00:00 2001 From: Rola Date: Tue, 20 Aug 2024 11:07:16 +0200 Subject: [PATCH 2/2] Make lint yelling --- codecov/commands/tests/test_base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/codecov/commands/tests/test_base.py b/codecov/commands/tests/test_base.py index d26d5ed448..c40aade3f1 100644 --- a/codecov/commands/tests/test_base.py +++ b/codecov/commands/tests/test_base.py @@ -29,6 +29,7 @@ def test_base_interactor_with_missing_required_service(): assert excinfo.value.message == "Missing required service" + @pytest.mark.django_db def test_base_interactor_missing_user_in_owner(): owner = OwnerFactory()