diff options
author | Marcel Hellkamp <marc@gsites.de> | 2011-06-21 00:28:27 +0200 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2011-06-21 00:36:35 +0200 |
commit | 6ab03c9cc01e9a17e1ec557d1ed840748ce221e8 (patch) | |
tree | 895663c1cda61ba12d7d298dce37d78d86cf6b43 /test/test_environ.py | |
parent | e412cd9fa5f4ebb81767e3eec73327ba7cc4f88c (diff) | |
download | bottle-6ab03c9cc01e9a17e1ec557d1ed840748ce221e8.tar.gz |
BaseRequest now supports a dict-like item access API to read, write and
delete headers.
Small performance tweak in the Router implementation.
Response headers are now stored directly on the BaseRequest instance. This
avoids the need to create a separate HeaderDict instance and reduces the
per-request overhead.
The old BaseRequest.headers dictionary is still available, but only created
on demand.
BaseRequest.headerlist now returns a copy of the header list and no longer
flushes the response cookies as a side-effect. The new
BaseRequest.yield_headers() method does the same, but returns a generator.
BaseRequest.wsgiheader() is deprecated in favor of BaseRequest.headerlist
or BaseRequest.yield_headers().
Diffstat (limited to 'test/test_environ.py')
-rwxr-xr-x | test/test_environ.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/test_environ.py b/test/test_environ.py index 61f9d81..3f764f4 100755 --- a/test/test_environ.py +++ b/test/test_environ.py @@ -404,6 +404,11 @@ class TestResponse(unittest.TestCase): self.assertEqual(rs.status_code, 999) self.assertEqual(rs.status_line, '999 Who knows?') + rs.status = 555 # Strange code + self.assertEqual(rs.status, 555) + self.assertEqual(rs.status_code, 555) + self.assertEqual(rs.status_line, '555 Unknown') + rs.status = '404 Brain not Found' # Custom reason self.assertEqual(rs.status, 404) self.assertEqual(rs.status_code, 404) @@ -464,6 +469,48 @@ class TestResponse(unittest.TestCase): if name.title() == 'Set-Cookie'] self.assertTrue('name=;' in cookies[0]) + def test_set_header(self): + response = BaseResponse() + response['x-test'] = 'foo' + headers = [value for name, value in response.wsgiheader() + if name.title() == 'X-Test'] + self.assertEqual(['foo'], headers) + self.assertEqual('foo', response['x-test']) + + response['X-Test'] = 'bar' + headers = [value for name, value in response.wsgiheader() + if name.title() == 'X-Test'] + self.assertEqual(['bar'], headers) + self.assertEqual('bar', response['x-test']) + + def test_append_header(self): + response = BaseResponse() + response.set_header('x-test', 'foo') + headers = [value for name, value in response.wsgiheader() + if name.title() == 'X-Test'] + self.assertEqual(['foo'], headers) + self.assertEqual('foo', response['x-test']) + + response.set_header('X-Test', 'bar', True) + headers = [value for name, value in response.wsgiheader() + if name.title() == 'X-Test'] + self.assertEqual(['foo', 'bar'], headers) + self.assertEqual('bar', response['x-test']) + + def test_delete_header(self): + response = BaseResponse() + response['x-test'] = 'foo' + self.assertEqual('foo', response['x-test']) + del response['X-tESt'] + self.assertRaises(KeyError, lambda: response['x-test']) + + def test_non_string_header(self): + response = BaseResponse() + response['x-test'] = 5 + self.assertEqual('5', response['x-test']) + response['x-test'] = None + self.assertEqual('None', response['x-test']) + class TestRedirect(unittest.TestCase): |