]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
exercise all branches of new helper "get_filenode_metadata"
authorzancas <zancas@leastauthority.com>
Tue, 7 Oct 2014 23:36:03 +0000 (17:36 -0600)
committerzancas <zancas@leastauthority.com>
Fri, 10 Oct 2014 17:27:27 +0000 (11:27 -0600)
Note fix following issues from origial commit:

refactor unittests, fix style, add test

(0) use CommonFixture as mixin to increase DRYness
(1) self.failUnlessIn('size', metadata.keys()) --> self.failUnlessIn('size', metdata)
(2) test_size_is_not_None --> test_size_is_0 AND test_size_is_1000

src/allmydata/test/test_json_metadata.py [new file with mode: 0644]

diff --git a/src/allmydata/test/test_json_metadata.py b/src/allmydata/test/test_json_metadata.py
new file mode 100644 (file)
index 0000000..ab51854
--- /dev/null
@@ -0,0 +1,48 @@
+import mock
+
+from twisted.trial.unittest import TestCase
+
+from allmydata.web.common import get_filenode_metadata, SDMF_VERSION, MDMF_VERSION
+from allmydata.immutable.filenode import ImmutableFileNode
+
+class CommonFixture(object):
+    def setUp(self):
+        self.mockfilenode = mock.Mock()
+
+    def test_size_is_0(self):
+        """If get_size doesn't return None the returned metadata must contain "size"."""
+        self.mockfilenode.get_size.return_value = 0
+        metadata = get_filenode_metadata(self.mockfilenode)
+        self.failUnlessIn('size', metadata)
+
+    def test_size_is_1000(self):
+        """1000 is sufficiently large to guarantee the cap is not a literal."""
+        self.mockfilenode.get_size.return_value = 1000
+        metadata = get_filenode_metadata(self.mockfilenode)
+        self.failUnlessIn('size', metadata)
+
+    def test_size_is_None(self):
+        """If get_size returns None the returned metadata must not contain "size"."""
+        self.mockfilenode.get_size.return_value = None
+        metadata = get_filenode_metadata(self.mockfilenode)
+        self.failIfIn('size', metadata)
+
+
+class Test_GetFileNodeMetaData_Immutable(CommonFixture, TestCase):
+    def setUp(self):
+        CommonFixture.setUp(self)
+        self.mockfilenode.is_mutable.return_value = False
+
+
+class Test_GetFileNodeMetaData_SDMF(CommonFixture, TestCase):
+    def setUp(self):
+        CommonFixture.setUp(self)
+        self.mockfilenode.is_mutable.return_value = True
+        self.mockfilenode.get_version.return_value = SDMF_VERSION
+
+
+class Test_GetFileNodeMetaData_MDMF(CommonFixture, TestCase):
+    def setUp(self):
+        CommonFixture.setUp(self)
+        self.mockfilenode.is_mutable.return_value = True
+        self.mockfilenode.get_version.return_value = MDMF_VERSION