From 73af482d726e17ee27005582b26ff12a6c20c360 Mon Sep 17 00:00:00 2001 From: Alexander Todorov Date: Tue, 24 Oct 2023 11:53:11 +0300 Subject: [PATCH] Fall-back to credentials from DB if settings.EXTERNAL_ISSUE_RPC_CREDENTIALS override returns None --- tcms/issuetracker/base.py | 6 +++++- tcms/issuetracker/tests/redmine_post_processing.py | 4 ++++ tcms/issuetracker/tests/test_redmine.py | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tcms/issuetracker/base.py b/tcms/issuetracker/base.py index ac8eacb6a7..b480e418c6 100644 --- a/tcms/issuetracker/base.py +++ b/tcms/issuetracker/base.py @@ -240,6 +240,10 @@ def rpc_credentials(self): credentials_function = _function_from_path( settings.EXTERNAL_ISSUE_RPC_CREDENTIALS ) - return credentials_function(self) + result = credentials_function(self) + + # if result is None or not a tuple then fallback + if result and isinstance(result, tuple): + return result return (self.bug_system.api_username, self.bug_system.api_password) diff --git a/tcms/issuetracker/tests/redmine_post_processing.py b/tcms/issuetracker/tests/redmine_post_processing.py index ca7700b6b0..e8bb48de59 100644 --- a/tcms/issuetracker/tests/redmine_post_processing.py +++ b/tcms/issuetracker/tests/redmine_post_processing.py @@ -24,3 +24,7 @@ def change_assignee(rpc, new_issue, execution, user): def rpc_creds(issue_tracker): return ("tester", "test-me") + + +def rpc_no_creds(issue_tracker): + return None diff --git a/tcms/issuetracker/tests/test_redmine.py b/tcms/issuetracker/tests/test_redmine.py index 03d37b3ef2..7acd3f5323 100644 --- a/tcms/issuetracker/tests/test_redmine.py +++ b/tcms/issuetracker/tests/test_redmine.py @@ -161,3 +161,13 @@ def test_overriden_credentials_are_returned(self): # not admin:admin as defined above self.assertEqual(rpc_username, "tester") self.assertEqual(rpc_password, "test-me") + + @override_settings( + EXTERNAL_ISSUE_RPC_CREDENTIALS="tcms.issuetracker.tests.redmine_post_processing.rpc_no_creds" + ) + def test_overriden_credentials_fallback(self): + (rpc_username, rpc_password) = self.integration.rpc_credentials + + # admin:admin as defined above b/c rpc_no_creds() returns None + self.assertEqual(rpc_username, "admin") + self.assertEqual(rpc_password, "admin")