本文整理汇总了Python中airflow.hooks.http_hook.HttpHook.run_with_advanced_retry方法的典型用法代码示例。如果您正苦于以下问题:Python HttpHook.run_with_advanced_retry方法的具体用法?Python HttpHook.run_with_advanced_retry怎么用?Python HttpHook.run_with_advanced_retry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类airflow.hooks.http_hook.HttpHook
的用法示例。
在下文中一共展示了HttpHook.run_with_advanced_retry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestHttpHook
# 需要导入模块: from airflow.hooks.http_hook import HttpHook [as 别名]
# 或者: from airflow.hooks.http_hook.HttpHook import run_with_advanced_retry [as 别名]
#.........这里部分代码省略.........
side_effect=get_airflow_connection
):
with self.assertRaises(AirflowException):
self.post_hook.run('v1/test')
@requests_mock.mock()
def test_post_request_do_not_raise_for_status_if_check_response_is_false(self, m):
m.post(
'http://test:8080/v1/test',
status_code=418,
text='{"status":{"status": 418}}',
reason='I\'m a teapot'
)
with mock.patch(
'airflow.hooks.base_hook.BaseHook.get_connection',
side_effect=get_airflow_connection
):
resp = self.post_hook.run('v1/test', extra_options={'check_response': False})
self.assertEqual(resp.status_code, 418)
@mock.patch('airflow.hooks.http_hook.requests.Session')
def test_retry_on_conn_error(self, mocked_session):
retry_args = dict(
wait=tenacity.wait_none(),
stop=tenacity.stop_after_attempt(7),
retry=requests.exceptions.ConnectionError
)
def send_and_raise(request, **kwargs):
raise requests.exceptions.ConnectionError
mocked_session().send.side_effect = send_and_raise
# The job failed for some reason
with self.assertRaises(tenacity.RetryError):
self.get_hook.run_with_advanced_retry(
endpoint='v1/test',
_retry_args=retry_args
)
self.assertEqual(
self.get_hook._retry_obj.stop.max_attempt_number + 1,
mocked_session.call_count
)
def test_header_from_extra_and_run_method_are_merged(self):
def run_and_return(session, prepped_request, extra_options, **kwargs):
return prepped_request
# The job failed for some reason
with mock.patch(
'airflow.hooks.http_hook.HttpHook.run_and_check',
side_effect=run_and_return
):
with mock.patch(
'airflow.hooks.base_hook.BaseHook.get_connection',
side_effect=get_airflow_connection
):
pr = self.get_hook.run('v1/test', headers={'some_other_header': 'test'})
actual = dict(pr.headers)
self.assertEqual(actual.get('bareer'), 'test')
self.assertEqual(actual.get('some_other_header'), 'test')
@mock.patch('airflow.hooks.http_hook.HttpHook.get_connection')
def test_http_connection(self, mock_get_connection):
c = Connection(conn_id='http_default', conn_type='http',
host='localhost', schema='http')
mock_get_connection.return_value = c
hook = HttpHook()
hook.get_conn({})
self.assertEqual(hook.base_url, 'http://localhost')
@mock.patch('airflow.hooks.http_hook.HttpHook.get_connection')
def test_https_connection(self, mock_get_connection):
c = Connection(conn_id='http_default', conn_type='http',
host='localhost', schema='https')
mock_get_connection.return_value = c
hook = HttpHook()
hook.get_conn({})
self.assertEqual(hook.base_url, 'https://localhost')
@mock.patch('airflow.hooks.http_hook.HttpHook.get_connection')
def test_host_encoded_http_connection(self, mock_get_connection):
c = Connection(conn_id='http_default', conn_type='http',
host='http://localhost')
mock_get_connection.return_value = c
hook = HttpHook()
hook.get_conn({})
self.assertEqual(hook.base_url, 'http://localhost')
@mock.patch('airflow.hooks.http_hook.HttpHook.get_connection')
def test_host_encoded_https_connection(self, mock_get_connection):
c = Connection(conn_id='http_default', conn_type='http',
host='https://localhost')
mock_get_connection.return_value = c
hook = HttpHook()
hook.get_conn({})
self.assertEqual(hook.base_url, 'https://localhost')