diff options
-rw-r--r-- | src/leap/soledad/server/_blobs.py | 3 | ||||
-rw-r--r-- | tests/blobs/test_fs_backend.py | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py index 5670c562..5f5ae5ac 100644 --- a/src/leap/soledad/server/_blobs.py +++ b/src/leap/soledad/server/_blobs.py @@ -144,7 +144,8 @@ class FilesystemBlobsBackend(object): pass def get_blob_size(self, user, blob_id, namespace=''): - raise NotImplementedError + blob_path = self._get_path(user, blob_id, namespace) + return os.stat(blob_path).st_size def count(self, user, request, namespace=''): base_path = self._get_path(user, namespace=namespace) diff --git a/tests/blobs/test_fs_backend.py b/tests/blobs/test_fs_backend.py index 47d78ad4..94b628c4 100644 --- a/tests/blobs/test_fs_backend.py +++ b/tests/blobs/test_fs_backend.py @@ -52,6 +52,19 @@ class FilesystemBackendTestCase(unittest.TestCase): expected_method.assert_called_once_with('Tag', [expected_tag]) @pytest.mark.usefixtures("method_tmpdir") + def test_get_blob_size(self): + # get a backend + backend = _blobs.FilesystemBlobsBackend(blobs_path=self.tempdir) + # write a blob with size=10 + path = backend._get_path('user', 'blob_id', '') + mkdir_p(os.path.split(path)[0]) + with open(path, "w") as f: + f.write("0123456789") + # check it's size + size = backend.get_blob_size('user', 'blob_id', '') + self.assertEquals(10, size) + + @pytest.mark.usefixtures("method_tmpdir") @mock.patch.object(_blobs.static, 'File') @mock.patch.object(_blobs.FilesystemBlobsBackend, '_get_path', Mock(return_value='path')) |