From ac3a37be88d5514f458082ef133e0e0d00c14f83 Mon Sep 17 00:00:00 2001 From: Alexander Todorov Date: Mon, 28 Aug 2023 14:38:45 +0300 Subject: [PATCH] Allow overriding IssueTrackerType.rpc_credentials via settings.EXTERNAL_ISSUE_RPC_CREDENTIALS --- tcms/issuetracker/base.py | 7 +++++++ .../tests/redmine_post_processing.py | 4 ++++ tcms/issuetracker/tests/test_redmine.py | 17 +++++++++++++++++ tcms/settings/common.py | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/tcms/issuetracker/base.py b/tcms/issuetracker/base.py index 58ec605353..ac8eacb6a7 100644 --- a/tcms/issuetracker/base.py +++ b/tcms/issuetracker/base.py @@ -6,6 +6,7 @@ RE_ENDS_IN_INT = re.compile(r"[\d]+$") + def _function_from_path(fully_qualified_dotted_path): """ Helper function which returns a callable object from a @@ -235,4 +236,10 @@ def rpc_credentials(self): .. versionadded:: 12.6 """ + if settings.EXTERNAL_ISSUE_RPC_CREDENTIALS: + credentials_function = _function_from_path( + settings.EXTERNAL_ISSUE_RPC_CREDENTIALS + ) + return credentials_function(self) + 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 c2f2eac2f9..ca7700b6b0 100644 --- a/tcms/issuetracker/tests/redmine_post_processing.py +++ b/tcms/issuetracker/tests/redmine_post_processing.py @@ -20,3 +20,7 @@ def change_assignee(rpc, new_issue, execution, user): # Note: assignee needs to be a member of the project where issues are created # and needs to have a role with the `assignable` flag set to 1. rpc.issue.update(new_issue.id, assigned_to_id=atodorov.id) + + +def rpc_creds(issue_tracker): + return ("tester", "test-me") diff --git a/tcms/issuetracker/tests/test_redmine.py b/tcms/issuetracker/tests/test_redmine.py index c5ef8bf6e4..03d37b3ef2 100644 --- a/tcms/issuetracker/tests/test_redmine.py +++ b/tcms/issuetracker/tests/test_redmine.py @@ -144,3 +144,20 @@ def test_report_issue_from_test_execution_1click_works(self): is_defect=True, ).exists() ) + + def test_non_overriden_credentials_are_returned(self): + (rpc_username, rpc_password) = self.integration.rpc_credentials + + # admin:admin as defined above + self.assertEqual(rpc_username, "admin") + self.assertEqual(rpc_password, "admin") + + @override_settings( + EXTERNAL_ISSUE_RPC_CREDENTIALS="tcms.issuetracker.tests.redmine_post_processing.rpc_creds" + ) + def test_overriden_credentials_are_returned(self): + (rpc_username, rpc_password) = self.integration.rpc_credentials + + # not admin:admin as defined above + self.assertEqual(rpc_username, "tester") + self.assertEqual(rpc_password, "test-me") diff --git a/tcms/settings/common.py b/tcms/settings/common.py index 24db02e788..558de77588 100644 --- a/tcms/settings/common.py +++ b/tcms/settings/common.py @@ -185,6 +185,10 @@ # tcms.issuetracker.tests.redmine_post_processing for hints! EXTERNAL_ISSUE_POST_PROCESSORS = [] +# a fully qualified dotted path which overrides the implementation of +# tcms.issutracker.base.IssueTrackerType.rpc_credentials +EXTERNAL_ISSUE_RPC_CREDENTIALS = "" + # Controls the default issue type for newly created issues in Jira. # See JIRA.get_issue_from_jira() method JIRA_ISSUE_TYPE = "Bug"