|
15 | 15 | from django.test import TestCase
|
16 | 16 | from django.test import TransactionTestCase
|
17 | 17 | from django.db.transaction import atomic
|
| 18 | +from django.db import connection |
18 | 19 |
|
19 | 20 | from patchwork.models import Comment
|
20 | 21 | from patchwork.models import Patch
|
@@ -1114,15 +1115,30 @@ def setUp(self):
|
1114 | 1115 | create_state()
|
1115 | 1116 |
|
1116 | 1117 | def _test_duplicate_mail(self, mail):
|
| 1118 | + errors = [] |
| 1119 | + |
| 1120 | + def log_query_errors(execute, sql, params, many, context): |
| 1121 | + try: |
| 1122 | + result = execute(sql, params, many, context) |
| 1123 | + except Exception as e: |
| 1124 | + errors.append(e) |
| 1125 | + raise |
| 1126 | + return result |
| 1127 | + |
1117 | 1128 | _parse_mail(mail)
|
| 1129 | + |
1118 | 1130 | with self.assertRaises(DuplicateMailError):
|
1119 |
| - # If we see any database errors from the duplicate insert |
1120 |
| - # (typically an IntegrityError), the insert will abort the current |
1121 |
| - # transaction. This atomic() ensures that we can recover, and |
1122 |
| - # perform subsequent queries. |
1123 |
| - with atomic(): |
1124 |
| - _parse_mail(mail) |
| 1131 | + with connection.execute_wrapper(log_query_errors): |
| 1132 | + # If we see any database errors from the duplicate insert |
| 1133 | + # (typically an IntegrityError), the insert will abort the |
| 1134 | + # current transaction. This atomic() ensures that we can |
| 1135 | + # recover, and perform subsequent queries. |
| 1136 | + with atomic(): |
| 1137 | + _parse_mail(mail) |
| 1138 | + |
| 1139 | + self.assertEqual(errors, []) |
1125 | 1140 |
|
| 1141 | + @unittest.expectedFailure |
1126 | 1142 | def test_duplicate_patch(self):
|
1127 | 1143 | diff = read_patch('0001-add-line.patch')
|
1128 | 1144 | m = create_email( diff, listid=self. listid, msgid='[email protected]')
|
|
0 commit comments