libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [libcloud] branch trunk updated: Adds missing docs for param ``ex_prefix`` within list_container_objects method.
Date Sun, 27 Jan 2019 21:08:35 GMT
This is an automated email from the ASF dual-hosted git repository.

anthonyshaw pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 09af52a  Adds missing docs for param ``ex_prefix`` within list_container_objects
method.
     new 469bda9  Merge pull request #1275 from richardARPANET/corrects-list-container-objects-docs
09af52a is described below

commit 09af52a3918258606b5696e6fbe6add2fc072e3c
Author: Richard O'Dwyer <richard@richard.do>
AuthorDate: Tue Jan 8 15:01:50 2019 +0100

    Adds missing docs for param ``ex_prefix`` within list_container_objects method.
    
    Also adds ex_prefix functionality to the DummyStore, since all other stores have this
feature.
---
 libcloud/storage/base.py            |  5 ++++-
 libcloud/storage/drivers/dummy.py   |  7 ++++--
 libcloud/test/storage/test_dummy.py | 45 +++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/libcloud/storage/base.py b/libcloud/storage/base.py
index 052725b..85a132d 100644
--- a/libcloud/storage/base.py
+++ b/libcloud/storage/base.py
@@ -221,13 +221,16 @@ class StorageDriver(BaseDriver):
         raise NotImplementedError(
             'iterate_container_objects not implemented for this driver')
 
-    def list_container_objects(self, container):
+    def list_container_objects(self, container, ex_prefix=None):
         """
         Return a list of objects for the given container.
 
         :param container: Container instance.
         :type container: :class:`Container`
 
+        :param ex_prefix: Filter objects starting with a prefix.
+        :type  ex_prefix: ``str``
+
         :return: A list of Object instances.
         :rtype: ``list`` of :class:`Object`
         """
diff --git a/libcloud/storage/drivers/dummy.py b/libcloud/storage/drivers/dummy.py
index 1200e51..6b5c3c3 100644
--- a/libcloud/storage/drivers/dummy.py
+++ b/libcloud/storage/drivers/dummy.py
@@ -178,10 +178,13 @@ class DummyStorageDriver(StorageDriver):
         for container in list(self._containers.values()):
             yield container['container']
 
-    def list_container_objects(self, container):
+    def list_container_objects(self, container, ex_prefix=None):
         container = self.get_container(container.name)
 
-        return container.objects
+        objects = list(self._containers[container.name]['objects'].values())
+        if ex_prefix is not None:
+            objects = [o for o in objects if o.name.startswith(ex_prefix)]
+        return objects
 
     def get_container(self, container_name):
         """
diff --git a/libcloud/test/storage/test_dummy.py b/libcloud/test/storage/test_dummy.py
new file mode 100644
index 0000000..b627cfa
--- /dev/null
+++ b/libcloud/test/storage/test_dummy.py
@@ -0,0 +1,45 @@
+import pytest
+
+from libcloud.storage.drivers.dummy import DummyStorageDriver
+
+
+@pytest.fixture
+def driver():
+    return DummyStorageDriver('key', 'id')
+
+
+@pytest.fixture
+def container_with_contents(driver):
+    container_name = 'test'
+    object_name = 'test.dat'
+    container = driver.create_container(container_name=container_name)
+    driver.upload_object(
+        __file__, container=container, object_name=object_name
+    )
+    return container_name, object_name
+
+
+def test_list_container_objects(driver, container_with_contents):
+    container_name, object_name = container_with_contents
+    container = driver.get_container(container_name)
+
+    objects = driver.list_container_objects(container=container)
+
+    assert any(o for o in objects if o.name == object_name)
+
+
+def test_list_container_objects_filter_by_prefix(
+    driver, container_with_contents
+):
+    container_name, object_name = container_with_contents
+    container = driver.get_container(container_name)
+
+    objects = driver.list_container_objects(
+        container=container, ex_prefix=object_name[:3]
+    )
+    assert any(o for o in objects if o.name == object_name)
+
+    objects = driver.list_container_objects(
+        container=container, ex_prefix='does-not-exist.dat'
+    )
+    assert not objects


Mime
View raw message