summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/leap/soledad/server/_blobs.py13
-rw-r--r--src/leap/soledad/server/interfaces.py4
-rw-r--r--tests/blobs/test_fs_backend.py6
3 files changed, 16 insertions, 7 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py
index 42c00841..7210cb6a 100644
--- a/src/leap/soledad/server/_blobs.py
+++ b/src/leap/soledad/server/_blobs.py
@@ -184,7 +184,7 @@ class FilesystemBlobsBackend(object):
blob_ids = list(self._filter_flag(blob_ids, filter_flag))
blob_ids = [os.path.basename(path).replace('.deleted', '')
for path in blob_ids]
- return blob_ids
+ return defer.succeed(blob_ids)
def _filter_flag(self, blob_paths, flag):
for blob_path in blob_paths:
@@ -288,10 +288,13 @@ class BlobsResource(resource.Resource):
order = request.args.get('order_by', [None])[0]
filter_flag = request.args.get('filter_flag', [False])[0]
deleted = request.args.get('deleted', [False])[0]
- blobs = self._handler.list_blobs(user, namespace,
- order_by=order, deleted=deleted,
- filter_flag=filter_flag)
- return json.dumps(blobs)
+ d = self._handler.list_blobs(user, namespace,
+ order_by=order, deleted=deleted,
+ filter_flag=filter_flag)
+ d.addCallback(lambda blobs: json.dumps(blobs))
+ d.addCallback(lambda blobs: request.write(blobs))
+ d.addCallback(lambda _: request.finish())
+ return NOT_DONE_YET
only_flags = request.args.get('only_flags', [False])[0]
try:
if only_flags:
diff --git a/src/leap/soledad/server/interfaces.py b/src/leap/soledad/server/interfaces.py
index a1762647..7009cb85 100644
--- a/src/leap/soledad/server/interfaces.py
+++ b/src/leap/soledad/server/interfaces.py
@@ -127,6 +127,10 @@ class IBlobsBackend(Interface):
:return: A list of blob ids, optionally ordered and/or restricted by
namespace.
:rtype: list of str
+
+ :return: A deferred that fires with a list of blob ids, optionally
+ ordered and/or restricted by namespace.
+ :rtype: twisted.internet.defer.Deferred
"""
def get_total_storage(user):
diff --git a/tests/blobs/test_fs_backend.py b/tests/blobs/test_fs_backend.py
index e77e56b0..727ffe92 100644
--- a/tests/blobs/test_fs_backend.py
+++ b/tests/blobs/test_fs_backend.py
@@ -127,20 +127,22 @@ class FilesystemBackendTestCase(unittest.TestCase):
@pytest.mark.usefixtures("method_tmpdir")
@mock.patch('leap.soledad.server._blobs.os.walk')
+ @defer.inlineCallbacks
def test_list_blobs(self, walk_mock):
backend = _blobs.FilesystemBlobsBackend(blobs_path=self.tempdir)
_ = None
walk_mock.return_value = [('', _, ['blob_0']), ('', _, ['blob_1'])]
- result = backend.list_blobs('user')
+ result = yield backend.list_blobs('user')
self.assertEquals(result, ['blob_0', 'blob_1'])
@pytest.mark.usefixtures("method_tmpdir")
@mock.patch('leap.soledad.server._blobs.os.walk')
+ @defer.inlineCallbacks
def test_list_blobs_limited_by_namespace(self, walk_mock):
backend = _blobs.FilesystemBlobsBackend(self.tempdir)
_ = None
walk_mock.return_value = [('', _, ['blob_0']), ('', _, ['blob_1'])]
- result = backend.list_blobs('user', namespace='incoming')
+ result = yield backend.list_blobs('user', namespace='incoming')
self.assertEquals(result, ['blob_0', 'blob_1'])
target_dir = os.path.join(self.tempdir, 'user', 'incoming')
walk_mock.assert_called_once_with(target_dir)