Skip to content

Commit d4b5fbd

Browse files
jk-ozlabsstephenfin
authored andcommitted
tests: Add duplicate mail test
Test that we get the correct DuplicateMailError from parsing the same mail twice. Signed-off-by: Jeremy Kerr <[email protected]> Reviewed-by: Stephen Finucane <[email protected]>
1 parent a971756 commit d4b5fbd

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
@@ -14,6 +14,7 @@
1414

1515
from django.test import TestCase
1616
from django.test import TransactionTestCase
17+
from django.db.transaction import atomic
1718

1819
from patchwork.models import Comment
1920
from patchwork.models import Patch
@@ -31,6 +32,7 @@
3132
from patchwork.parser import parse_version
3233
from patchwork.parser import split_prefixes
3334
from patchwork.parser import subject_check
35+
from patchwork.parser import DuplicateMailError
3436
from patchwork.tests import TEST_MAIL_DIR
3537
from patchwork.tests import TEST_FUZZ_DIR
3638
from patchwork.tests.utils import create_project
@@ -1103,3 +1105,28 @@ def test_hdr(self):
11031105

11041106
def test_x_face(self):
11051107
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

Comments
 (0)