diff options
author | drebs <drebs@leap.se> | 2017-12-08 21:55:45 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2017-12-13 13:43:48 -0200 |
commit | 601eb94cabe9d7003bdda012338bf0a3edfd46cb (patch) | |
tree | b359a18636cc79fa101d5038dd7774c434adac80 | |
parent | ad1e3a4a4863006b3415e619138c3bae88da3941 (diff) |
[refactor] make get_blob_size() return a deferred
-rw-r--r-- | src/leap/soledad/server/_blobs.py | 3 | ||||
-rw-r--r-- | src/leap/soledad/server/interfaces.py | 4 | ||||
-rw-r--r-- | 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") |