summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-03-22 16:34:15 -0300
committerdrebs <drebs@leap.se>2017-04-04 18:27:38 +0200
commitaaa9115cfd4096a4fb6cf0ffbc2c07c75ed3a751 (patch)
tree4edc3cea4624b764a301ee482190c5dfe184eb7c /testing
parent5acadaa7716a86448af02c3a078759ddddd45c85 (diff)
[feature] use 409 status code for existing blob id
Raising was generating 500, which is a generic status code for server side errors. This commit adds proper status code of 409 while handling the error on client side by translating the code into a proper exception class.
Diffstat (limited to 'testing')
-rw-r--r--testing/tests/blobs/test_fs_backend.py9
-rw-r--r--testing/tests/server/test_blobs_server.py15
2 files changed, 19 insertions, 5 deletions
diff --git a/testing/tests/blobs/test_fs_backend.py b/testing/tests/blobs/test_fs_backend.py
index fd38336d..ce82fce0 100644
--- a/testing/tests/blobs/test_fs_backend.py
+++ b/testing/tests/blobs/test_fs_backend.py
@@ -18,6 +18,7 @@
Tests for blobs backend on server side.
"""
from twisted.trial import unittest
+from twisted.web.test.test_web import DummyRequest
from leap.soledad.server import _blobs
from io import BytesIO
from mock import Mock
@@ -45,7 +46,7 @@ class FilesystemBackendTestCase(unittest.TestCase):
render_mock = Mock()
file_mock.return_value = render_mock
backend = _blobs.FilesystemBlobsBackend()
- request = object()
+ request = DummyRequest([''])
backend._get_path = Mock(return_value='path')
backend.read_blob('user', 'blob_id', request)
@@ -59,8 +60,10 @@ class FilesystemBackendTestCase(unittest.TestCase):
isfile.return_value = True
backend = _blobs.FilesystemBlobsBackend()
backend._get_path = Mock(return_value='path')
- with pytest.raises(_blobs.BlobAlreadyExists):
- backend.write_blob('user', 'blob_id', 'request')
+ request = DummyRequest([''])
+ result = backend.write_blob('user', 'blob_id', request)
+ assert result == "Blob already exists: blob_id"
+ assert request.responseCode == 409
@pytest.mark.usefixtures("method_tmpdir")
@mock.patch.object(os.path, 'isfile')
diff --git a/testing/tests/server/test_blobs_server.py b/testing/tests/server/test_blobs_server.py
index 2c52ea46..1f35c285 100644
--- a/testing/tests/server/test_blobs_server.py
+++ b/testing/tests/server/test_blobs_server.py
@@ -24,7 +24,7 @@ from twisted.web.server import Site
from twisted.internet import reactor
from twisted.internet import defer
from leap.soledad.server import _blobs as server_blobs
-from leap.soledad.client._blobs import BlobManager
+from leap.soledad.client._blobs import BlobManager, BlobAlreadyExistsError
class BlobServerTestCase(unittest.TestCase):
@@ -42,7 +42,7 @@ class BlobServerTestCase(unittest.TestCase):
@defer.inlineCallbacks
@pytest.mark.usefixtures("method_tmpdir")
- def test_upload(self):
+ def test_upload_download(self):
manager = BlobManager('', self.uri, self.secret,
self.secret, 'user')
fd = BytesIO("save me")
@@ -50,3 +50,14 @@ class BlobServerTestCase(unittest.TestCase):
blob, size = yield manager._download_and_decrypt('blob_id',
'mydoc', '1')
assert blob.getvalue() == "save me"
+
+ @defer.inlineCallbacks
+ @pytest.mark.usefixtures("method_tmpdir")
+ def test_upload_deny_duplicates(self):
+ manager = BlobManager('', self.uri, self.secret,
+ self.secret, 'user')
+ fd = BytesIO("save me")
+ yield manager._encrypt_and_upload('blob_id', 'mydoc', '1', fd)
+ fd = BytesIO("save me")
+ with pytest.raises(BlobAlreadyExistsError):
+ yield manager._encrypt_and_upload('blob_id', 'mydoc', '1', fd)