def test_send_post_no_auth(self, mock_post): notifier_config = {'url': 'https://localhost/api/'} data = {'head': 'feet'} http._send_post(notifier_config, data) mock_post.assert_called_once_with( 'https://localhost/api/', data=data, auth=None )
def test_send_post_no_auth(self, mock_post): notifier_config = {'url': 'https://localhost/api/'} data = {'head': 'feet'} http._send_post(notifier_config, data) mock_post.assert_called_once_with( 'https://localhost/api/', json=data, auth=None )
def test_send_post_no_auth(self, mock_post): notifier_config = {'url': 'https://localhost/api/'} data = {'head': 'feet'} http._send_post(notifier_config, data) mock_post.assert_called_once_with( 'https://localhost/api/', data=data, headers={'Content-Type': 'application/json'}, auth=None, )
def test_send_post_auth(self, mock_post, mock_basic_auth): notifier_config = { 'url': 'https://localhost/api/', 'username': '******', 'password': '******' } data = {'head': 'feet'} http._send_post(notifier_config, data) mock_post.assert_called_once_with( 'https://localhost/api/', json=data, auth=mock_basic_auth.return_value ) mock_basic_auth.assert_called_once_with('jcline', 'hunter2')
def test_send_post_auth(self, mock_post, mock_basic_auth): notifier_config = { 'url': 'https://localhost/api/', 'username': '******', 'password': '******' } data = {'head': 'feet'} http._send_post(notifier_config, data) mock_post.assert_called_once_with( 'https://localhost/api/', data=data, auth=mock_basic_auth.return_value ) mock_basic_auth.assert_called_once_with('jcline', 'hunter2')
def test_send_post_with_ca(self, post): notifier_config = { 'url': 'https://localhost/api/', 'ca_path': '/tmp/CA', } data = {'head': 'feet'} http._send_post(notifier_config, data) post.assert_called_once_with( 'https://localhost/api/', data=data, headers={'Content-Type': 'application/json'}, auth=None, verify=notifier_config['ca_path'], timeout=15 )
def test_send_post_auth(self, mock_post, mock_basic_auth): notifier_config = { 'url': 'https://localhost/api/', 'username': '******', 'password': '******' } data = {'head': 'feet'} http._send_post(notifier_config, data) mock_post.assert_called_once_with( 'https://localhost/api/', data=data, headers={'Content-Type': 'application/json'}, auth=mock_basic_auth.return_value, timeout=15 ) mock_basic_auth.assert_called_once_with('jcline', 'hunter2')
def test_send_post_bad_response(self, mock_post, mock_basic_auth, mock_log): """Assert non-200 posts get logged.""" expected_log = 'Received HTTP 404 from HTTP notifier to https://localhost/api/.' notifier_config = { 'url': 'https://localhost/api/', 'username': '******', 'password': '******' } data = {'head': 'feet'} mock_post.return_value.status_code = 404 http._send_post(notifier_config, data) mock_post.assert_called_once_with( 'https://localhost/api/', json=data, auth=mock_basic_auth.return_value ) mock_log.error.assert_called_once_with(expected_log)
def test_send_post_bad_response(self, mock_post, mock_basic_auth, mock_log): """Assert non-200 posts get logged.""" expected_log = 'Received HTTP 404 from HTTP notifier to https://localhost/api/.' notifier_config = { 'url': 'https://localhost/api/', 'username': '******', 'password': '******' } data = {'head': 'feet'} mock_post.return_value.status_code = 404 http._send_post(notifier_config, data) mock_post.assert_called_once_with( 'https://localhost/api/', data=data, auth=mock_basic_auth.return_value ) mock_log.error.assert_called_once_with(expected_log)
def test_send_post_no_url(self, mock_post, mock_basic_auth, mock_log): """Assert attempting to post to no url fails.""" expected_log = 'HTTP notifier configured without a URL; cannot fire event' http._send_post({}, {}) mock_log.error.assert_called_once_with(expected_log) self.assertEqual(0, mock_post.call_count)