summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-03-22 00:02:32 -0300
committerdrebs <drebs@leap.se>2017-04-04 18:27:37 +0200
commita44954eb34f1ba46eae17b281022e3c8b2fae889 (patch)
treef223f24d35743ef82f58c267144a46d11c714c05
parentc6d8c86561de093531131a7709afefcf4ec576a9 (diff)
[test] test blobs local db with file handlers
-rw-r--r--testing/tests/blobs/test_local_backend.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/testing/tests/blobs/test_local_backend.py b/testing/tests/blobs/test_local_backend.py
index 730da38b..1e23606c 100644
--- a/testing/tests/blobs/test_local_backend.py
+++ b/testing/tests/blobs/test_local_backend.py
@@ -19,10 +19,11 @@ Tests for sqlcipher backend on blobs client.
"""
from twisted.trial import unittest
from twisted.internet import defer
-from leap.soledad.client._blobs import BlobManager
+from leap.soledad.client._blobs import BlobManager, BlobDoc
from io import BytesIO
from mock import Mock
import pytest
+import os
class SQLCipherBlobsClientTestCase(unittest.TestCase):
@@ -48,3 +49,44 @@ class SQLCipherBlobsClientTestCase(unittest.TestCase):
result = yield self.manager.get(*args)
assert result is None
self.manager._download_and_decrypt.assert_called_once_with(*args)
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_get_from_existing_value(self):
+ self.manager._download_and_decrypt = Mock(return_value=None)
+ msg = "It's me, M4r10!"
+ yield self.manager.local.put('myblob_id', BytesIO(msg),
+ size=len(msg))
+ args = ('myblob_id', 'mydoc_id', 'cool_rev')
+ result = yield self.manager.get(*args)
+ assert result.getvalue() == msg
+ assert not self.manager._download_and_decrypt.called
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_put_stores_on_local_db(self):
+ self.manager._encrypt_and_upload = Mock(return_value=None)
+ msg = "Hey Joe"
+ doc = BlobDoc('mydoc_id', 'mydoc_rev', BytesIO(msg),
+ blob_id='myblob_id')
+ yield self.manager.put(doc, size=len(msg))
+ result = yield self.manager.local.get('myblob_id')
+ assert result.getvalue() == msg
+ assert self.manager._encrypt_and_upload.called
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_put_then_get_using_real_file_descriptor(self):
+ self.manager._encrypt_and_upload = Mock(return_value=None)
+ self.manager._download_and_decrypt = Mock(return_value=None)
+ msg = "Fuuuuull cycleee! \o/"
+ tmpfile = os.tmpfile()
+ tmpfile.write(msg)
+ tmpfile.seek(0)
+ doc = BlobDoc('mydoc_id', 'mydoc_rev', tmpfile,
+ blob_id='myblob_id')
+ yield self.manager.put(doc, size=len(msg))
+ result = yield self.manager.get(doc.blob_id, doc.doc_id, doc.rev)
+ assert result.getvalue() == msg
+ assert self.manager._encrypt_and_upload.called
+ assert not self.manager._download_and_decrypt.called