Skip to content
Snippets Groups Projects
Verified Commit 9f07826c authored by drebs's avatar drebs
Browse files

[refactor] make blobs backend get_flags() agnostic of twisted.web requests

parent 6f29df7d
No related branches found
No related tags found
1 merge request!169#9007 - improve and document IBlobsBackend
......@@ -85,16 +85,14 @@ class FilesystemBlobsBackend(object):
_file = static.File(path, defaultType='application/octet-stream')
return _file.render_GET(request)
def get_flags(self, user, blob_id, request, namespace=''):
def get_flags(self, user, blob_id, namespace=''):
path = self._get_path(user, blob_id, namespace)
if not os.path.isfile(path):
# 404 - Not Found
request.setResponseCode(404)
return "Blob doesn't exists: %s" % blob_id
raise BlobNotFound
if not os.path.isfile(path + '.flags'):
return '[]'
return []
with open(path + '.flags', 'r') as flags_file:
return flags_file.read()
return json.loads(flags_file.read())
def set_flags(self, user, blob_id, request, namespace=''):
path = self._get_path(user, blob_id, namespace)
......@@ -286,16 +284,18 @@ class BlobsResource(resource.Resource):
order_by=order, deleted=deleted,
filter_flag=filter_flag)
only_flags = request.args.get('only_flags', [False])[0]
if only_flags:
return self._handler.get_flags(user, blob_id, request, namespace)
try:
if only_flags:
flags = self._handler.get_flags(user, blob_id, namespace)
return json.dumps(flags)
tag = self._handler.get_tag(user, blob_id, namespace)
request.responseHeaders.setRawHeaders('Tag', [tag])
except BlobNotFound:
# 404 - Not Found
request.setResponseCode(404)
return "Blob doesn't exists: %s" % blob_id
request.responseHeaders.setRawHeaders('Tag', [tag])
return self._handler.read_blob(user, blob_id, request, namespace)
return self._handler.read_blob(user, blob_id, request,
namespace=namespace)
def render_DELETE(self, request):
logger.info("http put: %s" % request.path)
......
......@@ -167,7 +167,7 @@ class IBlobsBackend(Interface):
:rtype: str
"""
def get_flags(user, blob_id, request, namespace=''):
def get_flags(user, blob_id, namespace=''):
"""
Get the flags for a blob.
......@@ -175,14 +175,11 @@ class IBlobsBackend(Interface):
:type user: str
:param blob_id: The id of the blob.
:type blob_id: str
:param request: A representation of all of the information about the
request that is being made.
:type request: twisted.web.server.Request
:param namespace: An optional namespace for the blob.
:type namespace: str
:return: a JSON encoded string with a list of flags.
:rtype: str
:return: a list of flags.
:rtype: list of str
"""
def set_flags(user, blob_id, request, namespace=''):
......
......@@ -18,7 +18,6 @@
Integration tests for incoming API
"""
import pytest
import json
from io import BytesIO
from uuid import uuid4
from twisted.web.test.test_web import DummyRequest
......@@ -86,8 +85,7 @@ class IncomingOnCouchServerTestCase(CouchDBTestCase):
db = self.state.open_database(user_id)
request = DummyRequest([user_id, doc_id])
yield db.read_blob(user_id, doc_id, request, 'MX')
flags = db.get_flags(user_id, doc_id, request, 'MX')
flags = json.loads(flags)
flags = db.get_flags(user_id, doc_id, 'MX')
expected_preamble = formatter.preamble(content, doc_id)
expected_preamble = decode_preamble(expected_preamble, True)
written_preamble, written_content = request.written[0].split()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment