From: zancas Date: Tue, 7 Oct 2014 23:36:03 +0000 (-0600) Subject: exercise all branches of new helper "get_filenode_metadata" X-Git-Tag: allmydata-tahoe-1.10.1a1~114^2~1 X-Git-Url: https://git.rkrishnan.org/pf/content/%22news.html/statistics?a=commitdiff_plain;h=1545e14076137e44b2b14b44d90f83a8a24d3750;p=tahoe-lafs%2Ftahoe-lafs.git exercise all branches of new helper "get_filenode_metadata" 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 --- diff --git a/src/allmydata/test/test_json_metadata.py b/src/allmydata/test/test_json_metadata.py new file mode 100644 index 00000000..ab51854a --- /dev/null +++ b/src/allmydata/test/test_json_metadata.py @@ -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