You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by tu...@apache.org on 2020/07/24 12:40:36 UTC
[airflow] branch master updated: Add get_blobs_list method to
WasbHook (#9950)
This is an automated email from the ASF dual-hosted git repository.
turbaszek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/master by this push:
new 0bf330b Add get_blobs_list method to WasbHook (#9950)
0bf330b is described below
commit 0bf330ba8681c417fd5a10b3ba01c75600dc5f2e
Author: jayrumi <jr...@gmail.com>
AuthorDate: Fri Jul 24 15:39:23 2020 +0300
Add get_blobs_list method to WasbHook (#9950)
---
airflow/providers/microsoft/azure/hooks/wasb.py | 17 +++++++++++++++++
tests/providers/microsoft/azure/hooks/test_wasb.py | 10 ++++++++++
2 files changed, 27 insertions(+)
diff --git a/airflow/providers/microsoft/azure/hooks/wasb.py b/airflow/providers/microsoft/azure/hooks/wasb.py
index 32f9b57..3c91cf3 100644
--- a/airflow/providers/microsoft/azure/hooks/wasb.py
+++ b/airflow/providers/microsoft/azure/hooks/wasb.py
@@ -88,6 +88,23 @@ class WasbHook(BaseHook):
num_results=1, **kwargs)
return len(list(matches)) > 0
+ def get_blobs_list(self, container_name: str, prefix: str, **kwargs):
+ """
+ Return a list of blobs from path defined in prefix param
+
+ :param container_name: Name of the container.
+ :type container_name: str
+ :param prefix: Prefix of the blob.
+ :type prefix: str
+ :param kwargs: Optional keyword arguments that
+ `BlockBlobService.list_blobs()` takes (num_results, include,
+ delimiter, marker, timeout)
+ :type kwargs: object
+ :return: List of blobs.
+ :rtype: list(azure.storage.common.models.ListGenerator)
+ """
+ return self.connection.list_blobs(container_name, prefix, **kwargs)
+
def load_file(self, file_path, container_name, blob_name, **kwargs):
"""
Upload a file to Azure Blob Storage.
diff --git a/tests/providers/microsoft/azure/hooks/test_wasb.py b/tests/providers/microsoft/azure/hooks/test_wasb.py
index 46fe8e5..87b1c44 100644
--- a/tests/providers/microsoft/azure/hooks/test_wasb.py
+++ b/tests/providers/microsoft/azure/hooks/test_wasb.py
@@ -188,3 +188,13 @@ class TestWasbHook(unittest.TestCase):
is_prefix=True, ignore_if_missing=False
)
self.assertIsInstance(context.exception, AirflowException)
+
+ @mock.patch('airflow.providers.microsoft.azure.hooks.wasb.BlockBlobService',
+ autospec=True)
+ def test_get_blobs_list(self, mock_service):
+ mock_instance = mock_service.return_value
+ hook = WasbHook(wasb_conn_id='wasb_test_sas_token')
+ hook.get_blobs_list('container', 'prefix', num_results=1, timeout=3)
+ mock_instance.list_blobs.assert_called_once_with(
+ 'container', 'prefix', num_results=1, timeout=3
+ )