Taragolis commented on issue #39352:
URL: https://github.com/apache/airflow/issues/39352#issuecomment-2089858838
I guess this one just required to mock `yandexcloud.SDK.client`, this one
change seems work well (but need to double check)
```diff
diff --git a/tests/providers/yandex/hooks/test_yq.py
b/tests/providers/yandex/hooks/test_yq.py
index c378c65347..2864642c0e 100644
--- a/tests/providers/yandex/hooks/test_yq.py
+++ b/tests/providers/yandex/hooks/test_yq.py
@@ -31,12 +31,7 @@ IAM_TOKEN = "my_iam_token"
SERVICE_ACCOUNT_AUTH_KEY_JSON = """{"id":"my_id",
"service_account_id":"my_sa1", "private_key":"my_pk"}"""
-class DummySDK:
- def __init__(self) -> None:
- self.client = None
-
-
-class DummyTokenRequester:
+class FakeTokenRequester:
def get_token(self) -> str:
return IAM_TOKEN
@@ -44,15 +39,12 @@ class DummyTokenRequester:
return "my_dummy_request"
-class DummyCreateTokenResponse:
- iam_token = "zzz"
-
-
class TestYandexCloudYqHook:
def _init_hook(self):
with mock.patch("airflow.hooks.base.BaseHook.get_connection") as
mock_get_connection:
mock_get_connection.return_value = self.connection
- self.hook = YQHook(default_folder_id="my_folder_id")
+ with
mock.patch("airflow.providers.yandex.hooks.yq.yandexcloud.SDK.client"):
+ self.hook = YQHook(default_folder_id="my_folder_id")
def setup_method(self):
self.connection = Connection(extra={"service_account_json":
SERVICE_ACCOUNT_AUTH_KEY_JSON})
@@ -82,7 +74,7 @@ class TestYandexCloudYqHook:
m.assert_called_once_with("query1")
@responses.activate()
- @mock.patch("yandexcloud._auth_fabric.get_auth_token_requester",
return_value=DummyTokenRequester())
+ @mock.patch("yandexcloud._auth_fabric.get_auth_token_requester",
return_value=FakeTokenRequester())
def test_metadata_token_usage(self, mock_get_auth_token_requester):
responses.post(
"https://api.yandex-query.cloud.yandex.net/api/fq/v1/queries",
@@ -101,14 +93,9 @@ class TestYandexCloudYqHook:
query_id = self.hook.create_query(query_text="select 777", name="my
query")
assert query_id == "query1"
- @mock.patch(
-
"yandex.cloud.iam.v1.iam_token_service_pb2_grpc.IamTokenServiceStub.Create",
- create=True,
- new_callable=mock.PropertyMock,
- )
@mock.patch("yandexcloud._auth_fabric.__validate_service_account_key")
- @mock.patch("yandexcloud._auth_fabric.get_auth_token_requester",
return_value=DummyTokenRequester())
- def test_select_results(self, mock_get_auth_token_requester,
mock_validate, mock_create_token):
+ @mock.patch("yandexcloud._auth_fabric.get_auth_token_requester",
return_value=FakeTokenRequester())
+ def test_select_results(self, mock_get_auth_token_requester,
mock_validate):
with mock.patch.multiple(
"yandex_query_client.YQHttpClient",
create_query=mock.DEFAULT,
@@ -120,7 +107,6 @@ class TestYandexCloudYqHook:
) as mocks:
self._init_hook()
mock_validate.assert_called()
- mock_create_token.assert_called()
mock_get_auth_token_requester.assert_called_once_with(
service_account_key=json.loads(SERVICE_ACCOUNT_AUTH_KEY_JSON)
)
```
cc: @dondaum @uzhastik @Piatachock
--
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]