summaryrefslogtreecommitdiff
path: root/testing/tests
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-05-01 04:41:39 -0300
committerVictor Shyba <victor1984@riseup.net>2017-05-01 04:41:39 -0300
commit6ae4b45866a8f4eb85fbde56f2525288afcd300f (patch)
treeb06d3350fff991fd26e62d40e976629c53893592 /testing/tests
parenta79e59656b08c9c60e607e9863191dca41591ae0 (diff)
[test] add tests for sqlcipher client backend
BlobManager tests covers them indirectly, but testing them directly may help locating source of bugs. - Related: #8812
Diffstat (limited to 'testing/tests')
-rw-r--r--testing/tests/blobs/test_blob_manager.py2
-rw-r--r--testing/tests/blobs/test_sqlcipher_client_backend.py63
2 files changed, 64 insertions, 1 deletions
diff --git a/testing/tests/blobs/test_blob_manager.py b/testing/tests/blobs/test_blob_manager.py
index b5a14de4..7609936d 100644
--- a/testing/tests/blobs/test_blob_manager.py
+++ b/testing/tests/blobs/test_blob_manager.py
@@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
-Tests for sqlcipher backend on blobs client.
+Tests for BlobManager.
"""
from twisted.trial import unittest
from twisted.internet import defer
diff --git a/testing/tests/blobs/test_sqlcipher_client_backend.py b/testing/tests/blobs/test_sqlcipher_client_backend.py
new file mode 100644
index 00000000..951bac22
--- /dev/null
+++ b/testing/tests/blobs/test_sqlcipher_client_backend.py
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+# test_sqlcipher_client_backend.py
+# Copyright (C) 2017 LEAP
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+Tests for sqlcipher backend on blobs client.
+"""
+from twisted.trial import unittest
+from twisted.internet import defer
+from leap.soledad.client._blobs import SQLiteBlobBackend
+from io import BytesIO
+import pytest
+
+
+class SQLBackendTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.key = "A" * 96
+ self.local = SQLiteBlobBackend(self.tempdir, self.key)
+ self.addCleanup(self.local.close)
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_get_inexistent(self):
+ bad_blob_id = 'inexsistent_id'
+ self.assertFalse((yield self.local.exists(bad_blob_id)))
+ result = yield self.local.get(bad_blob_id)
+ self.assertIsNone(result)
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_get_existent(self):
+ blob_id = 'blob_id'
+ content = "x"
+ yield self.local.put(blob_id, BytesIO(content), len(content))
+ result = yield self.local.get(blob_id)
+ self.assertTrue((yield self.local.exists(blob_id)))
+ self.assertEquals(result.getvalue(), content)
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_list(self):
+ blob_ids = [('blob_id%s' % i) for i in range(10)]
+ content = "x"
+ deferreds = []
+ for blob_id in blob_ids:
+ deferreds.append(self.local.put(blob_id, BytesIO(content),
+ len(content)))
+ yield defer.gatherResults(deferreds)
+ result = yield self.local.list()
+ self.assertEquals(blob_ids, result)