Additional tests for MDMF URIs and for zero-length files. refs #393

This commit is contained in:
david-sarah 2011-08-22 18:15:32 -07:00
parent ac7b8400d4
commit 88989a4ea2
3 changed files with 58 additions and 21 deletions

View File

@ -406,3 +406,6 @@ class GridTestMixin:
if return_response: if return_response:
d.addCallback(_got_data) d.addCallback(_got_data)
return factory.deferred return factory.deferred
def PUT(self, urlpath, **kwargs):
return self.GET(urlpath, method="PUT", **kwargs)

View File

@ -41,9 +41,11 @@ class MemAccum:
setup_py_uri = "URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861" setup_py_uri = "URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861"
one_uri = "URI:LIT:n5xgk" # LIT for "one" one_uri = "URI:LIT:n5xgk" # LIT for "one"
mut_write_uri = "URI:SSK:vfvcbdfbszyrsaxchgevhmmlii:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq" mut_write_uri = "URI:SSK:vfvcbdfbszyrsaxchgevhmmlii:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq"
mdmf_write_uri = "URI:MDMF:x533rhbm6kiehzl5kj3s44n5ie:4gif5rhneyd763ouo5qjrgnsoa3bg43xycy4robj2rf3tvmhdl3a:1:131072"
empty_litdir_uri = "URI:DIR2-LIT:" empty_litdir_uri = "URI:DIR2-LIT:"
tiny_litdir_uri = "URI:DIR2-LIT:gqytunj2onug64tufqzdcosvkjetutcjkq5gw4tvm5vwszdgnz5hgyzufqydulbshj5x2lbm" # contains one child which is itself also LIT tiny_litdir_uri = "URI:DIR2-LIT:gqytunj2onug64tufqzdcosvkjetutcjkq5gw4tvm5vwszdgnz5hgyzufqydulbshj5x2lbm" # contains one child which is itself also LIT
mut_read_uri = "URI:SSK-RO:jf6wkflosyvntwxqcdo7a54jvm:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq" mut_read_uri = "URI:SSK-RO:jf6wkflosyvntwxqcdo7a54jvm:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq"
mdmf_read_uri = "URI:MDMF-RO:d4cydxselputycfzkw6qgz4zv4:4gif5rhneyd763ouo5qjrgnsoa3bg43xycy4robj2rf3tvmhdl3a:1:131072"
future_write_uri = "x-tahoe-crazy://I_am_from_the_future." future_write_uri = "x-tahoe-crazy://I_am_from_the_future."
future_read_uri = "x-tahoe-crazy-readonly://I_am_from_the_future." future_read_uri = "x-tahoe-crazy-readonly://I_am_from_the_future."
future_nonascii_write_uri = u"x-tahoe-even-more-crazy://I_am_from_the_future_rw_\u263A".encode('utf-8') future_nonascii_write_uri = u"x-tahoe-even-more-crazy://I_am_from_the_future_rw_\u263A".encode('utf-8')
@ -586,6 +588,7 @@ class Dirnode(GridTestMixin, unittest.TestCase,
u"two": (nm.create_from_cap(setup_py_uri), u"two": (nm.create_from_cap(setup_py_uri),
{"metakey": "metavalue"}), {"metakey": "metavalue"}),
u"mut": (nm.create_from_cap(mut_write_uri, mut_read_uri), {}), u"mut": (nm.create_from_cap(mut_write_uri, mut_read_uri), {}),
u"mdmf": (nm.create_from_cap(mdmf_write_uri, mdmf_read_uri), {}),
u"fut": (nm.create_from_cap(future_write_uri, future_read_uri), {}), u"fut": (nm.create_from_cap(future_write_uri, future_read_uri), {}),
u"fro": (nm.create_from_cap(None, future_read_uri), {}), u"fro": (nm.create_from_cap(None, future_read_uri), {}),
u"fut-unic": (nm.create_from_cap(future_nonascii_write_uri, future_nonascii_read_uri), {}), u"fut-unic": (nm.create_from_cap(future_nonascii_write_uri, future_nonascii_read_uri), {}),
@ -619,11 +622,12 @@ class Dirnode(GridTestMixin, unittest.TestCase,
def _check_kids(children): def _check_kids(children):
self.failUnlessReallyEqual(set(children.keys()), self.failUnlessReallyEqual(set(children.keys()),
set([one_nfc, u"two", u"mut", u"fut", u"fro", set([one_nfc, u"two", u"mut", u"mdmf", u"fut", u"fro",
u"fut-unic", u"fro-unic", u"empty_litdir", u"tiny_litdir"])) u"fut-unic", u"fro-unic", u"empty_litdir", u"tiny_litdir"]))
one_node, one_metadata = children[one_nfc] one_node, one_metadata = children[one_nfc]
two_node, two_metadata = children[u"two"] two_node, two_metadata = children[u"two"]
mut_node, mut_metadata = children[u"mut"] mut_node, mut_metadata = children[u"mut"]
mdmf_node, mdmf_metadata = children[u"mdmf"]
fut_node, fut_metadata = children[u"fut"] fut_node, fut_metadata = children[u"fut"]
fro_node, fro_metadata = children[u"fro"] fro_node, fro_metadata = children[u"fro"]
futna_node, futna_metadata = children[u"fut-unic"] futna_node, futna_metadata = children[u"fut-unic"]
@ -645,6 +649,10 @@ class Dirnode(GridTestMixin, unittest.TestCase,
self.failUnlessReallyEqual(mut_node.get_readonly_uri(), mut_read_uri) self.failUnlessReallyEqual(mut_node.get_readonly_uri(), mut_read_uri)
self.failUnless(isinstance(mut_metadata, dict), mut_metadata) self.failUnless(isinstance(mut_metadata, dict), mut_metadata)
self.failUnlessReallyEqual(mdmf_node.get_uri(), mdmf_write_uri)
self.failUnlessReallyEqual(mdmf_node.get_readonly_uri(), mdmf_read_uri)
self.failUnless(isinstance(mdmf_metadata, dict), mdmf_metadata)
self.failUnless(fut_node.is_unknown()) self.failUnless(fut_node.is_unknown())
self.failUnlessReallyEqual(fut_node.get_uri(), future_write_uri) self.failUnlessReallyEqual(fut_node.get_uri(), future_write_uri)
self.failUnlessReallyEqual(fut_node.get_readonly_uri(), "ro." + future_read_uri) self.failUnlessReallyEqual(fut_node.get_readonly_uri(), "ro." + future_read_uri)
@ -852,6 +860,18 @@ class Dirnode(GridTestMixin, unittest.TestCase,
"is not allowed in an immutable directory", "is not allowed in an immutable directory",
c.create_immutable_dirnode, c.create_immutable_dirnode,
bad_kids5)) bad_kids5))
bad_kids6 = {one_nfd: (nm.create_from_cap(mdmf_write_uri), {})}
d.addCallback(lambda ign:
self.shouldFail(MustBeDeepImmutableError, "bad_kids6",
"is not allowed in an immutable directory",
c.create_immutable_dirnode,
bad_kids6))
bad_kids7 = {one_nfd: (nm.create_from_cap(mdmf_read_uri), {})}
d.addCallback(lambda ign:
self.shouldFail(MustBeDeepImmutableError, "bad_kids7",
"is not allowed in an immutable directory",
c.create_immutable_dirnode,
bad_kids7))
d.addCallback(lambda ign: c.create_immutable_dirnode({})) d.addCallback(lambda ign: c.create_immutable_dirnode({}))
def _created_empty(dn): def _created_empty(dn):
self.failUnless(isinstance(dn, dirnode.DirectoryNode)) self.failUnless(isinstance(dn, dirnode.DirectoryNode))
@ -903,12 +923,18 @@ class Dirnode(GridTestMixin, unittest.TestCase,
d.addCallback(_check_kids) d.addCallback(_check_kids)
d.addCallback(lambda ign: n.get(u"subdir")) d.addCallback(lambda ign: n.get(u"subdir"))
d.addCallback(lambda sd: self.failIf(sd.is_mutable())) d.addCallback(lambda sd: self.failIf(sd.is_mutable()))
bad_kids = {one_nfd: (nm.create_from_cap(mut_write_uri), {})} bad_kids8 = {one_nfd: (nm.create_from_cap(mut_write_uri), {})}
d.addCallback(lambda ign: d.addCallback(lambda ign:
self.shouldFail(MustBeDeepImmutableError, "YZ", self.shouldFail(MustBeDeepImmutableError, "bad_kids8",
"is not allowed in an immutable directory", "is not allowed in an immutable directory",
n.create_subdirectory, n.create_subdirectory,
u"sub2", bad_kids, mutable=False)) u"sub2", bad_kids8, mutable=False))
bad_kids9 = {one_nfd: (nm.create_from_cap(mdmf_write_uri), {})}
d.addCallback(lambda ign:
self.shouldFail(MustBeDeepImmutableError, "bad_kids9",
"is not allowed in an immutable directory",
n.create_subdirectory,
u"sub2", bad_kids9, mutable=False))
return d return d
d.addCallback(_made_parent) d.addCallback(_made_parent)
return d return d
@ -1607,9 +1633,7 @@ class Dirnode2(testutil.ReallyEqualMixin, testutil.ShouldFailMixin, unittest.Tes
self.failUnlessReallyEqual(strip_prefix_for_ro("imm.foo", True), "foo") self.failUnlessReallyEqual(strip_prefix_for_ro("imm.foo", True), "foo")
def test_unknownnode(self): def test_unknownnode(self):
mut_write_uri = "URI:SSK:vfvcbdfbszyrsaxchgevhmmlii:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq" lit_uri = one_uri
mut_read_uri = "URI:SSK-RO:jf6wkflosyvntwxqcdo7a54jvm:euw4iw7bbnkrrwpzuburbhppuxhc3gwxv26f6imekhz7zyw2ojnq"
lit_uri = "URI:LIT:n5xgk"
# This does not attempt to be exhaustive. # This does not attempt to be exhaustive.
no_no = [# Opaque node, but not an error. no_no = [# Opaque node, but not an error.
@ -1622,12 +1646,15 @@ class Dirnode2(testutil.ReallyEqualMixin, testutil.ShouldFailMixin, unittest.Tes
( 3, UnknownNode("foo", None, deep_immutable=True)), ( 3, UnknownNode("foo", None, deep_immutable=True)),
( 4, UnknownNode("ro.foo", None, deep_immutable=True)), ( 4, UnknownNode("ro.foo", None, deep_immutable=True)),
( 5, UnknownNode("ro." + mut_read_uri, None, deep_immutable=True)), ( 5, UnknownNode("ro." + mut_read_uri, None, deep_immutable=True)),
( 5.1, UnknownNode("ro." + mdmf_read_uri, None, deep_immutable=True)),
( 6, UnknownNode("URI:SSK-RO:foo", None, deep_immutable=True)), ( 6, UnknownNode("URI:SSK-RO:foo", None, deep_immutable=True)),
( 7, UnknownNode("URI:SSK:foo", None)), ( 7, UnknownNode("URI:SSK:foo", None)),
] ]
must_be_ro = [# These are errors because a readonly constraint is not met. must_be_ro = [# These are errors because a readonly constraint is not met.
( 8, UnknownNode("ro." + mut_write_uri, None)), ( 8, UnknownNode("ro." + mut_write_uri, None)),
( 8.1, UnknownNode("ro." + mdmf_write_uri, None)),
( 9, UnknownNode(None, "ro." + mut_write_uri)), ( 9, UnknownNode(None, "ro." + mut_write_uri)),
( 9.1, UnknownNode(None, "ro." + mdmf_write_uri)),
] ]
must_be_imm = [# These are errors because an immutable constraint is not met. must_be_imm = [# These are errors because an immutable constraint is not met.
(10, UnknownNode(None, "ro.URI:SSK-RO:foo", deep_immutable=True)), (10, UnknownNode(None, "ro.URI:SSK-RO:foo", deep_immutable=True)),
@ -1637,7 +1664,9 @@ class Dirnode2(testutil.ReallyEqualMixin, testutil.ShouldFailMixin, unittest.Tes
(14, UnknownNode("bar", "imm.foo", deep_immutable=True)), (14, UnknownNode("bar", "imm.foo", deep_immutable=True)),
(15, UnknownNode("bar", "imm." + lit_uri, deep_immutable=True)), (15, UnknownNode("bar", "imm." + lit_uri, deep_immutable=True)),
(16, UnknownNode("imm." + mut_write_uri, None)), (16, UnknownNode("imm." + mut_write_uri, None)),
(16.1, UnknownNode("imm." + mdmf_write_uri, None)),
(17, UnknownNode("imm." + mut_read_uri, None)), (17, UnknownNode("imm." + mut_read_uri, None)),
(17.1, UnknownNode("imm." + mdmf_read_uri, None)),
(18, UnknownNode("bar", "imm.foo")), (18, UnknownNode("bar", "imm.foo")),
] ]
bad_uri = [# These are errors because the URI is bad once we've stripped the prefix. bad_uri = [# These are errors because the URI is bad once we've stripped the prefix.

View File

@ -2920,15 +2920,20 @@ class Version(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin, \
self.small_data = "test data" * 10 # about 90 B; SDMF self.small_data = "test data" * 10 # about 90 B; SDMF
def do_upload_mdmf(self): def do_upload(self):
d = self.nm.create_mutable_file(MutableData(self.data), d1 = self.nm.create_mutable_file(MutableData(self.data),
version=MDMF_VERSION) version=MDMF_VERSION)
def _then(n): d2 = self.nm.create_mutable_file(MutableData(self.small_data))
assert isinstance(n, MutableFileNode) dl = gatherResults([d1, d2])
self.mdmf_node = n def _then((n1, n2)):
return n assert isinstance(n1, MutableFileNode)
d.addCallback(_then) assert isinstance(n2, MutableFileNode)
return d
self.mdmf_node = n1
self.sdmf_node = n2
dl.addCallback(_then)
return dl
def do_upload_sdmf(self): def do_upload_sdmf(self):
d = self.nm.create_mutable_file(MutableData(self.small_data)) d = self.nm.create_mutable_file(MutableData(self.small_data))
@ -3242,21 +3247,21 @@ class Version(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin, \
return d return d
def test_read(self): def test_read(self):
d = self.do_upload_mdmf() d = self.mdmf_node.get_best_readable_version()
d.addCallback(lambda ign: self.mdmf_node.get_best_readable_version())
def _read_data(version): def _read_data(version):
c = consumer.MemoryConsumer() c = consumer.MemoryConsumer()
d2 = defer.succeed(None) d2 = defer.succeed(None)
d2.addCallback(lambda ignored: version.read(c)) d2.addCallback(lambda ignored: version.read(c))
d2.addCallback(lambda ignored: d2.addCallback(lambda ignored:
self.failUnlessEqual("".join(c.chunks), self.data)) self.failUnlessEqual(expected, "".join(c.chunks)))
return d2 return d2
d.addCallback(_read_data) d.addCallback(_read_data)
d.addCallback(lambda ignored: node.download_best_version())
d.addCallback(lambda data: self.failUnlessEqual(expected, data))
return d return d
def test_download_best_version(self): def test_download_best_version(self):
d = self.do_upload() d = self.mdmf_node.download_best_version()
d.addCallback(lambda ign: self.mdmf_node.download_best_version())
d.addCallback(lambda data: d.addCallback(lambda data:
self.failUnlessEqual(data, self.data)) self.failUnlessEqual(data, self.data))
d.addCallback(lambda ignored: d.addCallback(lambda ignored: