Skip to content

Commit

Permalink
Allow overriding IssueTrackerType.rpc_credentials
Browse files Browse the repository at this point in the history
via settings.EXTERNAL_ISSUE_RPC_CREDENTIALS
  • Loading branch information
atodorov committed Aug 28, 2023
1 parent bdefcca commit 56da1db
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tcms/issuetracker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
4 changes: 4 additions & 0 deletions tcms/issuetracker/tests/redmine_post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
45 changes: 45 additions & 0 deletions tcms/issuetracker/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 4 additions & 0 deletions tcms/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 56da1db

Please sign in to comment.