Exemple #1
0
 def test_create_event_with_default_routing_key(self, mock_event_create):
     hook = PagerdutyHook(pagerduty_conn_id=DEFAULT_CONN_ID)
     mock_event_create.return_value = {
         "status": "success",
         "message": "Event processed",
         "dedup_key": "samplekeyhere",
     }
     resp = hook.create_event(
         summary="test",
         source="airflow_test",
         severity="error",
         custom_details='{"foo": "bar"}',
     )
     self.assertEqual(resp["status"], "success")
     mock_event_create.assert_called_once_with(api_key="pagerduty_token",
                                               data={
                                                   "routing_key": "route",
                                                   "event_action":
                                                   "trigger",
                                                   "payload": {
                                                       "severity":
                                                       "error",
                                                       "source":
                                                       "airflow_test",
                                                       "summary":
                                                       "test",
                                                       "custom_details":
                                                       '{"foo": "bar"}',
                                                   },
                                               })
 def test_create_event(self, m):
     hook = PagerdutyHook(pagerduty_conn_id=DEFAULT_CONN_ID)
     mock_response_body = {
         "status": "success",
         "message": "Event processed",
         "dedup_key": "samplekeyhere",
     }
     m.post('https://events.pagerduty.com/v2/enqueue',
            json=mock_response_body)
     resp = hook.create_event(
         routing_key="different_key",
         summary="test",
         source="airflow_test",
         severity="error",
     )
     self.assertEqual(resp, mock_response_body)