summaryrefslogtreecommitdiff
path: root/testing/tests/blobs
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-09-07 18:09:11 -0300
committerdrebs <drebs@riseup.net>2017-09-11 11:22:59 -0300
commitf5e2ec7f1901863ce967a91cf0a244b771bcf857 (patch)
tree1df7334734c25a81bf5e368779bcfcd5d91f9afe /testing/tests/blobs
parentf0e069b9f7f0718263d96b3158c0c6a3de959d04 (diff)
[tests] improve isolation on user uuid
Hardcoded and repeated user uuids can lead to accidental concurrent operations between test cases, breaking isolation and creating random failures. This commit improves it a bit.
Diffstat (limited to 'testing/tests/blobs')
-rw-r--r--testing/tests/blobs/test_blob_manager.py22
-rw-r--r--testing/tests/blobs/test_sqlcipher_client_backend.py19
2 files changed, 21 insertions, 20 deletions
diff --git a/testing/tests/blobs/test_blob_manager.py b/testing/tests/blobs/test_blob_manager.py
index dd57047d..7d985768 100644
--- a/testing/tests/blobs/test_blob_manager.py
+++ b/testing/tests/blobs/test_blob_manager.py
@@ -42,17 +42,17 @@ class BlobManagerTestCase(unittest.TestCase):
self.manager = BlobManager(
self.tempdir, '',
'A' * 32, self.secret,
- 'uuid', 'token', None)
+ uuid4().hex, 'token', None)
self.addCleanup(self.manager.close)
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
- def test_get_inexistent(self):
+ def test_get_missing(self):
self.manager._download_and_decrypt = Mock(return_value=None)
- bad_blob_id = 'inexsistent_id'
- result = yield self.manager.get(bad_blob_id)
+ missing_blob_id = uuid4().hex
+ result = yield self.manager.get(missing_blob_id)
self.assertIsNone(result)
- args = bad_blob_id, ''
+ args = missing_blob_id, ''
self.manager._download_and_decrypt.assert_called_once_with(*args)
@defer.inlineCallbacks
@@ -109,26 +109,26 @@ class BlobManagerTestCase(unittest.TestCase):
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
def test_send_missing(self):
- fd = BytesIO('test')
+ fd, missing_id = BytesIO('test'), uuid4().hex
self.manager._encrypt_and_upload = Mock(return_value=None)
self.manager.remote_list = Mock(return_value=[])
- yield self.manager.local.put('missing_id', fd, 4)
+ yield self.manager.local.put(missing_id, fd, 4)
yield self.manager.send_missing()
call_list = self.manager._encrypt_and_upload.call_args_list
self.assertEquals(1, len(call_list))
call_blob_id, call_fd = call_list[0][0]
- self.assertEquals('missing_id', call_blob_id)
+ self.assertEquals(missing_id, call_blob_id)
self.assertEquals('test', call_fd.getvalue())
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
def test_duplicated_blob_error_on_put(self):
self.manager._encrypt_and_upload = Mock(return_value=None)
- content = "Blob content"
- doc1 = BlobDoc(BytesIO(content), 'existing_id')
+ content, existing_id = "Blob content", uuid4().hex
+ doc1 = BlobDoc(BytesIO(content), existing_id)
yield self.manager.put(doc1, len(content))
- doc2 = BlobDoc(BytesIO(content), 'existing_id')
+ doc2 = BlobDoc(BytesIO(content), existing_id)
self.manager._encrypt_and_upload.reset_mock()
with pytest.raises(BlobAlreadyExistsError):
yield self.manager.put(doc2, len(content))
diff --git a/testing/tests/blobs/test_sqlcipher_client_backend.py b/testing/tests/blobs/test_sqlcipher_client_backend.py
index 6193b486..daf561c7 100644
--- a/testing/tests/blobs/test_sqlcipher_client_backend.py
+++ b/testing/tests/blobs/test_sqlcipher_client_backend.py
@@ -21,6 +21,7 @@ from twisted.trial import unittest
from twisted.internet import defer
from leap.soledad.client._db.blobs import SQLiteBlobBackend
from io import BytesIO
+from uuid import uuid4
import pytest
@@ -34,7 +35,7 @@ class SQLBackendTestCase(unittest.TestCase):
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
def test_get_inexisting(self):
- bad_blob_id = 'inexsisting_id'
+ bad_blob_id = uuid4().hex
self.assertFalse((yield self.local.exists(bad_blob_id)))
result = yield self.local.get(bad_blob_id)
self.assertIsNone(result)
@@ -42,7 +43,7 @@ class SQLBackendTestCase(unittest.TestCase):
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
def test_get_existing(self):
- blob_id = 'blob_id'
+ blob_id = uuid4().hex
content = "x"
yield self.local.put(blob_id, BytesIO(content), len(content))
result = yield self.local.get(blob_id)
@@ -52,18 +53,18 @@ class SQLBackendTestCase(unittest.TestCase):
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
def test_delete(self):
- blob_id = 'blob_id'
+ blob_id1, blob_id2 = uuid4().hex, uuid4().hex
content = "x"
- yield self.local.put(blob_id, BytesIO(content), len(content))
- yield self.local.put('remains', BytesIO(content), len(content))
- yield self.local.delete(blob_id)
- self.assertFalse((yield self.local.exists(blob_id)))
- self.assertTrue((yield self.local.exists('remains')))
+ yield self.local.put(blob_id1, BytesIO(content), len(content))
+ yield self.local.put(blob_id2, BytesIO(content), len(content))
+ yield self.local.delete(blob_id1)
+ self.assertFalse((yield self.local.exists(blob_id1)))
+ self.assertTrue((yield self.local.exists(blob_id2)))
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
def test_list(self):
- blob_ids = [('blob_id%s' % i) for i in range(10)]
+ blob_ids = [uuid4().hex for _ in range(10)]
content = "x"
deferreds = []
for blob_id in blob_ids: