]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Add duplicate mail test
authorJeremy Kerr <jk@ozlabs.org>
Thu, 16 Apr 2020 01:29:24 +0000 (09:29 +0800)
committerStephen Finucane <stephen@that.guru>
Sat, 18 Apr 2020 11:55:14 +0000 (12:55 +0100)
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 d4b5fbd1d0c743003d59cef025f54b8d97586ddf)

patchwork/tests/test_parser.py

index d5c98091b31cbe7a52760a01d9da1d8ea7c8efff..7fe3608fa9dcad0cb6f86a8f9d826c376f491cf7 100644 (file)
@@ -12,6 +12,7 @@ import os
 import sys
 import unittest
 
+from django.db.transaction import atomic
 from django.test import TestCase
 from django.test import TransactionTestCase
 from django.utils import six
@@ -32,6 +33,7 @@ from patchwork.parser import parse_series_marker
 from patchwork.parser import parse_version
 from patchwork.parser import split_prefixes
 from patchwork.parser import subject_check
+from patchwork.parser import DuplicateMailError
 from patchwork.tests import TEST_MAIL_DIR
 from patchwork.tests import TEST_FUZZ_DIR
 from patchwork.tests.utils import create_project
@@ -1121,3 +1123,28 @@ class WeirdMailTest(TransactionTestCase):
 
     def test_x_face(self):
         self._test_patch('x-face.mbox')
+
+
+class DuplicateMailTest(TestCase):
+    def setUp(self):
+        self.listid = 'patchwork.ozlabs.org'
+        create_project(listid=self.listid)
+        create_state()
+
+    def _test_duplicate_mail(self, mail):
+        _parse_mail(mail)
+        with self.assertRaises(DuplicateMailError):
+            # If we see any database errors from the duplicate insert
+            # (typically an IntegrityError), the insert will abort the current
+            # transaction. This atomic() ensures that we can recover, and
+            # perform subsequent queries.
+            with atomic():
+                _parse_mail(mail)
+
+    def test_duplicate_patch(self):
+        diff = read_patch('0001-add-line.patch')
+        m = create_email(diff, listid=self.listid, msgid='1@example.com')
+
+        self._test_duplicate_mail(m)
+
+        self.assertEqual(Patch.objects.count(), 1)