Skip to content

Commit 1493073

Browse files
jk-ozlabsstephenfin
authored andcommitted
tests: Add duplicate mail test
Test that we get the correct DuplicateMailError from parsing the same mail twice. Conflicts: patchwork/tests/test_parser.py NOTE(stephenfin): Conflicts are due to the removal of 'six' imports on master. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Reviewed-by: Stephen Finucane <stephen@that.guru> (cherry picked from commit d4b5fbd)
1 parent 77b8191 commit 1493073

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

patchwork/tests/test_parser.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import sys
1313
import unittest
1414

15+
from django.db.transaction import atomic
1516
from django.test import TestCase
1617
from django.test import TransactionTestCase
1718
from django.utils import six
@@ -32,6 +33,7 @@
3233
from patchwork.parser import parse_version
3334
from patchwork.parser import split_prefixes
3435
from patchwork.parser import subject_check
36+
from patchwork.parser import DuplicateMailError
3537
from patchwork.tests import TEST_MAIL_DIR
3638
from patchwork.tests import TEST_FUZZ_DIR
3739
from patchwork.tests.utils import create_project
@@ -1121,3 +1123,28 @@ def test_hdr(self):
11211123

11221124
def test_x_face(self):
11231125
self._test_patch('x-face.mbox')
1126+
1127+
1128+
class DuplicateMailTest(TestCase):
1129+
def setUp(self):
1130+
self.listid = 'patchwork.ozlabs.org'
1131+
create_project(listid=self.listid)
1132+
create_state()
1133+
1134+
def _test_duplicate_mail(self, mail):
1135+
_parse_mail(mail)
1136+
with self.assertRaises(DuplicateMailError):
1137+
# If we see any database errors from the duplicate insert
1138+
# (typically an IntegrityError), the insert will abort the current
1139+
# transaction. This atomic() ensures that we can recover, and
1140+
# perform subsequent queries.
1141+
with atomic():
1142+
_parse_mail(mail)
1143+
1144+
def test_duplicate_patch(self):
1145+
diff = read_patch('0001-add-line.patch')
1146+
m = create_email(diff, listid=self.listid, msgid='1@example.com')
1147+
1148+
self._test_duplicate_mail(m)
1149+
1150+
self.assertEqual(Patch.objects.count(), 1)

0 commit comments

Comments
 (0)