def test_post_event_to_st2_sensu_stashed(self): sensu_handler.ST2_API_BASE_URL = 'https://localhost/api/v1/' responses.add( responses.POST, 'https://localhost/api/v1/webhooks/st2', json={}, status=202 ) responses.add( responses.GET, 'http://localhost:4567/stashes/silence/ma_client', json={}, status=200 ) responses.add( responses.GET, 'http://localhost:4567/stashes/silence/ma_client/ma_check', json={}, status=200 ) responses.add( responses.GET, 'http://localhost:4567/stashes/silence/all/ma_check', json={}, status=200 ) trigger_payload = { 'client': {'name': 'ma_client'}, 'check': {'name': 'ma_check'}, 'id': 'foo-check-id' } with self.assertRaises(SystemExit) as cm: sensu_handler._post_event_to_st2(json.dumps(trigger_payload)) self.assertEqual(cm.exception.code, 0)
def test_post_event_to_st2_sensu_stashed(self): sensu_handler.ST2_API_BASE_URL = 'https://localhost/api/v1/' responses.add(responses.POST, 'https://localhost/api/v1/webhooks/st2', json={}, status=202) responses.add(responses.GET, 'http://localhost:4567/stashes/silence/ma_client', json={}, status=200) responses.add( responses.GET, 'http://localhost:4567/stashes/silence/ma_client/ma_check', json={}, status=200) responses.add(responses.GET, 'http://localhost:4567/stashes/silence/all/ma_check', json={}, status=200) trigger_payload = { 'client': { 'name': 'ma_client' }, 'check': { 'name': 'ma_check' }, 'id': 'foo-check-id' } with self.assertRaises(SystemExit) as cm: sensu_handler._post_event_to_st2(json.dumps(trigger_payload)) self.assertEqual(cm.exception.code, 0)
def test_post_event_to_st2_bad_payload(self): sensu_handler.ST2_API_BASE_URL = 'https://localhost/api/v1/' responses.add( responses.POST, 'https://localhost/api/v1/webhooks/st2', json={}, status=202 ) payload = {'foo': 'bar'} with self.assertRaises(SystemExit) as cm: sensu_handler._post_event_to_st2(payload) self.assertTrue(cm.exception.code > 0)
def test_post_event_to_st2_bad_payload(self): sensu_handler.ST2_API_BASE_URL = 'https://localhost/api/v1/' responses.add(responses.POST, 'https://localhost/api/v1/webhooks/st2', json={}, status=202) payload = {'foo': 'bar'} with self.assertRaises(SystemExit) as cm: sensu_handler._post_event_to_st2(payload) self.assertTrue(cm.exception.code > 0)
def test_post_event_to_st2_good_payload(self): sensu_handler.ST2_API_BASE_URL = 'https://localhost/api/v1/' responses.add( responses.POST, 'https://localhost/api/v1/webhooks/st2', json={}, status=202 ) responses.add( responses.GET, 'http://localhost:4567/stashes/silence/ma_client', json={}, status=404 ) responses.add( responses.GET, 'http://localhost:4567/stashes/silence/ma_client/ma_check', json={}, status=404 ) responses.add( responses.GET, 'http://localhost:4567/stashes/silence/all/ma_check', json={}, status=404 ) trigger_payload = { 'client': {'name': 'ma_client'}, 'check': {'name': 'ma_check'}, 'id': 'foo-check-id' } ret = sensu_handler._post_event_to_st2(json.dumps(trigger_payload)) self.assertEqual(ret, True)
def test_post_event_to_st2_good_payload(self): sensu_handler.ST2_API_BASE_URL = 'https://localhost/api/v1/' responses.add(responses.POST, 'https://localhost/api/v1/webhooks/st2', json={}, status=202) responses.add(responses.GET, 'http://localhost:4567/stashes/silence/ma_client', json={}, status=404) responses.add( responses.GET, 'http://localhost:4567/stashes/silence/ma_client/ma_check', json={}, status=404) responses.add(responses.GET, 'http://localhost:4567/stashes/silence/all/ma_check', json={}, status=404) trigger_payload = { 'client': { 'name': 'ma_client' }, 'check': { 'name': 'ma_check' }, 'id': 'foo-check-id' } ret = sensu_handler._post_event_to_st2(json.dumps(trigger_payload)) self.assertEqual(ret, True)