|
14 | 14 |
|
15 | 15 | from django.test import TestCase
|
16 | 16 | from django.test import TransactionTestCase
|
| 17 | +from django.db.transaction import atomic |
17 | 18 |
|
18 | 19 | from patchwork.models import Comment
|
19 | 20 | from patchwork.models import Patch
|
|
31 | 32 | from patchwork.parser import parse_version
|
32 | 33 | from patchwork.parser import split_prefixes
|
33 | 34 | from patchwork.parser import subject_check
|
| 35 | +from patchwork.parser import DuplicateMailError |
34 | 36 | from patchwork.tests import TEST_MAIL_DIR
|
35 | 37 | from patchwork.tests import TEST_FUZZ_DIR
|
36 | 38 | from patchwork.tests.utils import create_project
|
@@ -1103,3 +1105,28 @@ def test_hdr(self):
|
1103 | 1105 |
|
1104 | 1106 | def test_x_face(self):
|
1105 | 1107 | self._test_patch('x-face.mbox')
|
| 1108 | + |
| 1109 | + |
| 1110 | +class DuplicateMailTest(TestCase): |
| 1111 | + def setUp(self): |
| 1112 | + self.listid = 'patchwork.ozlabs.org' |
| 1113 | + create_project(listid=self.listid) |
| 1114 | + create_state() |
| 1115 | + |
| 1116 | + def _test_duplicate_mail(self, mail): |
| 1117 | + _parse_mail(mail) |
| 1118 | + 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) |
| 1125 | + |
| 1126 | + def test_duplicate_patch(self): |
| 1127 | + diff = read_patch('0001-add-line.patch') |
| 1128 | + m = create_email( diff, listid=self. listid, msgid='[email protected]') |
| 1129 | + |
| 1130 | + self._test_duplicate_mail(m) |
| 1131 | + |
| 1132 | + self.assertEqual(Patch.objects.count(), 1) |
0 commit comments