source: trunk/src/allmydata/test/test_json_metadata.py

Last change on this file was 1cfe843d, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-22T23:40:25Z

more python2 removal

  • Property mode set to 100644
File size: 1.8 KB
Line 
1"""
2Ported to Python 3.
3"""
4
5from twisted.trial.unittest import TestCase
6
7from allmydata.web.common import get_filenode_metadata, SDMF_VERSION, MDMF_VERSION
8
9
10class 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
27class 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
47class Test_GetFileNodeMetaData_Immutable(CommonFixture, TestCase):
48    def setUp(self):
49        self.mutable_version = None
50
51
52class Test_GetFileNodeMetaData_SDMF(CommonFixture, TestCase):
53    def setUp(self):
54        self.mutable_version = SDMF_VERSION
55
56
57class Test_GetFileNodeMetaData_MDMF(CommonFixture, TestCase):
58    def setUp(self):
59        self.mutable_version = MDMF_VERSION
Note: See TracBrowser for help on using the repository browser.