]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
web: fix JSON output for mutable files
authorBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 22:14:19 +0000 (15:14 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 22:14:19 +0000 (15:14 -0700)
src/allmydata/test/test_web.py
src/allmydata/web/filenode.py

index 313f4fc6b9e0e7f248970052316b2a94f3d94a8c..754b42eccc96d34f49579b0c8a9d4b69e4221b25 100644 (file)
@@ -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"))
index 013c1e06d51451f2d166b91bf3556d58195eb394..f65af29e67939f94766067db5b44ca90f963d007 100644 (file)
@@ -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):