mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-20 17:52:50 +00:00
added unit test to webish's rename function
added unit tests to test various permutations of the rename function, and some sanity checks on the rename-form function. also added a guard to prevent '/' in from_/to_name in rename calls.
This commit is contained in:
parent
9be3da03f6
commit
920fed7f2a
@ -843,6 +843,57 @@ class Web(unittest.TestCase):
|
||||
d.addCallback(_check)
|
||||
return d
|
||||
|
||||
def test_POST_rename_file(self): # YES
|
||||
d = self.POST("/vdrive/global/foo", t="rename",
|
||||
from_name="bar.txt", to_name='wibble.txt')
|
||||
def _check(res):
|
||||
self.failIf("bar.txt" in self._foo_node.children)
|
||||
self.failUnless("wibble.txt" in self._foo_node.children)
|
||||
d.addCallback(_check)
|
||||
d.addCallback(lambda res: self.GET("/vdrive/global/foo/wibble.txt"))
|
||||
d.addCallback(self.failUnlessIsBarDotTxt)
|
||||
d.addCallback(lambda res: self.GET("/vdrive/global/foo/wibble.txt?t=json"))
|
||||
d.addCallback(self.failUnlessIsBarJSON)
|
||||
return d
|
||||
|
||||
def test_POST_rename_file_slash_fail(self): # YES
|
||||
d = self.POST("/vdrive/global/foo", t="rename",
|
||||
from_name="bar.txt", to_name='kirk/spock.txt')
|
||||
d.addBoth(self.shouldFail, error.Error,
|
||||
"test_POST_rename_file_slash_fail",
|
||||
"400 Bad Request",
|
||||
"to_name= may not contain a slash",
|
||||
)
|
||||
def _check1(res):
|
||||
self.failUnless("bar.txt" in self._foo_node.children)
|
||||
d.addCallback(_check1)
|
||||
d.addCallback(lambda res: self.POST("/vdrive/global", t="rename",
|
||||
from_name="foo/bar.txt", to_name='george.txt'))
|
||||
d.addBoth(self.shouldFail, error.Error,
|
||||
"test_POST_rename_file_slash_fail",
|
||||
"400 Bad Request",
|
||||
"from_name= may not contain a slash",
|
||||
)
|
||||
def _check2(res):
|
||||
self.failUnless("foo" in self.public_root.children)
|
||||
self.failIf("george.txt" in self.public_root.children)
|
||||
self.failUnless("bar.txt" in self._foo_node.children)
|
||||
d.addCallback(_check2)
|
||||
d.addCallback(lambda res: self.GET("/vdrive/global/foo?t=json"))
|
||||
d.addCallback(self.failUnlessIsFooJSON)
|
||||
return d
|
||||
|
||||
def test_POST_rename_dir(self): # YES
|
||||
d = self.POST("/vdrive/global", t="rename",
|
||||
from_name="foo", to_name='plunk')
|
||||
def _check(res):
|
||||
self.failIf("foo" in self.public_root.children)
|
||||
self.failUnless("plunk" in self.public_root.children)
|
||||
d.addCallback(_check)
|
||||
d.addCallback(lambda res: self.GET("/vdrive/global/plunk?t=json"))
|
||||
d.addCallback(self.failUnlessIsFooJSON)
|
||||
return d
|
||||
|
||||
def shouldRedirect(self, res, target):
|
||||
if not isinstance(res, failure.Failure):
|
||||
self.fail("we were expecting to get redirected to %s, not get an"
|
||||
@ -874,6 +925,15 @@ class Web(unittest.TestCase):
|
||||
|
||||
return d
|
||||
|
||||
def test_GET_rename_form(self): # YES
|
||||
d = self.GET("/vdrive/global/foo?t=rename-form&name=bar.txt",
|
||||
followRedirect=True) # XXX [ ] todo: figure out why '.../foo' doesn't work
|
||||
def _check(res):
|
||||
self.failUnless(re.search(r'name="when_done" value=".*vdrive/global/foo/', res))
|
||||
self.failUnless(re.search(r'name="from_name" value="bar\.txt"', res))
|
||||
d.addCallback(_check)
|
||||
return d
|
||||
|
||||
def log(self, res, msg):
|
||||
#print "MSG: %s RES: %s" % (msg, res)
|
||||
log.msg(msg)
|
||||
|
@ -545,6 +545,11 @@ class POSTHandler(rend.Page):
|
||||
raise RuntimeError("rename requires from_name and to_name")
|
||||
if not IDirectoryNode.providedBy(self._node):
|
||||
raise RuntimeError("rename must only be called on directories")
|
||||
for k,v in [ ('from_name', from_name), ('to_name', to_name) ]:
|
||||
if v and "/" in v:
|
||||
req.setResponseCode(http.BAD_REQUEST)
|
||||
req.setHeader("content-type", "text/plain")
|
||||
return "%s= may not contain a slash" % (k,)
|
||||
d = self._node.get(from_name)
|
||||
def add_dest(child):
|
||||
uri = child.get_uri()
|
||||
|
Loading…
x
Reference in New Issue
Block a user