diff options
-rw-r--r-- | client/src/leap/soledad/client/_blobs.py | 10 | ||||
-rw-r--r-- | testing/tests/blobs/test_local_backend.py | 15 |
2 files changed, 25 insertions, 0 deletions
diff --git a/client/src/leap/soledad/client/_blobs.py b/client/src/leap/soledad/client/_blobs.py index f9f1515b..e781421e 100644 --- a/client/src/leap/soledad/client/_blobs.py +++ b/client/src/leap/soledad/client/_blobs.py @@ -163,6 +163,9 @@ class BlobManager(object): data = yield self._client.get(uri) defer.returnValue((yield data.json())) + def local_list(self): + return self.local.list() + @defer.inlineCallbacks def put(self, doc, size): fd = doc.blob_fd @@ -289,6 +292,13 @@ class SQLiteBlobBackend(object): if result: defer.returnValue(BytesIO(str(result[0][0]))) + @defer.inlineCallbacks + def list(self): + query = 'select blob_id from blobs' + result = yield self.dbpool.runQuery(query) + if result: + defer.returnValue([b_id[0] for b_id in result]) + def _init_blob_table(conn): maybe_create = ( diff --git a/testing/tests/blobs/test_local_backend.py b/testing/tests/blobs/test_local_backend.py index 1e23606c..79f433fe 100644 --- a/testing/tests/blobs/test_local_backend.py +++ b/testing/tests/blobs/test_local_backend.py @@ -90,3 +90,18 @@ class SQLCipherBlobsClientTestCase(unittest.TestCase): assert result.getvalue() == msg assert self.manager._encrypt_and_upload.called assert not self.manager._download_and_decrypt.called + + @defer.inlineCallbacks + @pytest.mark.usefixtures("method_tmpdir") + def test_local_list_blobs(self): + self.manager._encrypt_and_upload = Mock(return_value=None) + msg = "1337" + doc = BlobDoc('mydoc_id', 'mydoc_rev', BytesIO(msg), + blob_id='myblob_id') + yield self.manager.put(doc, size=len(msg)) + doc2 = BlobDoc('mydoc_id2', 'mydoc_rev2', BytesIO(msg), + blob_id='myblob_id2') + yield self.manager.put(doc2, size=len(msg)) + blobs_list = yield self.manager.local_list() + + assert 'myblob_id' in blobs_list and 'myblob_id2' in blobs_list |