Skip to content

Commit

Permalink
add test for token_auth
Browse files Browse the repository at this point in the history
  • Loading branch information
buzzdeee committed Mar 4, 2022
1 parent 4a211e2 commit fc896c1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/alerters/jira_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,31 @@ def test_jira_set_priority(caplog):
'Priority 0 not found. Valid priorities are []') == caplog.record_tuples[0]
assert ('elastalert', logging.ERROR,
'Priority 0 not found. Valid priorities are []') == caplog.record_tuples[1]

def test_jira_auth_token(caplog):
description_txt = "Test authentication via apitoken"
rule = {
'name': 'test alert',
'jira_account_file': 'jirafile',
'type': mock_rule(),
'jira_project': 'testproject',
'jira_priority': 0,
'jira_issuetype': 'testtype',
'jira_server': 'jiraserver',
'jira_description': description_txt,
'jira_assignee': 'testuser',
'timestamp_field': '@timestamp',
'alert_subject': 'Issue {0} occurred at {1}',
'alert_subject_args': ['test_term', '@timestamp'],
'rule_file': '/tmp/foo.yaml'
}
with mock.patch('elastalert.alerters.jira.JIRA') as mock_jira, \
mock.patch('elastalert.alerters.jira.read_yaml') as mock_open:
mock_open.return_value = {'apikey': 'theapikey'}
alert = JiraAlerter(rule)
alert.set_priority
expected = [
mock.call('jiraserver', token_auth=('theapikey')),
]
# we only want to test authentication via apikey, the rest we don't care of
assert mock_jira.mock_calls[:1] == expected

0 comments on commit fc896c1

Please sign in to comment.