Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
soledad
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
leap
soledad
Commits
96dff026
Verified
Commit
96dff026
authored
7 years ago
by
drebs
Browse files
Options
Downloads
Patches
Plain Diff
[refactor] make count() return a deferred
parent
601eb94c
No related branches found
Branches containing commit
No related tags found
1 merge request
!169
#9007 - improve and document IBlobsBackend
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/leap/soledad/server/_blobs.py
+6
-2
6 additions, 2 deletions
src/leap/soledad/server/_blobs.py
src/leap/soledad/server/interfaces.py
+3
-3
3 additions, 3 deletions
src/leap/soledad/server/interfaces.py
tests/blobs/test_fs_backend.py
+24
-5
24 additions, 5 deletions
tests/blobs/test_fs_backend.py
with
33 additions
and
10 deletions
src/leap/soledad/server/_blobs.py
+
6
−
2
View file @
96dff026
...
...
@@ -159,7 +159,7 @@ class FilesystemBlobsBackend(object):
count
=
0
for
_
,
_
,
filenames
in
os
.
walk
(
base_path
):
count
+=
len
(
filter
(
lambda
i
:
not
i
.
endswith
(
'
.flags
'
),
filenames
))
return
json
.
dumps
({
"
count
"
:
count
}
)
return
defer
.
succeed
(
count
)
def
list_blobs
(
self
,
user
,
namespace
=
''
,
order_by
=
None
,
deleted
=
False
,
filter_flag
=
False
):
...
...
@@ -279,7 +279,11 @@ class BlobsResource(resource.Resource):
logger
.
info
(
"
http get: %s
"
%
request
.
path
)
user
,
blob_id
,
namespace
=
self
.
_validate
(
request
)
if
not
blob_id
and
request
.
args
.
get
(
'
only_count
'
,
[
False
])[
0
]:
return
self
.
_handler
.
count
(
user
,
namespace
)
d
=
self
.
_handler
.
count
(
user
,
namespace
)
d
.
addCallback
(
lambda
count
:
json
.
dumps
({
"
count
"
:
count
}))
d
.
addCallback
(
lambda
count
:
request
.
write
(
count
))
d
.
addCallback
(
lambda
_
:
request
.
finish
())
return
NOT_DONE_YET
elif
not
blob_id
:
order
=
request
.
args
.
get
(
'
order_by
'
,
[
None
])[
0
]
filter_flag
=
request
.
args
.
get
(
'
filter_flag
'
,
[
False
])[
0
]
...
...
This diff is collapsed.
Click to expand it.
src/leap/soledad/server/interfaces.py
+
3
−
3
View file @
96dff026
...
...
@@ -98,9 +98,9 @@ class IBlobsBackend(Interface):
:param namespace: Restrict the count to a certain namespace.
:type namespace: str
:return:
T
he number of blobs in the backend
storage, possibly
restricted to a certain namespace.
:rtype:
int
:return:
A deferred that fires with t
he number of blobs in the backend
storage, possibly
restricted to a certain namespace.
:rtype:
twisted.internet.defer.Deferred
"""
def
list_blobs
(
user
,
namespace
=
''
,
order_by
=
None
,
deleted
=
False
,
...
...
This diff is collapsed.
Click to expand it.
tests/blobs/test_fs_backend.py
+
24
−
5
View file @
96dff026
...
...
@@ -19,6 +19,7 @@ Tests for blobs backend on server side.
"""
from
twisted.trial
import
unittest
from
twisted.internet
import
defer
from
twisted.web.client
import
FileBodyProducer
from
twisted.web.test.test_web
import
DummyRequest
from
leap.common.files
import
mkdir_p
from
leap.soledad.server
import
_blobs
...
...
@@ -26,6 +27,8 @@ from mock import Mock
import
mock
import
os
import
base64
import
io
import
json
import
pytest
...
...
@@ -209,11 +212,27 @@ class FilesystemBackendTestCase(unittest.TestCase):
@defer.inlineCallbacks
def
test_write_blob_using_namespace
(
self
):
backend
=
_blobs
.
FilesystemBlobsBackend
(
blobs_path
=
self
.
tempdir
)
request
=
DummyRequest
([
''
])
request
.
content
=
BytesIO
(
'
content
'
)
yield
backend
.
write_blob
(
'
user
'
,
'
blob_id
'
,
request
,
producer
=
FileBodyProducer
(
io
.
BytesIO
(
'
content
'
))
yield
backend
.
write_blob
(
'
user
'
,
'
blob_id
'
,
producer
,
namespace
=
'
custom
'
)
default
=
yield
backend
.
list_blobs
(
'
user
'
,
request
)
custom
=
yield
backend
.
list_blobs
(
'
user
'
,
request
,
namespace
=
'
custom
'
)
default
=
yield
backend
.
list_blobs
(
'
user
'
)
custom
=
yield
backend
.
list_blobs
(
'
user
'
,
namespace
=
'
custom
'
)
self
.
assertEquals
([],
json
.
loads
(
default
))
self
.
assertEquals
([
'
blob_id
'
],
json
.
loads
(
custom
))
@pytest.mark.usefixtures
(
"
method_tmpdir
"
)
@defer.inlineCallbacks
def
test_count
(
self
):
backend
=
_blobs
.
FilesystemBlobsBackend
(
blobs_path
=
self
.
tempdir
)
content
=
'
blah
'
yield
backend
.
write_blob
(
'
user
'
,
'
blob_id_1
'
,
io
.
BytesIO
(
content
))
yield
backend
.
write_blob
(
'
user
'
,
'
blob_id_2
'
,
io
.
BytesIO
(
content
))
yield
backend
.
write_blob
(
'
user
'
,
'
blob_id_3
'
,
io
.
BytesIO
(
content
))
count
=
yield
backend
.
count
(
'
user
'
)
self
.
assertEqual
(
3
,
count
)
yield
backend
.
write_blob
(
'
user
'
,
'
blob_id_1
'
,
io
.
BytesIO
(
content
),
namespace
=
'
xfiles
'
)
yield
backend
.
write_blob
(
'
user
'
,
'
blob_id_2
'
,
io
.
BytesIO
(
content
),
namespace
=
'
xfiles
'
)
count
=
yield
backend
.
count
(
'
user
'
,
namespace
=
'
xfiles
'
)
self
.
assertEqual
(
2
,
count
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment