From: Brian Warner Date: Sat, 7 Jul 2007 17:34:05 +0000 (-0700) Subject: web: more test work, now all tests either pass or are skipped (POST, XMLRPC, and... X-Git-Url: https://git.rkrishnan.org/uri/%3C?a=commitdiff_plain;h=0cd730a7b380d1fb3f8cff269c396ddd83e4f8fa;p=tahoe-lafs%2Ftahoe-lafs.git web: more test work, now all tests either pass or are skipped (POST, XMLRPC, and URI/) --- diff --git a/src/allmydata/dirnode.py b/src/allmydata/dirnode.py index 418d974c..f2743193 100644 --- a/src/allmydata/dirnode.py +++ b/src/allmydata/dirnode.py @@ -364,7 +364,7 @@ class ImmutableDirectoryNode: def get_child_at_path(self, path): if not path: - return self + return defer.succeed(self) if isinstance(path, (str, unicode)): path = path.split("/") childname = path[0] diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 26d48a8f..0f7a3bdc 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -559,56 +559,79 @@ class Web(unittest.TestCase): f.write("contents of %s\n" % filename) f.close() - def test_PUT_NEWDIRURL_localdir(self): # NO + def walk_mynodes(self, node, path=()): + yield path, node + if interfaces.IDirectoryNode.providedBy(node): + for name in sorted(node.children.keys()): + child_uri = node.children[name] + childnode = self.nodes[child_uri] + childpath = path + (name,) + for xpath,xnode in self.walk_mynodes(childnode, childpath): + yield xpath, xnode + + def dump_root(self): + print "NODEWALK" + for path,node in self.walk_mynodes(self.public_root): + print path + + def test_PUT_NEWDIRURL_localdir(self): # YES localdir = os.path.abspath("web/PUT_NEWDIRURL_localdir") # create some files there - fileutil.make_dirs(os.path.join(localdir, "web")) - fileutil.make_dirs(os.path.join(localdir, "web/one")) - fileutil.make_dirs(os.path.join(localdir, "web/two")) - fileutil.make_dirs(os.path.join(localdir, "web/three")) - self.touch(localdir, "web/three/foo.txt") - self.touch(localdir, "web/three/bar.txt") - self.touch(localdir, "web/zap.zip") + fileutil.make_dirs(os.path.join(localdir, "one")) + fileutil.make_dirs(os.path.join(localdir, "one/sub")) + fileutil.make_dirs(os.path.join(localdir, "two")) + fileutil.make_dirs(os.path.join(localdir, "three")) + self.touch(localdir, "three/foo.txt") + self.touch(localdir, "three/bar.txt") + self.touch(localdir, "zap.zip") + d = self.PUT("/vdrive/global/foo/newdir?localdir=%s" % localdir, "") def _check(res): self.failUnless("newdir" in self._foo_node.children) - webnode = self.nodes[self._foo_node.children["newdir"]] - self.failUnlessEqual(sorted(webnode.children.keys()), + newnode = self.nodes[self._foo_node.children["newdir"]] + self.failUnlessEqual(sorted(newnode.children.keys()), sorted(["one", "two", "three", "zap.zip"])) - threenode = self.nodes[webnode.children["three"]] + onenode = self.nodes[newnode.children["one"]] + self.failUnlessEqual(sorted(onenode.children.keys()), + sorted(["sub"])) + threenode = self.nodes[newnode.children["three"]] self.failUnlessEqual(sorted(threenode.children.keys()), sorted(["foo.txt", "bar.txt"])) - barnode = self.nodes[threenode.children["foo.txt"]] + barnode = self.nodes[threenode.children["bar.txt"]] contents = self.files[barnode.get_uri()] - self.failUnlessEqual(contents, "contents of web/three/bar.txt") + self.failUnlessEqual(contents, "contents of three/bar.txt\n") d.addCallback(_check) return d - def test_PUT_NEWDIRURL_localdir_mkdirs(self): # NO + def test_PUT_NEWDIRURL_localdir_mkdirs(self): # YES localdir = os.path.abspath("web/PUT_NEWDIRURL_localdir_mkdirs") # create some files there - fileutil.make_dirs(os.path.join(localdir, "web")) - fileutil.make_dirs(os.path.join(localdir, "web/one")) - fileutil.make_dirs(os.path.join(localdir, "web/two")) - fileutil.make_dirs(os.path.join(localdir, "web/three")) - self.touch(localdir, "web/three/foo.txt") - self.touch(localdir, "web/three/bar.txt") - self.touch(localdir, "web/zap.zip") + fileutil.make_dirs(os.path.join(localdir, "one")) + fileutil.make_dirs(os.path.join(localdir, "one/sub")) + fileutil.make_dirs(os.path.join(localdir, "two")) + fileutil.make_dirs(os.path.join(localdir, "three")) + self.touch(localdir, "three/foo.txt") + self.touch(localdir, "three/bar.txt") + self.touch(localdir, "zap.zip") + d = self.PUT("/vdrive/global/foo/subdir/newdir?localdir=%s" % localdir, "") def _check(res): self.failUnless("subdir" in self._foo_node.children) subnode = self.nodes[self._foo_node.children["subdir"]] self.failUnless("newdir" in subnode.children) - webnode = self.nodes[subnode.children["newdir"]] - self.failUnlessEqual(sorted(webnode.children.keys()), + newnode = self.nodes[subnode.children["newdir"]] + self.failUnlessEqual(sorted(newnode.children.keys()), sorted(["one", "two", "three", "zap.zip"])) - threenode = self.nodes[webnode.children["three"]] + onenode = self.nodes[newnode.children["one"]] + self.failUnlessEqual(sorted(onenode.children.keys()), + sorted(["sub"])) + threenode = self.nodes[newnode.children["three"]] self.failUnlessEqual(sorted(threenode.children.keys()), sorted(["foo.txt", "bar.txt"])) - barnode = self.nodes[threenode.children["foo.txt"]] + barnode = self.nodes[threenode.children["bar.txt"]] contents = self.files[barnode.get_uri()] - self.failUnlessEqual(contents, "contents of web/three/bar.txt") + self.failUnlessEqual(contents, "contents of three/bar.txt\n") d.addCallback(_check) return d diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 974c8ca7..f58d77bb 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -546,6 +546,7 @@ class PUTHandler(rend.Page): if localfile: d.addCallback(self._upload_localfile, localfile, name) elif localdir: + d.addCallback(self._get_or_create_directories, self._path[-1:]) d.addCallback(self._upload_localdir, localdir) elif t == "uri": d.addCallback(self._attach_uri, req.content, name) @@ -611,11 +612,18 @@ class PUTHandler(rend.Page): return d def _upload_localdir(self, node, localdir): + print "PUTHandler._upload_localdir", localdir # build up a list of files to upload all_files = [] all_dirs = [] for root, dirs, files in os.walk(localdir): - path = tuple(root.split(os.sep)) + print "walking", root + if root == localdir: + path = () + else: + relative_root = root[len(localdir)+1:] + path = tuple(relative_root.split(os.sep)) + print " path", path for d in dirs: all_dirs.append(path + (d,)) for f in files: @@ -629,6 +637,7 @@ class PUTHandler(rend.Page): return d def _makedir(self, res, node, dir): + print "_makedir", node, dir d = defer.succeed(None) # get the parent. As long as os.walk gives us parents before # children, this ought to work @@ -638,9 +647,10 @@ class PUTHandler(rend.Page): return d def _upload_one_file(self, res, node, localdir, f): + print "_upload_one_file", node, localdir, f # get the parent. We can be sure this exists because we already # went through and created all the directories we require. - localfile = os.path.join(localdir, f) + localfile = os.path.join(localdir, *f) d = node.get_child_at_path(f[:-1]) d.addCallback(self._upload_localfile, localfile, f[-1]) return d