def setUp(self): super(IssueAPITestCase, self).setUp() with patch('ambassador.transport.Transport.get_key_cert', return_value=self.mock_cert): with patch('platforms.jira.handlers.jira.JIRA', return_value=self.mock_auth): with patch.dict('platforms.jira.handlers.settings.JIRA', self.mock_settings): self.handler_w_user = IssueAPI(endpoint=self.endpoint, user=self.user) self.handler_wo_user = IssueAPI(endpoint=self.endpoint)
def test_format_descr_wo_notes(self): """ Tests the _format_description method when the alert has no notes. """ self.mock_settings['INCLUDE_FULL_DESCRIPTION'] = False with patch('ambassador.transport.Transport.get_key_cert', return_value=self.mock_cert): with patch('platforms.jira.handlers.jira.JIRA', return_value=self.mock_auth): with patch.dict('platforms.jira.handlers.settings.JIRA', self.mock_settings): handler_w_user = IssueAPI(endpoint=self.endpoint, user=self.user) alert = Alert.objects.get(pk=2) actual = handler_w_user._format_description(alert) expected = '' self.assertEqual(actual, expected)
def test_get_jira_user_multi(self): """ Tests the _get_jira_user method when JIRA returns more than one matching user. """ self.mock_auth.search_users = Mock( return_value=[self.mock_jira_user_1, self.mock_jira_user_2]) with patch('ambassador.transport.Transport.get_key_cert', return_value=self.mock_cert): with patch('platforms.jira.handlers.jira.JIRA', return_value=self.mock_auth): with patch.dict('platforms.jira.handlers.settings.JIRA', self.mock_settings): handler_w_user = IssueAPI(endpoint=self.endpoint, user=self.user) actual = handler_w_user._get_jira_user() expected = None self.assertEqual(actual, expected)
def test_format_full_description(self): """ Tests the _format_description method when a full description is used and empty fields are included. """ with patch('ambassador.transport.Transport.get_key_cert', return_value=self.mock_cert): with patch('platforms.jira.handlers.jira.JIRA', return_value=self.mock_auth): with patch.dict('platforms.jira.handlers.settings.JIRA', self.mock_settings): handler_w_user = IssueAPI(endpoint=self.endpoint, user=self.user) alert = Alert.objects.get(pk=2) alert.data = self.mock_data actual = handler_w_user._format_description(alert) expected = """\ {code:bgColor=#f5f5f5|title=Test Alert|titleBGColor=#dcdcdc} Alert ID: 2 Title: Threat Alert Level: HIGH Incidents: 1 Created date: 2015-03-01 02:41:24.468404+00:00 Collection: mongodb.test_database.test_posts Document ID: 2 Source Data: { "host": "foo", "message": "bar" } Notes: None ----- John Smith commented at 2015-03-01 02:43:24.468404+00:00: This alert isn't this important {code}""" self.assertEqual(actual, expected)