~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to test/unit/common/test_constraints.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2013-08-13 10:37:13 UTC
  • mfrom: (1.2.21)
  • Revision ID: package-import@ubuntu.com-20130813103713-1ctbx4zifyljs2aq
Tags: 1.9.1-0ubuntu1
[ James Page ]
* d/control: Update VCS fields for new branch locations.

[ Chuck Short ]
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# limitations under the License.
15
15
 
16
16
import unittest
 
17
import mock
 
18
 
17
19
from test.unit import MockTrue
18
20
 
19
21
from swift.common.swob import HTTPBadRequest, Request
24
26
 
25
27
class TestConstraints(unittest.TestCase):
26
28
 
 
29
    def assertIn(self, member, container, msg=None):
 
30
        """Copied from 2.7"""
 
31
        if member not in container:
 
32
            standardMsg = '%s not found in %s' % (safe_repr(member),
 
33
                                                  safe_repr(container))
 
34
            self.fail(self._formatMessage(msg, standardMsg))
 
35
 
27
36
    def test_check_metadata_empty(self):
28
37
        headers = {}
29
38
        self.assertEquals(constraints.check_metadata(Request.blank('/',
48
57
        headers = {'X-Object-Meta-%s' % name: 'v'}
49
58
        self.assertEquals(constraints.check_metadata(Request.blank('/',
50
59
            headers=headers), 'object').status_int, HTTP_BAD_REQUEST)
 
60
        self.assertIn(('X-Object-Meta-%s' % name).lower(),
 
61
            constraints.check_metadata(Request.blank('/', headers=headers),
 
62
                                                     'object').body.lower())
51
63
 
52
64
    def test_check_metadata_value_length(self):
53
65
        value = 'a' * constraints.MAX_META_VALUE_LENGTH
58
70
        headers = {'X-Object-Meta-Name': value}
59
71
        self.assertEquals(constraints.check_metadata(Request.blank('/',
60
72
            headers=headers), 'object').status_int, HTTP_BAD_REQUEST)
 
73
        self.assertIn('x-object-meta-name',
 
74
            constraints.check_metadata(Request.blank('/', headers=headers),
 
75
                                                     'object').body.lower())
 
76
        self.assertIn(str(constraints.MAX_META_VALUE_LENGTH),
 
77
            constraints.check_metadata(Request.blank('/', headers=headers),
 
78
                                                     'object').body)
61
79
 
62
80
    def test_check_metadata_count(self):
63
81
        headers = {}
170
188
 
171
189
    def test_check_mount(self):
172
190
        self.assertFalse(constraints.check_mount('', ''))
173
 
        constraints.os = MockTrue()  # mock os module
174
 
        self.assertTrue(constraints.check_mount('/srv', '1'))
175
 
        self.assertTrue(constraints.check_mount('/srv', 'foo-bar'))
176
 
        self.assertTrue(constraints.check_mount('/srv', '003ed03c-242a-4b2f-bee9-395f801d1699'))
177
 
        self.assertFalse(constraints.check_mount('/srv', 'foo bar'))
178
 
        self.assertFalse(constraints.check_mount('/srv', 'foo/bar'))
179
 
        self.assertFalse(constraints.check_mount('/srv', 'foo?bar'))
180
 
        reload(constraints)  # put it back
 
191
        with mock.patch("swift.common.constraints.ismount", MockTrue()):
 
192
            self.assertTrue(constraints.check_mount('/srv', '1'))
 
193
            self.assertTrue(constraints.check_mount('/srv', 'foo-bar'))
 
194
            self.assertTrue(constraints.check_mount('/srv', '003ed03c-242a-4b2f-bee9-395f801d1699'))
 
195
            self.assertFalse(constraints.check_mount('/srv', 'foo bar'))
 
196
            self.assertFalse(constraints.check_mount('/srv', 'foo/bar'))
 
197
            self.assertFalse(constraints.check_mount('/srv', 'foo?bar'))
181
198
 
182
199
    def test_check_float(self):
183
200
        self.assertFalse(constraints.check_float(''))
209
226
                     'ab' * constraints.MAX_HEADER_SIZE})
210
227
        self.assertEquals(constraints.check_metadata(req, 'object').status_int,
211
228
                          HTTP_BAD_REQUEST)
 
229
        self.assertIn('x-object-meta-hello', constraints.check_metadata(req,
 
230
                      'object').body.lower())
212
231
 
213
232
    def test_validate_constraints(self):
214
233
        c = constraints
217
236
        self.assertTrue(c.MAX_HEADER_SIZE > c.MAX_META_NAME_LENGTH)
218
237
        self.assertTrue(c.MAX_HEADER_SIZE > c.MAX_META_VALUE_LENGTH)
219
238
 
 
239
 
220
240
if __name__ == '__main__':
221
241
    unittest.main()