]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_filenode.py : improve coverage of mutable filenode, fix a bug in __hash__
authorBrian Warner <warner@allmydata.com>
Tue, 4 Mar 2008 21:01:28 +0000 (14:01 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 4 Mar 2008 21:01:28 +0000 (14:01 -0700)
src/allmydata/mutable.py
src/allmydata/test/test_filenode.py

index 20d1bb8d4632239ed10bf24a9dae6a86c2283594..925a286a64051daf013bfab684e77cbdbee94fc1 100644 (file)
@@ -1580,13 +1580,13 @@ class MutableFileNode:
         return self._uri.is_readonly()
 
     def __hash__(self):
-        return hash((self.__class__, self.uri))
+        return hash((self.__class__, self._uri))
     def __cmp__(self, them):
         if cmp(type(self), type(them)):
             return cmp(type(self), type(them))
         if cmp(self.__class__, them.__class__):
             return cmp(self.__class__, them.__class__)
-        return cmp(self.uri, them.uri)
+        return cmp(self._uri, them._uri)
 
     def get_verifier(self):
         return IMutableFileURI(self._uri).get_verifier()
index 9929b7783d298b9a323e6d384ed7244f46780ae0..46300df83eb24a4487a43a17b737776e1ed6e49a 100644 (file)
@@ -1,6 +1,7 @@
 
 from twisted.trial import unittest
-from allmydata import filenode, uri, download
+from allmydata import filenode, uri, download, mutable
+from allmydata.util import hashutil
 
 class NotANode:
     pass
@@ -57,3 +58,48 @@ class Node(unittest.TestCase):
         d.addCallback(_check)
         return d
 
+    def test_mutable_filenode(self):
+        client = None
+        wk = "\x00"*16
+        fp = "\x00"*32
+        rk = hashutil.ssk_readkey_hash(wk)
+        si = hashutil.ssk_storage_index_hash(rk)
+
+        u = uri.WriteableSSKFileURI("\x00"*16, "\x00"*32)
+        n = mutable.MutableFileNode(client).init_from_uri(u)
+
+        self.failUnlessEqual(n.get_writekey(), wk)
+        self.failUnlessEqual(n.get_readkey(), rk)
+        self.failUnlessEqual(n.get_storage_index(), si)
+        # these itmes are populated on first read (or create), so until that
+        # happens they'll be None
+        self.failUnlessEqual(n.get_privkey(), None)
+        self.failUnlessEqual(n.get_encprivkey(), None)
+        self.failUnlessEqual(n.get_pubkey(), None)
+
+        self.failUnlessEqual(n.get_uri(), u.to_string())
+        self.failUnlessEqual(n.get_readonly_uri(), u.get_readonly().to_string())
+        self.failUnlessEqual(n.is_mutable(), True)
+        self.failUnlessEqual(n.is_readonly(), False)
+
+        n2 = mutable.MutableFileNode(client).init_from_uri(u)
+        self.failUnlessEqual(n, n2)
+        self.failIfEqual(n, "not even the right type")
+        self.failIfEqual(n, u) # not the right class
+        d = {n: "can these be used as dictionary keys?"}
+        d[n2] = "replace the old one"
+        self.failUnlessEqual(len(d), 1)
+
+        nro = n.get_readonly()
+        self.failUnless(isinstance(nro, mutable.MutableFileNode))
+
+        self.failUnlessEqual(nro.get_readonly(), nro)
+        nro_u = nro.get_uri()
+        self.failUnlessEqual(nro_u, nro.get_readonly_uri())
+        self.failUnlessEqual(nro_u, u.get_readonly().to_string())
+        self.failUnlessEqual(nro.is_mutable(), True)
+        self.failUnlessEqual(nro.is_readonly(), True)
+
+        v = n.get_verifier()
+        self.failUnless(isinstance(v, uri.SSKVerifierURI))
+