def test_response_in_logs(self):
        """
        Test that when using SimpleHttpOperator with 'GET' on localhost:8080,
        the log contains 'Google' in it
        """
        operator = SimpleHttpOperator(
            task_id='test_HTTP_op',
            method='GET',
            endpoint='/',
            http_conn_id='HTTP_GOOGLE',
            log_response=True,
        )

        with patch.object(operator.log, 'info') as mock_info:
            operator.execute(None)
            mock_info.assert_called_with(AnyStringWith('Google'))
Esempio n. 2
0
    def test_response_in_logs(self, m):
        """
        Test that when using SimpleHttpOperator with 'GET',
        the log contains 'Example Domain' in it
        """

        m.get('http://www.example.com', text='Example.com fake response')
        operator = SimpleHttpOperator(
            task_id='test_HTTP_op',
            method='GET',
            endpoint='/',
            http_conn_id='HTTP_EXAMPLE',
            log_response=True,
        )

        with mock.patch.object(operator.log, 'info') as mock_info:
            operator.execute(None)
            mock_info.assert_called_with('Example.com fake response')
Esempio n. 3
0
def on_failure_callback(context):
    """
    Define the callback to post on Slack if a failure is detected in the Workflow
    :return: operator.execute
    """
    operator = SimpleHttpOperator(
        task_id='weixin_http',
        http_conn_id='http_weixin',
        method='POST',
        endpoint='',
        data=json.dumps(
            {"content": "Airflow af_adt_advertiser_revenue_report_ag exec error!", "app": "BigdataMonitor"}),
        # data=json.dumps({"content": "Airflow exec successfull!","app":"HostMonitoring","username":"******"}),
        headers={"Content-Type": "application/json"},
    )
    return operator.execute(context=context)