diff options
Diffstat (limited to 'testing/tests')
-rw-r--r-- | testing/tests/blobs/test_blobs.py | 17 | ||||
-rw-r--r-- | testing/tests/blobs/test_fs_backend.py | 10 |
2 files changed, 16 insertions, 11 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) diff --git a/testing/tests/blobs/test_fs_backend.py b/testing/tests/blobs/test_fs_backend.py index aaf5f4c3..fd38336d 100644 --- a/testing/tests/blobs/test_fs_backend.py +++ b/testing/tests/blobs/test_fs_backend.py @@ -29,8 +29,9 @@ import pytest class FilesystemBackendTestCase(unittest.TestCase): - def test_tag_header(self): - _blobs.open = lambda x: BytesIO('A' * 40 + 'B' * 16) + @mock.patch.object(_blobs, 'open') + def test_tag_header(self, open_mock): + open_mock.return_value = BytesIO('A' * 40 + 'B' * 16) expected_tag = base64.urlsafe_b64encode('B' * 16) expected_method = Mock() backend = _blobs.FilesystemBlobsBackend() @@ -39,9 +40,10 @@ class FilesystemBackendTestCase(unittest.TestCase): expected_method.assert_called_once_with('Tag', [expected_tag]) - def test_read_blob(self): + @mock.patch.object(_blobs.static, 'File') + def test_read_blob(self, file_mock): render_mock = Mock() - _blobs.static.File = Mock(return_value=render_mock) + file_mock.return_value = render_mock backend = _blobs.FilesystemBlobsBackend() request = object() backend._get_path = Mock(return_value='path') |