]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
web/directory: fix rw_uri output in t=JSON to reflect mutable files properly
authorBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 01:37:28 +0000 (18:37 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 20 May 2008 01:37:28 +0000 (18:37 -0700)
src/allmydata/test/test_web.py
src/allmydata/web/directory.py

index 7343ece91ce202e6e17e1c25a3bddb8634b14972..d8faa952c3a7c08978c47ec3c289cd626d31c9d2 100644 (file)
@@ -911,6 +911,7 @@ class Web(WebMixin, unittest.TestCase):
             self.failUnless(IMutableFileNode.providedBy(newnode))
             self.failUnless(newnode.is_mutable())
             self.failIf(newnode.is_readonly())
+            self._mutable_node = newnode
             self._mutable_uri = newnode.get_uri()
         d.addCallback(_got)
 
@@ -976,6 +977,21 @@ class Web(WebMixin, unittest.TestCase):
             self.failUnlessEqual(self._mutable_uri, newnode.get_uri())
         d.addCallback(_got3)
 
+        d.addCallback(lambda res:
+                      self.GET(self.public_url + "/foo/?t=json",
+                               followRedirect=True))
+        def _check_page_json(res):
+            parsed = simplejson.loads(res)
+            self.failUnlessEqual(parsed[0], "dirnode")
+            children = parsed[1]["children"]
+            self.failUnless("new.txt" in children)
+            new_json = children["new.txt"]
+            self.failUnlessEqual(new_json[0], "filenode")
+            self.failUnlessEqual(new_json[1]["rw_uri"], self._mutable_uri)
+            ro_uri = unicode(self._mutable_node.get_readonly().to_string())
+            self.failUnlessEqual(new_json[1]["ro_uri"], ro_uri)
+        d.addCallback(_check_page_json)
+
         d.addErrback(self.dump_error)
         return d
 
index 8397541b5cf82242a9a26fa70f5e9663953d883e..8e7c021acbd4a9c18cd65d54f12e98447ae3870b 100644 (file)
@@ -627,28 +627,36 @@ def DirectoryJSONMetadata(ctx, dirnode):
     def _got(children):
         kids = {}
         for name, (childnode, metadata) in children.iteritems():
+            if childnode.is_readonly():
+                rw_uri = None
+                ro_uri = childnode.get_uri()
+            else:
+                rw_uri = childnode.get_uri()
+                ro_uri = childnode.get_readonly_uri()
             if IFileNode.providedBy(childnode):
-                kiduri = childnode.get_uri()
-                kiddata = ("filenode",
-                           {'ro_uri': kiduri,
-                            'size': childnode.get_size(),
-                            'metadata': metadata,
-                            })
+                kiddata = ("filenode", {'size': childnode.get_size(),
+                                        'metadata': metadata,
+                                        })
             else:
                 assert IDirectoryNode.providedBy(childnode), (childnode,
                                                               children,)
-                kiddata = ("dirnode",
-                           {'ro_uri': childnode.get_readonly_uri(),
-                            'metadata': metadata,
-                            })
-                if not childnode.is_readonly():
-                    kiddata[1]['rw_uri'] = childnode.get_uri()
+                kiddata = ("dirnode", {'metadata': metadata})
+            if ro_uri:
+                kiddata[1]["ro_uri"] = ro_uri
+            if rw_uri:
+                kiddata[1]["rw_uri"] = rw_uri
             kids[name] = kiddata
-        contents = { 'children': kids,
-                     'ro_uri': dirnode.get_readonly_uri(),
-                     }
-        if not dirnode.is_readonly():
-            contents['rw_uri'] = dirnode.get_uri()
+        if dirnode.is_readonly():
+            drw_uri = None
+            dro_uri = dirnode.get_uri()
+        else:
+            drw_uri = dirnode.get_uri()
+            dro_uri = dirnode.get_readonly_uri()
+        contents = { 'children': kids }
+        if dro_uri:
+            contents['ro_uri'] = dro_uri
+        if drw_uri:
+            contents['rw_uri'] = drw_uri
         data = ("dirnode", contents)
         return simplejson.dumps(data, indent=1)
     d.addCallback(_got)