~ubuntuone-control-tower/ubuntuone-storage-protocol/stable-1-6

« back to all changes in this revision

Viewing changes to tests/test_volumes.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2010-11-16 15:10:48 UTC
  • mfrom: (121.1.4 use-packages)
  • Revision ID: tarmac-20101116151048-b0e20j7lorb4yhe1
Switch to using packaged mocker and ubuntuone-dev-tools
Use pyflakes with u1lint and also run pep8
Fix a lot of pylint/pyflakes/pep8 errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
from ubuntuone.storageprotocol import protocol_pb2, volumes
26
26
 
27
27
# let's not get picky about aatributes outside __init__ in tests
28
 
# pylint: disable-msg=W0201
29
28
# pylint: disable=W0201
30
29
 
31
30
PATH = u'~/Documents/pdfs/moño/'
36
35
FREE_BYTES = 1024
37
36
GENERATION = 999
38
37
 
 
38
 
39
39
class VolumeTestCase(unittest.TestCase):
40
40
    """Check Volume data type."""
41
41
 
45
45
    kwargs = dict(volume_id=VOLUME, node_id=NODE,
46
46
                  free_bytes=FREE_BYTES, generation=GENERATION)
47
47
 
48
 
 
49
48
    def setUp(self):
50
49
        """Initialize testing volume."""
51
50
        self.volume = self.volume_class(**self.kwargs)
61
60
        self.assertEquals(FREE_BYTES, self.volume.free_bytes)
62
61
        self.assertEquals(GENERATION, self.volume.generation)
63
62
 
64
 
 
65
63
    def test_creation(self):
66
64
        """Test creation."""
67
65
        self.assert_correct_attributes()
70
68
        """Test class inheritance."""
71
69
        self.assertTrue(isinstance(self.volume, volumes.Volume))
72
70
 
73
 
 
74
71
    def test_from_params(self):
75
72
        """Test creation using from_params."""
76
73
        self.volume = self.volume_class.from_params(**self.kwargs)
78
75
 
79
76
    def test_from_msg(self):
80
77
        """Test creation using from_msg."""
81
 
        self.assertRaises(NotImplementedError, self.volume_class.from_msg, None)
 
78
        self.assertRaises(NotImplementedError,
 
79
                          self.volume_class.from_msg, None)
82
80
 
83
81
    def test_is_equal(self):
84
82
        """Test object equality."""
97
95
class ShareTestCase(VolumeTestCase):
98
96
    """Check Share data type."""
99
97
 
100
 
    # pylint: disable-msg=W0212
101
98
    # pylint: disable=W0212
102
99
    to_me = volumes._direction_prot2nice[protocol_pb2.Shares.TO_ME]
103
100
    only_view = volumes._access_prot2nice[protocol_pb2.Shares.VIEW]
123
120
    def test_from_msg(self):
124
121
        """Test creation using from_msg."""
125
122
        message = protocol_pb2.Shares()
126
 
        # pylint: disable-msg=W0201
127
123
        # pylint: disable=W0201
128
124
        message.share_id = str(VOLUME)
129
125
        message.subtree = str(NODE)
144
140
                  free_bytes=FREE_BYTES, generation=GENERATION,
145
141
                  suggested_path=PATH)
146
142
 
147
 
 
148
143
    def assert_correct_attributes(self):
149
144
        """Assert over attribute correctness."""
150
145
        super(UDFTestCase, self).assert_correct_attributes()
151
146
        self.assertEquals(PATH, self.volume.suggested_path)
152
147
 
153
 
 
154
148
    def test_from_msg(self):
155
149
        """Test creation using from_msg."""
156
150
        message = protocol_pb2.UDFs()
157
 
        # pylint: disable-msg=W0201
158
151
        # pylint: disable=W0201
159
152
        message.volume = str(VOLUME)
160
153
        message.node = str(NODE)
172
165
    volume_class = volumes.RootVolume
173
166
    kwargs = dict(node_id=NODE, free_bytes=FREE_BYTES, generation=GENERATION)
174
167
 
175
 
 
176
168
    def test_from_msg(self):
177
169
        """Test creation using from_msg."""
178
170
        message = protocol_pb2.Root()
179
 
        # pylint: disable-msg=W0201
180
171
        # pylint: disable=W0201
181
172
        message.node = str(NODE)
182
173
        message.generation = GENERATION