Skip to content
Snippets Groups Projects
Verified Commit d574e734 authored by Victor's avatar Victor
Browse files

[feature] add implementation for get_blob_size

parent 5c810908
No related branches found
No related tags found
1 merge request!166Streaming blobs (Related: #8809 #8810 #8773 )
...@@ -144,7 +144,8 @@ class FilesystemBlobsBackend(object): ...@@ -144,7 +144,8 @@ class FilesystemBlobsBackend(object):
pass pass
def get_blob_size(self, user, blob_id, namespace=''): 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=''): def count(self, user, request, namespace=''):
base_path = self._get_path(user, namespace=namespace) base_path = self._get_path(user, namespace=namespace)
......
...@@ -51,6 +51,19 @@ class FilesystemBackendTestCase(unittest.TestCase): ...@@ -51,6 +51,19 @@ class FilesystemBackendTestCase(unittest.TestCase):
expected_method.assert_called_once_with('Tag', [expected_tag]) 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") @pytest.mark.usefixtures("method_tmpdir")
@mock.patch.object(_blobs.static, 'File') @mock.patch.object(_blobs.static, 'File')
@mock.patch.object(_blobs.FilesystemBlobsBackend, '_get_path', @mock.patch.object(_blobs.FilesystemBlobsBackend, '_get_path',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment