2014-10-07 23:36:03 +00:00
|
|
|
|
|
|
|
from twisted.trial.unittest import TestCase
|
|
|
|
|
|
|
|
from allmydata.web.common import get_filenode_metadata, SDMF_VERSION, MDMF_VERSION
|
2014-10-10 19:39:18 +00:00
|
|
|
|
2014-10-07 23:36:03 +00:00
|
|
|
|
2015-07-17 21:03:53 +00:00
|
|
|
class MockFileNode(object):
|
|
|
|
def __init__(self, size, mutable_version=None):
|
|
|
|
self.size = size
|
|
|
|
self.mutable_version = mutable_version
|
|
|
|
|
|
|
|
def get_size(self):
|
|
|
|
return self.size
|
|
|
|
|
|
|
|
def is_mutable(self):
|
|
|
|
return self.mutable_version is not None
|
2014-10-07 23:36:03 +00:00
|
|
|
|
2015-07-17 21:03:53 +00:00
|
|
|
def get_version(self):
|
|
|
|
if self.mutable_version is None:
|
|
|
|
raise AttributeError()
|
|
|
|
return self.mutable_version
|
|
|
|
|
|
|
|
|
|
|
|
class CommonFixture(object):
|
2014-10-07 23:36:03 +00:00
|
|
|
def test_size_is_0(self):
|
|
|
|
"""If get_size doesn't return None the returned metadata must contain "size"."""
|
2015-07-17 21:03:53 +00:00
|
|
|
mockfilenode = MockFileNode(0, mutable_version=self.mutable_version)
|
|
|
|
metadata = get_filenode_metadata(mockfilenode)
|
|
|
|
self.failUnlessEqual(metadata['size'], 0)
|
2014-10-07 23:36:03 +00:00
|
|
|
|
|
|
|
def test_size_is_1000(self):
|
|
|
|
"""1000 is sufficiently large to guarantee the cap is not a literal."""
|
2015-07-17 21:03:53 +00:00
|
|
|
mockfilenode = MockFileNode(1000, mutable_version=self.mutable_version)
|
|
|
|
metadata = get_filenode_metadata(mockfilenode)
|
|
|
|
self.failUnlessEqual(metadata['size'], 1000)
|
2014-10-07 23:36:03 +00:00
|
|
|
|
|
|
|
def test_size_is_None(self):
|
|
|
|
"""If get_size returns None the returned metadata must not contain "size"."""
|
2015-07-17 21:03:53 +00:00
|
|
|
mockfilenode = MockFileNode(None, mutable_version=self.mutable_version)
|
|
|
|
metadata = get_filenode_metadata(mockfilenode)
|
2014-10-07 23:36:03 +00:00
|
|
|
self.failIfIn('size', metadata)
|
|
|
|
|
|
|
|
|
|
|
|
class Test_GetFileNodeMetaData_Immutable(CommonFixture, TestCase):
|
|
|
|
def setUp(self):
|
2015-07-17 21:03:53 +00:00
|
|
|
self.mutable_version = None
|
2014-10-07 23:36:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Test_GetFileNodeMetaData_SDMF(CommonFixture, TestCase):
|
|
|
|
def setUp(self):
|
2015-07-17 21:03:53 +00:00
|
|
|
self.mutable_version = SDMF_VERSION
|
2014-10-07 23:36:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Test_GetFileNodeMetaData_MDMF(CommonFixture, TestCase):
|
|
|
|
def setUp(self):
|
2015-07-17 21:03:53 +00:00
|
|
|
self.mutable_version = MDMF_VERSION
|