121
121
self.assertRaises(ValueError, self.fp.seek, 0, -1)
124
def assertRegexMatches(test, groups, regex, text):
125
"""Check that the regex matches and returns the right values"""
126
m = regex.match(text)
127
test.assertNotEqual(None, m, "text %s did not match regex" % (text,))
129
test.assertEqual(groups, m.groups())
124
132
class TestHttpRangeResponse(TestCase):
126
def assertMatches(self, regex, text, groups):
127
"""Check that the regex matches and returns the right values"""
128
m = regex.match(text)
129
self.assertNotEqual(None, m, "text %s did not match regex" % (text,))
131
self.assertEqual(groups, m.groups())
133
134
def test_range_re(self):
134
135
"""Test that we match valid ranges."""
135
136
regex = response.HttpRangeResponse.CONTENT_RANGE_RE
136
self.assertMatches(regex, 'bytes 1-10/11', ('bytes', '1', '10', '11'))
137
self.assertMatches(regex,
138
'\tbytes 1-10/11 ', ('bytes', '1', '10', '11'))
139
self.assertMatches(regex,
140
'\tbytes 2123-4242/1231 ', ('bytes', '2123', '4242', '1231'))
141
self.assertMatches(regex,
142
' chars 1-2/3', ('chars', '1', '2', '3'))
137
assertRegexMatches(self, ('bytes', '1', '10', '11'),
138
regex, 'bytes 1-10/11')
139
assertRegexMatches(self, ('bytes', '1', '10', '11'),
140
regex, '\tbytes 1-10/11 ')
141
assertRegexMatches(self, ('bytes', '2123', '4242', '1231'),
142
regex, '\tbytes 2123-4242/1231 ')
143
assertRegexMatches(self, ('chars', '1', '2', '3'),
144
regex, ' chars 1-2/3')
144
146
def test__parse_range(self):
145
147
"""Test that _parse_range acts reasonably."""
166
168
self.assertRaises(errors.InvalidRange, f.read, 2)
168
170
self.assertEqual('012345', f.read(6))
173
class TestHttpMultipartRangeResponse(TestCase):
175
def test_content_type_re(self):
176
regex = response.HttpMultipartRangeResponse.CONTENT_TYPE_RE
177
assertRegexMatches(self, ('xxyyzz',),
178
regex, 'multipart/byteranges; boundary = xxyyzz')
179
assertRegexMatches(self, ('xxyyzz',),
180
regex, 'multipart/byteranges;boundary=xxyyzz')
181
assertRegexMatches(self, ('xx yy zz',),
182
regex, ' multipart/byteranges ; boundary= xx yy zz ')
183
self.assertEqual(None, regex.match('multipart byteranges;boundary=xx'))