summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/leap/soledad/client/_db/blobs/__init__.py5
-rw-r--r--tests/blobs/test_blob_manager.py23
-rw-r--r--tests/blobs/test_fs_backend.py13
3 files changed, 39 insertions, 2 deletions
diff --git a/src/leap/soledad/client/_db/blobs/__init__.py b/src/leap/soledad/client/_db/blobs/__init__.py
index 95814d46..4db7df6a 100644
--- a/src/leap/soledad/client/_db/blobs/__init__.py
+++ b/src/leap/soledad/client/_db/blobs/__init__.py
@@ -321,8 +321,9 @@ class BlobManager(BlobsSynchronizer):
# In fact, some kind of pipe is needed here, where each write on db
# handle gets forwarded into a write on the connection handle
fd = yield self.local.get(blob_id, namespace=namespace)
- yield self._encrypt_and_upload(blob_id, fd)
- yield self.local.update_sync_status(blob_id, SyncStatus.SYNCED)
+ yield self._encrypt_and_upload(blob_id, fd, namespace=namespace)
+ yield self.local.update_sync_status(blob_id, SyncStatus.SYNCED,
+ namespace=namespace)
def set_flags(self, blob_id, flags, namespace=''):
"""
diff --git a/tests/blobs/test_blob_manager.py b/tests/blobs/test_blob_manager.py
index 76ebcd03..761ede44 100644
--- a/tests/blobs/test_blob_manager.py
+++ b/tests/blobs/test_blob_manager.py
@@ -83,6 +83,29 @@ class BlobManagerTestCase(unittest.TestCase):
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
+ def test_put_stores_on_local_db_with_namespace(self):
+ self.manager._encrypt_and_upload = Mock(return_value=None)
+ self.manager._download_and_decrypt = Mock(return_value=None)
+ msg, blob_id = "Hey Joe", uuid4().hex
+ doc = BlobDoc(BytesIO(msg), blob_id=blob_id)
+
+ yield self.manager.put(doc, size=len(msg), namespace='custom')
+ self.assertTrue(self.manager._encrypt_and_upload.called)
+
+ arg1, arg2 = self.manager._encrypt_and_upload.call_args[0]
+ kwargs = self.manager._encrypt_and_upload.call_args[1]
+ self.assertEquals(arg1, blob_id)
+ self.assertTrue(isinstance(arg2, BytesIO))
+ self.assertEquals(kwargs, {'namespace': 'custom'})
+
+ result = yield self.manager.local.get(blob_id)
+ self.assertEquals(result, None)
+
+ result = yield self.manager.local.get(blob_id, namespace='custom')
+ self.assertEquals(result.getvalue(), msg)
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
def test_put_local_only_doesnt_send_to_server(self):
self.manager._encrypt_and_upload = Mock(return_value=None)
msg, blob_id = "Hey Joe", uuid4().hex
diff --git a/tests/blobs/test_fs_backend.py b/tests/blobs/test_fs_backend.py
index 94b628c4..da328dab 100644
--- a/tests/blobs/test_fs_backend.py
+++ b/tests/blobs/test_fs_backend.py
@@ -214,3 +214,16 @@ class FilesystemBackendTestCase(unittest.TestCase):
unlink_mock.assert_any_call(backend._get_path('user',
'blob_id',
'trash') + '.flags')
+
+ @pytest.mark.usefixtures("method_tmpdir")
+ @defer.inlineCallbacks
+ def test_write_blob_using_namespace(self):
+ backend = _blobs.FilesystemBlobsBackend(blobs_path=self.tempdir)
+ request = DummyRequest([''])
+ request.content = BytesIO('content')
+ yield backend.write_blob('user', 'blob_id', request,
+ namespace='custom')
+ default = yield backend.list_blobs('user', request)
+ custom = yield backend.list_blobs('user', request, namespace='custom')
+ self.assertEquals([], json.loads(default))
+ self.assertEquals(['blob_id'], json.loads(custom))