From 4960723b1905fd8d20bbb14586206c5829f45371 Mon Sep 17 00:00:00 2001 From: Brian Sutherland Date: Thu, 27 Jun 2013 14:13:15 +0200 Subject: [PATCH] An exception on commit can have a 200 OK response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is a very bas idea to return a "Your changes have been saved" message when, in fact, they have not… --- repoze/tm/tests.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/repoze/tm/tests.py b/repoze/tm/tests.py index 15ce31e..56bf420 100644 --- a/repoze/tm/tests.py +++ b/repoze/tm/tests.py @@ -142,6 +142,29 @@ def execute_request(): self.assertEqual(transaction.aborted, True) self.assertEqual(dummycalled, [True]) + def test_exception_on_commit(self): + app = DummyApplication() + tm = self._makeOne(app) + transaction = DummyTransactionModule() + # raise exception on commit + class Bang(Exception): + pass + def commit(): + raise Bang() + transaction.commit = commit + tm.transaction = transaction + call_log = [] + def mock_start_response(*args, **kw): + call_log.append((args, kw)) + result = [] + def process(): + for chunk in tm({}, mock_start_response): + result.append(chunk) + self.assertRaises(Bang, process) + self.assertEqual(call_log, [(('500 Internal Server Error', [], None), {})]) + self.assertNotEqual(result, ['hello']) + + class TestAfterEnd(unittest.TestCase): def _getTargetClass(self): from repoze.tm import AfterEnd