olegkachur-e commented on code in PR #60394:
URL: https://github.com/apache/airflow/pull/60394#discussion_r2686367899


##########
providers/google/src/airflow/providers/google/cloud/hooks/cloud_run.py:
##########
@@ -67,16 +67,21 @@ class CloudRunHook(GoogleBaseHook):
         If set as a sequence, the identities from the list must grant
         Service Account Token Creator IAM role to the directly preceding 
identity, with first
         account from the list granting this role to the originating account.
+    :param transport: Optional. The transport to use for API requests. Can be 
'rest' or 'grpc'.

Review Comment:
   In the docs it is referenced as: 
   
   > "Optional[Union[str,JobsTransport,Callable[..., JobsTransport]]]
   > The transport to use, or a Callable that constructs and returns a new 
transport. If a Callable is given, it will be called with the same set of 
initialization arguments as used in the JobsTransport constructor. If set to 
None, a transport is chosen automatically.
   
   I think it makes sense to replicate similar hook behavior, at least to some 
extent, like `transport: Literal['rest', 'grpc'] | None = None)` 



##########
providers/google/tests/unit/google/cloud/hooks/test_cloud_run.py:
##########
@@ -259,6 +259,36 @@ def test_delete_job(self, mock_batch_service_client, 
cloud_run_hook):
         cloud_run_hook.delete_job(job_name=JOB_NAME, region=REGION, 
project_id=PROJECT_ID)
         
cloud_run_hook._client.delete_job.assert_called_once_with(delete_request)
 
+    @mock.patch(
+        
"airflow.providers.google.common.hooks.base_google.GoogleBaseHook.__init__",
+        new=mock_base_gcp_hook_default_project_id,
+    )
+    @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsClient")
+    def test_get_conn_with_transport(self, mock_jobs_client):
+        """Test that transport parameter is passed to JobsClient."""
+        hook = CloudRunHook(transport="rest")
+        hook.get_credentials = self.dummy_get_credentials
+        hook.get_conn()
+
+        mock_jobs_client.assert_called_once()
+        call_kwargs = mock_jobs_client.call_args[1]
+        assert call_kwargs["transport"] == "rest"
+
+    @mock.patch(
+        
"airflow.providers.google.common.hooks.base_google.GoogleBaseHook.__init__",
+        new=mock_base_gcp_hook_default_project_id,
+    )
+    @mock.patch("airflow.providers.google.cloud.hooks.cloud_run.JobsClient")
+    def test_get_conn_without_transport(self, mock_jobs_client):
+        """Test that JobsClient is created with default 'grpc' transport when 
not specified."""
+        hook = CloudRunHook()
+        hook.get_credentials = self.dummy_get_credentials
+        hook.get_conn()
+
+        mock_jobs_client.assert_called_once()
+        call_kwargs = mock_jobs_client.call_args[1]
+        assert call_kwargs["transport"] == "grpc"

Review Comment:
   Both `test_get_conn_with_transport` and `test_get_conn_without_transport` 
looks pretty similar, is there a chance to combine them with 
`@pytest.mark.parametrize` ? 



-- 
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]

Reply via email to