summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/src/leap/soledad/client/_blobs.py12
-rw-r--r--testing/tests/blobs/test_local_backend.py12
-rw-r--r--testing/tests/server/test_blobs_server.py13
3 files changed, 37 insertions, 0 deletions
diff --git a/client/src/leap/soledad/client/_blobs.py b/client/src/leap/soledad/client/_blobs.py
index b7dee538..fac65383 100644
--- a/client/src/leap/soledad/client/_blobs.py
+++ b/client/src/leap/soledad/client/_blobs.py
@@ -168,6 +168,18 @@ class BlobManager(object):
return self.local.list()
@defer.inlineCallbacks
+ def send_missing(self):
+ our_blobs = yield self.local_list()
+ server_blobs = yield self.remote_list()
+ missing = [b_id for b_id in our_blobs if b_id not in server_blobs]
+ logger.info("Amount of documents missing on server: %s" % len(missing))
+ # TODO: Send concurrently when we are able to stream directly from db
+ for blob_id in missing:
+ fd = yield self.local.get(blob_id)
+ logger.info("Upload local blob: %s" % blob_id)
+ yield self._encrypt_and_upload(blob_id, fd)
+
+ @defer.inlineCallbacks
def put(self, doc, size):
fd = doc.blob_fd
# TODO this is a tee really, but ok... could do db and upload
diff --git a/testing/tests/blobs/test_local_backend.py b/testing/tests/blobs/test_local_backend.py
index 5bfece8f..297f0389 100644
--- a/testing/tests/blobs/test_local_backend.py
+++ b/testing/tests/blobs/test_local_backend.py
@@ -100,3 +100,15 @@ class BlobManagerTestCase(unittest.TestCase):
blobs_list = yield self.manager.local_list()
self.assertEquals(set(['myblob_id', 'myblob_id2']), set(blobs_list))
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_send_missing(self):
+ fd = BytesIO('test')
+ self.manager._encrypt_and_upload = Mock(return_value=None)
+ self.manager.remote_list = Mock(return_value=[])
+ self.manager.local_list = Mock(return_value=['missing_id'])
+ self.manager.local = Mock(get=Mock(return_value=fd))
+ yield self.manager.send_missing()
+
+ self.manager._encrypt_and_upload.assert_called_with('missing_id', fd)
diff --git a/testing/tests/server/test_blobs_server.py b/testing/tests/server/test_blobs_server.py
index a0306504..910cd985 100644
--- a/testing/tests/server/test_blobs_server.py
+++ b/testing/tests/server/test_blobs_server.py
@@ -70,3 +70,16 @@ class BlobServerTestCase(unittest.TestCase):
fd = BytesIO("save me")
with pytest.raises(BlobAlreadyExistsError):
yield manager._encrypt_and_upload('blob_id', fd)
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_send_missing(self):
+ manager = BlobManager(self.tempdir, self.uri, self.secret,
+ self.secret, 'user')
+ self.addCleanup(manager.close)
+ blob_id = 'local_only_blob_id'
+ yield manager.local.put(blob_id, BytesIO("X"), size=1)
+ yield manager.send_missing()
+ result = yield manager._download_and_decrypt(blob_id)
+ assert result is not None
+ assert result[0].getvalue() == "X"