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..1b2460535c 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_credentials(issue_tracker): + return ("tester", "test-me") diff --git a/tcms/issuetracker/tests/test_base.py b/tcms/issuetracker/tests/test_base.py new file mode 100644 index 0000000000..2b9396fdbd --- /dev/null +++ b/tcms/issuetracker/tests/test_base.py @@ -0,0 +1,45 @@ +# pylint: disable=attribute-defined-outside-init + +import os +import unittest + +from django.test import override_settings + +from tcms.issuetracker.types import Redmine +from tcms.rpc.tests.utils import APITestCase +from tcms.testcases.models import BugSystem + + +@unittest.skipUnless( + os.getenv("TEST_BUGTRACKER_INTEGRATION"), + "Bug tracker integration testing not enabled", +) +class TestBaseIntegration(APITestCase): + def _fixture_setup(self): + super()._fixture_setup() + + bug_system = BugSystem.objects.create( # nosec:B106:hardcoded_password_funcarg + name="Redmine at kiwitcms.atlassian.net", + tracker_type="tcms.issuetracker.types.Redmine", + base_url="http://bugtracker.kiwitcms.org:3000", + api_username="admin", + api_password="admin", + ) + self.integration = Redmine(bug_system, None) + + def test_non_overriden_credentials_are_returned(self): + (rpc_username, rpc_password) = self.integration.rpc_credentials + + # not 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_credentials" + ) + 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"