1 | """ |
---|
2 | Ported to Python 3. |
---|
3 | """ |
---|
4 | |
---|
5 | from twisted.trial.unittest import TestCase |
---|
6 | |
---|
7 | from allmydata.web.common import get_filenode_metadata, SDMF_VERSION, MDMF_VERSION |
---|
8 | |
---|
9 | |
---|
10 | class MockFileNode(object): |
---|
11 | def __init__(self, size, mutable_version=None): |
---|
12 | self.size = size |
---|
13 | self.mutable_version = mutable_version |
---|
14 | |
---|
15 | def get_size(self): |
---|
16 | return self.size |
---|
17 | |
---|
18 | def is_mutable(self): |
---|
19 | return self.mutable_version is not None |
---|
20 | |
---|
21 | def get_version(self): |
---|
22 | if self.mutable_version is None: |
---|
23 | raise AttributeError() |
---|
24 | return self.mutable_version |
---|
25 | |
---|
26 | |
---|
27 | class CommonFixture(object): |
---|
28 | def test_size_is_0(self): |
---|
29 | """If get_size doesn't return None the returned metadata must contain "size".""" |
---|
30 | mockfilenode = MockFileNode(0, mutable_version=self.mutable_version) |
---|
31 | metadata = get_filenode_metadata(mockfilenode) |
---|
32 | self.failUnlessEqual(metadata['size'], 0) |
---|
33 | |
---|
34 | def test_size_is_1000(self): |
---|
35 | """1000 is sufficiently large to guarantee the cap is not a literal.""" |
---|
36 | mockfilenode = MockFileNode(1000, mutable_version=self.mutable_version) |
---|
37 | metadata = get_filenode_metadata(mockfilenode) |
---|
38 | self.failUnlessEqual(metadata['size'], 1000) |
---|
39 | |
---|
40 | def test_size_is_None(self): |
---|
41 | """If get_size returns None the returned metadata must not contain "size".""" |
---|
42 | mockfilenode = MockFileNode(None, mutable_version=self.mutable_version) |
---|
43 | metadata = get_filenode_metadata(mockfilenode) |
---|
44 | self.failIfIn('size', metadata) |
---|
45 | |
---|
46 | |
---|
47 | class Test_GetFileNodeMetaData_Immutable(CommonFixture, TestCase): |
---|
48 | def setUp(self): |
---|
49 | self.mutable_version = None |
---|
50 | |
---|
51 | |
---|
52 | class Test_GetFileNodeMetaData_SDMF(CommonFixture, TestCase): |
---|
53 | def setUp(self): |
---|
54 | self.mutable_version = SDMF_VERSION |
---|
55 | |
---|
56 | |
---|
57 | class Test_GetFileNodeMetaData_MDMF(CommonFixture, TestCase): |
---|
58 | def setUp(self): |
---|
59 | self.mutable_version = MDMF_VERSION |
---|