This is an automated email from the ASF dual-hosted git repository.

pankaj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 198b149d08 azurefilesharehook fix with connection type azure (#36309)
198b149d08 is described below

commit 198b149d082441ebdfd2a697088d73c0addb4703
Author: Abhishek <[email protected]>
AuthorDate: Tue Dec 19 22:20:04 2023 +0530

    azurefilesharehook fix with connection type azure (#36309)
---
 .../providers/microsoft/azure/hooks/fileshare.py   |  2 ++
 .../microsoft/azure/hooks/test_fileshare.py        | 37 +++++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/airflow/providers/microsoft/azure/hooks/fileshare.py 
b/airflow/providers/microsoft/azure/hooks/fileshare.py
index e9a2b21873..a051dbadad 100644
--- a/airflow/providers/microsoft/azure/hooks/fileshare.py
+++ b/airflow/providers/microsoft/azure/hooks/fileshare.py
@@ -135,6 +135,7 @@ class AzureFileShareHook(BaseHook):
 
     @property
     def share_directory_client(self):
+        self.get_conn()
         if self._connection_string:
             return ShareDirectoryClient.from_connection_string(
                 conn_str=self._connection_string,
@@ -160,6 +161,7 @@ class AzureFileShareHook(BaseHook):
 
     @property
     def share_file_client(self):
+        self.get_conn()
         if self._connection_string:
             return ShareFileClient.from_connection_string(
                 conn_str=self._connection_string,
diff --git a/tests/providers/microsoft/azure/hooks/test_fileshare.py 
b/tests/providers/microsoft/azure/hooks/test_fileshare.py
index 7ef5262e3e..be80f145d2 100644
--- a/tests/providers/microsoft/azure/hooks/test_fileshare.py
+++ b/tests/providers/microsoft/azure/hooks/test_fileshare.py
@@ -21,7 +21,13 @@ from io import StringIO
 from unittest import mock
 
 import pytest
-from azure.storage.fileshare import DirectoryProperties, FileProperties, 
ShareServiceClient
+from azure.storage.fileshare import (
+    DirectoryProperties,
+    FileProperties,
+    ShareDirectoryClient,
+    ShareFileClient,
+    ShareServiceClient,
+)
 
 from airflow.models import Connection
 from airflow.providers.microsoft.azure.hooks.fileshare import 
AzureFileShareHook
@@ -57,6 +63,13 @@ class TestAzureFileshareHook:
                 login="login",
                 extra={"wrong_key": "token"},
             ),
+            Connection(
+                conn_id="azure_default",
+                conn_type="azure",
+                login="app_id",
+                password="secret",
+                extra={"tenantId": "t_id", "subscriptionId": "s_id"},
+            ),
         )
 
     def test_key_and_connection(self):
@@ -65,6 +78,28 @@ class TestAzureFileshareHook:
         share_client = hook.share_service_client
         assert isinstance(share_client, ShareServiceClient)
 
+    def test_azure_default_share_service_client(self):
+        hook = AzureFileShareHook(azure_fileshare_conn_id="azure_default")
+        assert hook._conn_id == "azure_default"
+        share_client = hook.share_service_client
+        assert isinstance(share_client, ShareServiceClient)
+
+    def test_azure_default_share_directory_client(self):
+        hook = AzureFileShareHook(
+            azure_fileshare_conn_id="azure_default", share_name="share", 
directory_path="directory"
+        )
+        assert hook._conn_id == "azure_default"
+        share_client = hook.share_directory_client
+        assert isinstance(share_client, ShareDirectoryClient)
+
+    def test_azure_default_share_file_client(self):
+        hook = AzureFileShareHook(
+            azure_fileshare_conn_id="azure_default", share_name="share", 
file_path="file"
+        )
+        assert hook._conn_id == "azure_default"
+        share_client = hook.share_file_client
+        assert isinstance(share_client, ShareFileClient)
+
     def test_sas_token(self):
         hook = 
AzureFileShareHook(azure_fileshare_conn_id="azure_fileshare_extras")
         assert hook._conn_id == "azure_fileshare_extras"

Reply via email to