web: handle PUT mutable=true properly

This commit is contained in:
Brian Warner 2008-05-20 12:36:02 -07:00
parent d72f75019f
commit e323019708
2 changed files with 33 additions and 2 deletions

View File

@ -587,6 +587,24 @@ class Web(WebMixin, unittest.TestCase):
self.NEWFILE_CONTENTS))
return d
def test_PUT_NEWFILEURL_mutable(self):
d = self.PUT(self.public_url + "/foo/new.txt?mutable=true",
self.NEWFILE_CONTENTS)
# TODO: we lose the response code, so we can't check this
#self.failUnlessEqual(responsecode, 201)
def _check_uri(res):
u = uri.from_string_mutable_filenode(res)
self.failUnless(u.is_mutable())
self.failIf(u.is_readonly())
return res
d.addCallback(_check_uri)
d.addCallback(self.failUnlessURIMatchesChild, self._foo_node, u"new.txt")
d.addCallback(lambda res:
self.failUnlessMutableChildContentsAre(self._foo_node,
u"new.txt",
self.NEWFILE_CONTENTS))
return d
def test_PUT_NEWFILEURL_replace(self):
d = self.PUT(self.public_url + "/foo/bar.txt", self.NEWFILE_CONTENTS)
# TODO: we lose the response code, so we can't check this

View File

@ -22,8 +22,21 @@ class ReplaceMeMixin:
# a new file is being uploaded in our place.
req = IRequest(ctx)
client = IClient(ctx)
uploadable = FileHandle(req.content, convergence=client.convergence)
d = self.parentnode.add_file(self.name, uploadable, overwrite=replace)
mutable = boolean_of_arg(get_arg(req, "mutable", "false"))
if mutable:
req.content.seek(0)
data = req.content.read()
d = client.create_mutable_file(data)
def _uploaded(newnode):
d2 = self.parentnode.set_node(self.name, newnode,
overwrite=replace)
d2.addCallback(lambda res: newnode)
return d2
d.addCallback(_uploaded)
else:
uploadable = FileHandle(req.content, convergence=client.convergence)
d = self.parentnode.add_file(self.name, uploadable,
overwrite=replace)
def _done(filenode):
log.msg("webish upload complete",
facility="tahoe.webish", level=log.NOISY)