diff options
| author | Jeff Dairiki <dairiki@dairiki.org> | 2015-04-15 12:12:19 -0700 |
|---|---|---|
| committer | Jeff Dairiki <dairiki@dairiki.org> | 2015-04-15 12:34:10 -0700 |
| commit | 875b90d3376c060dea469bc7110c51e20b2eee0a (patch) | |
| tree | 591cfdd6c46fff53125a924bcd7e1908e7032d1c | |
| parent | fa16cb17480543f027bd5316edd3d4878513e5f7 (diff) | |
| download | pyramid-875b90d3376c060dea469bc7110c51e20b2eee0a.tar.gz pyramid-875b90d3376c060dea469bc7110c51e20b2eee0a.tar.bz2 pyramid-875b90d3376c060dea469bc7110c51e20b2eee0a.zip | |
Add tests for temporary_response context manager
These tests test for, among other things, the nits described in comments
on #1563, namely:
- ``Request.response`` should be restored even if the renderer raises an
exception
- If ``request.response`` is initially set to ``None``, it should be
restored to ``None`` (rather than deleted).
(Some of these tests currently fail.)
| -rw-r--r-- | pyramid/tests/test_renderers.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/pyramid/tests/test_renderers.py b/pyramid/tests/test_renderers.py index ed6344a40..542eea9aa 100644 --- a/pyramid/tests/test_renderers.py +++ b/pyramid/tests/test_renderers.py @@ -592,6 +592,48 @@ class Test_render_to_response(unittest.TestCase): self.assertEqual(result.body, b'{"a": 1}') self.assertFalse('response' in request.__dict__) +class Test_temporary_response(unittest.TestCase): + def _callFUT(self, request): + from pyramid.renderers import temporary_response + return temporary_response(request) + + def test_restores_response(self): + request = testing.DummyRequest() + orig_response = request.response + with self._callFUT(request): + request.response = object() + self.assertEqual(request.response, orig_response) + + def test_restores_response_on_exception(self): + request = testing.DummyRequest() + orig_response = request.response + try: + with self._callFUT(request): + request.response = object() + raise RuntimeError() + except RuntimeError: + self.assertEqual(request.response, orig_response) + else: # pragma: no cover + self.fail("RuntimeError not raised") + + def test_restores_response_to_none(self): + request = testing.DummyRequest(response=None) + with self._callFUT(request): + request.response = object() + self.assertEqual(request.response, None) + + def test_deletes_response(self): + request = testing.DummyRequest() + with self._callFUT(request): + request.response = object() + self.assertTrue('response' not in request.__dict__) + + def test_does_not_delete_response_if_no_response_to_delete(self): + request = testing.DummyRequest() + with self._callFUT(request): + pass + self.assertTrue('response' not in request.__dict__) + class Test_get_renderer(unittest.TestCase): def setUp(self): self.config = testing.setUp() |
