Merge "download_object/get_object must have the same API"

This commit is contained in:
Jenkins 2016-01-25 16:31:36 +00:00 committed by Gerrit Code Review
commit 3b727151bc
2 changed files with 13 additions and 7 deletions

View File

@ -142,9 +142,9 @@ class Proxy(proxy.BaseProxy):
def get_object(self, object, container=None):
"""Get the data associated with an object
:param object: The value can be the ID of an object or a
:param object: The value can be the name of an object or a
:class:`~openstack.object_store.v1.obj.Object` instance.
:param container: The value can be the ID of a container or a
:param container: The value can be the name of a container or a
:class:`~openstack.object_store.v1.container.Container`
instance.
@ -159,15 +159,21 @@ class Proxy(proxy.BaseProxy):
return self._get(_obj.Object, object,
path_args={"container": container_name})
def download_object(self, object, path):
def download_object(self, object, container=None, path=None):
"""Download the data contained inside an object to disk.
:param object: The object to save to disk.
:type object: :class:`~openstack.object_store.v1.obj.Object`
:param object: The value can be the name of an object or a
:class:`~openstack.object_store.v1.obj.Object` instance.
:param container: The value can be the name of a container or a
:class:`~openstack.object_store.v1.container.Container`
instance.
:param path str: Location to write the object contents.
:raises: :class:`~openstack.exceptions.ResourceNotFound`
when no resource can be found.
"""
with open(path, "w") as out:
out.write(self.get_object(object))
out.write(self.get_object(object, container))
def upload_object(self, **attrs):
"""Upload a new object from attributes

View File

@ -264,7 +264,7 @@ class Test_download_object(TestObjectStoreProxy):
file_path = "blarga/somefile"
with mock.patch("openstack.object_store.v1._proxy.open",
fake_open, create=True):
self.proxy.download_object(ob, file_path)
self.proxy.download_object(ob, container="tainer", path=file_path)
fake_open.assert_called_once_with(file_path, "w")
fake_handle = fake_open()