mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-24 07:06:41 +00:00
web: fix JSON output for mutable files
This commit is contained in:
parent
1d8e452184
commit
8dded7819c
@ -1139,6 +1139,7 @@ class Web(WebMixin, unittest.TestCase):
|
||||
self.failUnlessEqual(self._mutable_uri, newnode.get_uri())
|
||||
d.addCallback(_got3)
|
||||
|
||||
# look at the JSON form of the enclosing directory
|
||||
d.addCallback(lambda res:
|
||||
self.GET(self.public_url + "/foo/?t=json",
|
||||
followRedirect=True))
|
||||
@ -1154,6 +1155,17 @@ class Web(WebMixin, unittest.TestCase):
|
||||
self.failUnlessEqual(new_json[1]["ro_uri"], ro_uri)
|
||||
d.addCallback(_check_page_json)
|
||||
|
||||
# and the JSON form of the file
|
||||
d.addCallback(lambda res:
|
||||
self.GET(self.public_url + "/foo/new.txt?t=json"))
|
||||
def _check_file_json(res):
|
||||
parsed = simplejson.loads(res)
|
||||
self.failUnlessEqual(parsed[0], "filenode")
|
||||
self.failUnlessEqual(parsed[1]["rw_uri"], self._mutable_uri)
|
||||
ro_uri = unicode(self._mutable_node.get_readonly().to_string())
|
||||
self.failUnlessEqual(parsed[1]["ro_uri"], ro_uri)
|
||||
d.addCallback(_check_file_json)
|
||||
|
||||
# and look at t=uri and t=readonly-uri
|
||||
d.addCallback(lambda res:
|
||||
self.GET(self.public_url + "/foo/new.txt?t=uri"))
|
||||
|
@ -368,11 +368,18 @@ class FileDownloader(resource.Resource):
|
||||
return server.NOT_DONE_YET
|
||||
|
||||
def FileJSONMetadata(ctx, filenode):
|
||||
file_uri = filenode.get_uri()
|
||||
data = ("filenode",
|
||||
{'ro_uri': file_uri,
|
||||
'size': filenode.get_size(),
|
||||
})
|
||||
if filenode.is_readonly():
|
||||
rw_uri = None
|
||||
ro_uri = filenode.get_uri()
|
||||
else:
|
||||
rw_uri = filenode.get_uri()
|
||||
ro_uri = filenode.get_readonly_uri()
|
||||
data = ("filenode", {})
|
||||
data[1]['size'] = filenode.get_size()
|
||||
if ro_uri:
|
||||
data[1]['ro_uri'] = ro_uri
|
||||
if rw_uri:
|
||||
data[1]['rw_uri'] = rw_uri
|
||||
return text_plain(simplejson.dumps(data, indent=1), ctx)
|
||||
|
||||
def FileURI(ctx, filenode):
|
||||
|
Loading…
Reference in New Issue
Block a user