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 61d945a
Show file tree
Hide file tree
Showing 4 changed files with 32 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")
17 changes: 17 additions & 0 deletions tcms/issuetracker/tests/test_redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_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 61d945a

Please sign in to comment.