name_check: better test maximum_length

Previously, we were testing that a 254 (!?) character name would be valid
when the maximum configured is 500. Now we'll test that 500 character
names are valid.

While we're at it, stop patching self.test_check. It was unnecessary,
and we were doing it badly.

Change-Id: Ia604fa7b809a97fbce176c82606af73cdb92828c
This commit is contained in:
Tim Burke 2017-05-16 17:58:07 -07:00
parent 6e893e2288
commit 582af7cd9d

View File

@ -66,12 +66,10 @@ class TestNameCheckMiddleware(unittest.TestCase):
def test_maximum_length_from_config(self):
# test invalid length
orig_test_check = self.test_check
conf = {'maximum_length': "500"}
self.test_check = name_check.filter_factory(conf)(FakeApp())
path = '/V1.0/a/c' + 'o' * (500 - 8)
app = name_check.filter_factory({'maximum_length': "500"})(FakeApp())
path = '/V1.0/a/c/' + 'o' * (500 - 9)
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check)
).get_response(app)
self.assertEqual(
resp.body,
("Object/Container/Account name longer than the allowed "
@ -79,12 +77,11 @@ class TestNameCheckMiddleware(unittest.TestCase):
self.assertEqual(resp.status_int, 400)
# test valid length
path = '/V1.0/a/c' + 'o' * (MAX_LENGTH - 10)
path = '/V1.0/a/c/' + 'o' * (500 - 10)
resp = Request.blank(path, environ={'REQUEST_METHOD': 'PUT'}
).get_response(self.test_check)
).get_response(app)
self.assertEqual(resp.status_int, 200)
self.assertEqual(resp.body, 'OK')
self.test_check = orig_test_check
def test_invalid_length(self):
path = '/V1.0/' + 'c' * (MAX_LENGTH - 5)