[refactor] make blobs backend list_blobs() agnostic of twisted.web requests
authordrebs <drebs@leap.se>
Wed, 6 Dec 2017 21:24:39 +0000 (19:24 -0200)
committerdrebs <drebs@leap.se>
Wed, 13 Dec 2017 15:43:47 +0000 (13:43 -0200)
src/leap/soledad/server/_blobs.py
src/leap/soledad/server/interfaces.py
tests/blobs/test_fs_backend.py

index 89c5927..2ba3fe9 100644 (file)
@@ -157,8 +157,8 @@ class FilesystemBlobsBackend(object):
             count += len(filter(lambda i: not i.endswith('.flags'), filenames))
         return json.dumps({"count": count})
 
-    def list_blobs(self, user, request, namespace='', order_by=None,
-                   deleted=False, filter_flag=False):
+    def list_blobs(self, user, namespace='', order_by=None, deleted=False,
+                   filter_flag=False):
         namespace = namespace or 'default'
         blob_ids = []
         base_path = self._get_path(user, namespace=namespace)
@@ -180,7 +180,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 json.dumps(blob_ids)
+        return blob_ids
 
     def _filter_flag(self, blob_paths, flag):
         for blob_path in blob_paths:
@@ -280,9 +280,10 @@ 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]
-            return self._handler.list_blobs(user, request, namespace,
-                                            order_by=order, deleted=deleted,
-                                            filter_flag=filter_flag)
+            blobs = self._handler.list_blobs(user, namespace,
+                                             order_by=order, deleted=deleted,
+                                             filter_flag=filter_flag)
+            return json.dumps(blobs)
         only_flags = request.args.get('only_flags', [False])[0]
         try:
             if only_flags:
index f9cc96c..430cdec 100644 (file)
@@ -112,7 +112,7 @@ class IBlobsBackend(Interface):
         :rtype: int
         """
 
-    def list_blobs(user, request, namespace='', order_by=None, deleted=False,
+    def list_blobs(user, namespace='', order_by=None, deleted=False,
                    filter_flag=None):
         """
         List the blobs stored in the backend.
@@ -122,12 +122,8 @@ class IBlobsBackend(Interface):
 
         :param user: The id of the user who owns the blob.
         :type user: str
-        :param request: A representation of all of the information about the
-            request that is being made.
-        :type request: twisted.web.server.Request
         :param namespace: Restrict the count to a certain namespace.
         :type namespace: str
-
         :param order_by: 'date' (equivalent to '+date') or  '-date', to sort
             ascending or descending by date, respectivelly.
         :type order_by: str
@@ -137,9 +133,9 @@ class IBlobsBackend(Interface):
             be returned.
         :type filter_flag: str
 
-        :return: A JSON list of blob ids, optionally ordered and/or restricted
-                 by namespace.
-        :rtype: str
+        :return: A list of blob ids, optionally ordered and/or restricted by
+                 namespace.
+        :rtype: list of str
         """
 
     def get_total_storage(user):
index eada044..5df658f 100644 (file)
@@ -26,7 +26,6 @@ from mock import Mock
 import mock
 import os
 import base64
-import json
 import pytest
 
 
@@ -131,7 +130,7 @@ class FilesystemBackendTestCase(unittest.TestCase):
         backend = _blobs.FilesystemBlobsBackend(blobs_path=self.tempdir)
         _ = None
         walk_mock.return_value = [('', _, ['blob_0']), ('', _, ['blob_1'])]
-        result = json.loads(backend.list_blobs('user', DummyRequest([''])))
+        result = backend.list_blobs('user')
         self.assertEquals(result, ['blob_0', 'blob_1'])
 
     @pytest.mark.usefixtures("method_tmpdir")
@@ -140,8 +139,7 @@ class FilesystemBackendTestCase(unittest.TestCase):
         backend = _blobs.FilesystemBlobsBackend(self.tempdir)
         _ = None
         walk_mock.return_value = [('', _, ['blob_0']), ('', _, ['blob_1'])]
-        result = json.loads(backend.list_blobs('user', DummyRequest(['']),
-                                               namespace='incoming'))
+        result = 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)