Skip to content

Commit

Permalink
Fall-back to credentials from DB if settings.EXTERNAL_ISSUE_RPC_CREDE…
Browse files Browse the repository at this point in the history
…NTIALS override returns None
  • Loading branch information
atodorov committed Oct 24, 2023
1 parent 5adcedc commit 9df4327
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tcms/issuetracker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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 @@ -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
10 changes: 10 additions & 0 deletions tcms/issuetracker/tests/test_redmine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 9df4327

Please sign in to comment.