aritra24 commented on code in PR #36733:
URL: https://github.com/apache/airflow/pull/36733#discussion_r1449112481
##########
tests/providers/http/hooks/test_http.py:
##########
@@ -525,3 +588,111 @@ async def test_async_request_uses_connection_extra(self,
aioresponse):
assert all(
key in headers and headers[key] == value for key, value in
connection_extra.items()
)
+
+ @pytest.mark.asyncio
+ async def
test_async_request_uses_connection_extra_with_requests_parameters(self):
+ """Test api call asynchronously with a connection that has extra
field."""
+ connection_extra = {"bearer": "test"}
+ proxy = {"http": "http://proxy:80", "https": "https://proxy:80"}
+ airflow_connection = get_airflow_connection_with_extra(
+ extra={
+ **connection_extra,
+ **{
+ "proxies": proxy,
+ "timeout": 60,
+ "verify": False,
+ "allow_redirects": False,
+ "max_redirects": 3,
+ },
+ }
+ )
+
+ with mock.patch("airflow.hooks.base.BaseHook.get_connection",
side_effect=airflow_connection):
+ hook = HttpAsyncHook()
+ with mock.patch("aiohttp.ClientSession.post",
new_callable=mock.AsyncMock) as mocked_function:
+ await hook.run("v1/test")
+ headers = mocked_function.call_args.kwargs.get("headers")
+ assert all(
+ key in headers and headers[key] == value for key, value in
connection_extra.items()
+ )
+ assert mocked_function.call_args.kwargs.get("proxy") == proxy
+ assert mocked_function.call_args.kwargs.get("timeout") == 60
+ assert mocked_function.call_args.kwargs.get("verify_ssl") is
False
+ assert mocked_function.call_args.kwargs.get("allow_redirects")
is False
+ assert mocked_function.call_args.kwargs.get("max_redirects")
== 3
+
+ def
test_process_extra_options_from_connection_when_stream_is_defined_just_ignore_it(self):
+ extra_options = {}
+ conn = get_airflow_connection_with_extra(extra={"bearer": "test",
"stream": True})()
+
+ actual =
HttpAsyncHook._process_extra_options_from_connection(conn=conn,
extra_options=extra_options)
+
+ assert extra_options == {}
+ assert actual == {"bearer": "test"}
+
+ def
test_process_extra_options_from_connection_when_cert_is_defined_just_ignore_it(self):
+ extra_options = {}
+ conn = get_airflow_connection_with_extra(extra={"bearer": "test",
"cert": "cert.crt"})()
+
+ actual =
HttpAsyncHook._process_extra_options_from_connection(conn=conn,
extra_options=extra_options)
+
+ assert extra_options == {}
+ assert actual == {"bearer": "test"}
+
+ def
test_process_extra_options_from_connection_when_proxies_is_defined(self):
+ extra_options = {}
+ conn = get_airflow_connection_with_extra(
+ extra={"bearer": "test", "proxies": {"http": "http://proxy:80",
"https": "https://proxy:80"}}
+ )()
+
+ actual =
HttpAsyncHook._process_extra_options_from_connection(conn=conn,
extra_options=extra_options)
+
+ assert extra_options == {"proxy": {"http": "http://proxy:80", "https":
"https://proxy:80"}}
+ assert actual == {"bearer": "test"}
+
+ def test_process_extra_options_from_connection_when_proxy_is_defined(self):
+ extra_options = {}
+ conn = get_airflow_connection_with_extra(
+ extra={"bearer": "test", "proxy": {"http": "http://proxy:80",
"https": "https://proxy:80"}}
+ )()
+
+ actual =
HttpAsyncHook._process_extra_options_from_connection(conn=conn,
extra_options=extra_options)
+
+ assert extra_options == {"proxy": {"http": "http://proxy:80", "https":
"https://proxy:80"}}
+ assert actual == {"bearer": "test"}
+
+ def
test_process_extra_options_from_connection_when_verify_is_defined(self):
+ extra_options = {}
+ conn = get_airflow_connection_with_extra(extra={"bearer": "test",
"verify": False})()
+
+ actual =
HttpAsyncHook._process_extra_options_from_connection(conn=conn,
extra_options=extra_options)
+
+ assert extra_options == {"verify_ssl": False}
+ assert actual == {"bearer": "test"}
+
+ def
test_process_extra_options_from_connection_when_verify_ssl_is_defined(self):
+ extra_options = {}
+ conn = get_airflow_connection_with_extra(extra={"bearer": "test",
"verify_ssl": False})()
+
+ actual =
HttpAsyncHook._process_extra_options_from_connection(conn=conn,
extra_options=extra_options)
+
+ assert extra_options == {"verify_ssl": False}
+ assert actual == {"bearer": "test"}
+
+ def
test_process_extra_options_from_connection_when_allow_redirects_is_defined(self):
+ extra_options = {}
+ conn = get_airflow_connection_with_extra(extra={"bearer": "test",
"allow_redirects": False})()
+
+ actual =
HttpAsyncHook._process_extra_options_from_connection(conn=conn,
extra_options=extra_options)
+
+ assert extra_options == {"allow_redirects": False}
+ assert actual == {"bearer": "test"}
+
+ def
test_process_extra_options_from_connection_when_max_redirects_is_defined(self):
+ extra_options = {}
+ conn = get_airflow_connection_with_extra(extra={"bearer": "test",
"max_redirects": 3})()
+
+ actual =
HttpAsyncHook._process_extra_options_from_connection(conn=conn,
extra_options=extra_options)
+
+ assert extra_options == {"max_redirects": 3}
+ assert actual == {"bearer": "test"}
Review Comment:
This all looks like it's testing the same thing with different params, can
this perhaps just all be in one test?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]