From 601eb94cabe9d7003bdda012338bf0a3edfd46cb Mon Sep 17 00:00:00 2001 From: drebs Date: Fri, 8 Dec 2017 21:55:45 -0200 Subject: [refactor] make get_blob_size() return a deferred --- src/leap/soledad/server/_blobs.py | 3 ++- src/leap/soledad/server/interfaces.py | 4 ++-- tests/blobs/test_fs_backend.py | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py index f9166ce0..21becbf3 100644 --- a/src/leap/soledad/server/_blobs.py +++ b/src/leap/soledad/server/_blobs.py @@ -151,7 +151,8 @@ class FilesystemBlobsBackend(object): def get_blob_size(self, user, blob_id, namespace=''): blob_path = self._get_path(user, blob_id, namespace) - return os.stat(blob_path).st_size + size = os.stat(blob_path).st_size + return defer.succeed(size) def count(self, user, namespace=''): base_path = self._get_path(user, namespace=namespace) diff --git a/src/leap/soledad/server/interfaces.py b/src/leap/soledad/server/interfaces.py index f9257c9b..a7caf917 100644 --- a/src/leap/soledad/server/interfaces.py +++ b/src/leap/soledad/server/interfaces.py @@ -85,8 +85,8 @@ class IBlobsBackend(Interface): :param namespace: An optional namespace for the blob. :type namespace: str - :return: The size of the blob. - :rtype: int + :return: A deferred that fires with the size of the blob. + :rtype: twisted.internet.defer.Deferred """ def count(user, namespace=''): diff --git a/tests/blobs/test_fs_backend.py b/tests/blobs/test_fs_backend.py index 59b7976f..69526cbf 100644 --- a/tests/blobs/test_fs_backend.py +++ b/tests/blobs/test_fs_backend.py @@ -45,6 +45,7 @@ class FilesystemBackendTestCase(unittest.TestCase): self.assertEquals(expected_tag, tag) @pytest.mark.usefixtures("method_tmpdir") + @defer.inlineCallbacks def test_get_blob_size(self): # get a backend backend = _blobs.FilesystemBlobsBackend(blobs_path=self.tempdir) @@ -54,7 +55,7 @@ class FilesystemBackendTestCase(unittest.TestCase): with open(path, "w") as f: f.write("0123456789") # check it's size - size = backend.get_blob_size('user', 'blob_id', '') + size = yield backend.get_blob_size('user', 'blob_id', '') self.assertEquals(10, size) @pytest.mark.usefixtures("method_tmpdir") -- cgit v1.2.3