summaryrefslogtreecommitdiff
path: root/testing/tests/blobs/test_blobs.py
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-03-20 21:38:22 -0300
committerdrebs <drebs@leap.se>2017-04-04 18:27:37 +0200
commit9628d5fa3ed7bdfd046aee641a8d51605c15bd71 (patch)
tree0bf27af53f2d5c183ae54e9462c151e549e8bf99 /testing/tests/blobs/test_blobs.py
parenta7539317d4847a9eb9fe431709ddab23e54f4be3 (diff)
[test] use mock instead of directly patching
Diffstat (limited to 'testing/tests/blobs/test_blobs.py')
-rw-r--r--testing/tests/blobs/test_blobs.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/testing/tests/blobs/test_blobs.py b/testing/tests/blobs/test_blobs.py
index a36bad1e..77eff6cc 100644
--- a/testing/tests/blobs/test_blobs.py
+++ b/testing/tests/blobs/test_blobs.py
@@ -19,10 +19,11 @@ Tests for cryptographic related stuff.
"""
from twisted.trial import unittest
from twisted.internet import defer
-from leap.soledad.client import _blobs
-from leap.soledad.client._blobs import DecrypterBuffer
+from leap.soledad.client._blobs import DecrypterBuffer, BlobManager
from leap.soledad.client import _crypto
from io import BytesIO
+from mock import Mock
+import mock
class BlobTestCase(unittest.TestCase):
@@ -49,20 +50,22 @@ class BlobTestCase(unittest.TestCase):
fd, size = buf.close()
assert fd.getvalue() == 'rosa de foc'
+ @defer.inlineCallbacks
def test_blob_manager_encrypted_upload(self):
@defer.inlineCallbacks
- def _check_result(uri, data):
+ def _check_result(uri, data, *args, **kwargs):
decryptor = _crypto.BlobDecryptor(
self.doc_info, data,
armor=False,
secret=self.secret)
decrypted = yield decryptor.decrypt()
assert decrypted.getvalue() == 'up and up'
+ defer.returnValue(Mock(code=200))
- manager = _blobs.BlobManager(
- '', 'http://127.0.0.1/', self.secret, self.secret, 'user')
+ manager = BlobManager('', '', self.secret, self.secret, 'user')
doc_id, rev = self.doc_info.doc_id, self.doc_info.rev
fd = BytesIO('up and up')
- manager._client.put = _check_result
- return manager._encrypt_and_upload('blob_id', doc_id, rev, fd)
+ with mock.patch('leap.soledad.client._blobs.treq.put') as mock_treq:
+ mock_treq.side_effect = _check_result
+ yield manager._encrypt_and_upload('blob_id', doc_id, rev, fd)