summaryrefslogtreecommitdiff
path: root/testing/tests
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-03-17 07:05:01 -0300
committerdrebs <drebs@leap.se>2017-04-04 18:27:35 +0200
commit7dea944dc009c592e987f977d6224c8f5a565015 (patch)
tree1379549d75eba386648f13fa7c620b782c5e1fa2 /testing/tests
parent4da20addb409c6999c10bdacece7bb5e786ee69e (diff)
[test] check that write respects quota
Diffstat (limited to 'testing/tests')
-rw-r--r--testing/tests/blobs/test_fs_backend.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/testing/tests/blobs/test_fs_backend.py b/testing/tests/blobs/test_fs_backend.py
index ee388561..90b38037 100644
--- a/testing/tests/blobs/test_fs_backend.py
+++ b/testing/tests/blobs/test_fs_backend.py
@@ -21,6 +21,8 @@ from twisted.trial import unittest
from leap.soledad.server import _blobs
from io import BytesIO
from mock import Mock
+import mock
+import os
import base64
import pytest
@@ -50,9 +52,26 @@ class FilesystemBackendTestCase(unittest.TestCase):
_blobs.static.File.assert_called_once_with('path', defaultType=ctype)
render_mock.render_GET.assert_called_once_with(request)
- def test_cannot_overwrite(self):
- _blobs.os.path.isfile = lambda path: True
+ @mock.patch.object(os.path, 'isfile')
+ def test_cannot_overwrite(self, isfile):
+ 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')
+
+ @pytest.mark.usefixtures("method_tmpdir")
+ @mock.patch.object(os.path, 'isfile')
+ def test_write_cannot_exceed_quota(self, isfile):
+ isfile.return_value = False
+ backend = _blobs.FilesystemBlobsBackend()
+ backend._get_path = Mock(return_value=self.tempdir)
+ request = Mock()
+
+ backend.get_total_storage = lambda x: 100
+ backend.quota = 90
+ backend.write_blob('user', 'blob_id', request)
+
+ request.setResponseCode.assert_called_once_with(507)
+ request.write.assert_called_once_with('Quota Exceeded!')
+ request.finish.assert_called_once()