]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
tests: Reduce duplication in MailParsingTest
authorStephen Finucane <stephen@that.guru>
Fri, 7 Oct 2016 18:21:19 +0000 (19:21 +0100)
committerStephen Finucane <stephen@that.guru>
Fri, 7 Oct 2016 18:40:42 +0000 (19:40 +0100)
...and rename to 'EncodingParseTest' to signify function of tests.

Signed-off-by: Stephen Finucane <stephen@that.guru>
patchwork/tests/test_parser.py

index 83ce20429fa472501f61713b559b606f4fb41e58..912b821c12c6c20da8fe73642b814093feddff22 100644 (file)
@@ -543,35 +543,33 @@ class PatchParseTest(PatchTest):
         self.assertEqual(2, diff.count('\ No newline at end of file'))
 
 
-class MailParsingTest(TestCase):
+class EncodingParseTest(TestCase):
+    """Test parsing of patches with different encoding issues."""
 
     def setUp(self):
         self.project = create_project()
 
-    def test_invalid_header_char(self):
-        """Validate behaviour when an invalid character is in a header."""
-        mail = read_mail('0012-invalid-header-char.mbox', self.project)
+    def _test_encoded_patch_parse(self, mbox_filename):
+        mail = read_mail(mbox_filename, self.project)
         parse_mail(mail, list_id=self.project.listid)
         self.assertEqual(Patch.objects.all().count(), 1)
 
+    def test_invalid_header_char(self):
+        """Validate behaviour when an invalid character is in a header."""
+        self._test_encoded_patch_parse('0012-invalid-header-char.mbox')
+
     def test_utf8_mail(self):
         """Validate behaviour when a UTF-8 char is in a message."""
-        mail = read_mail('0013-with-utf8-body.mbox')
-        parse_mail(mail, list_id=self.project.listid)
-        self.assertEqual(Patch.objects.all().count(), 1)
+        self._test_encoded_patch_parse('0013-with-utf8-body.mbox')
 
     def test_utf8_unencoded_headers(self):
         """Validate behaviour when unencoded UTF-8 is in headers,
         including subject and from."""
-        mail = read_mail('0014-with-unencoded-utf8-headers.mbox')
-        parse_mail(mail, list_id=self.project.listid)
-        self.assertEqual(Patch.objects.all().count(), 1)
+        self._test_encoded_patch_parse('0014-with-unencoded-utf8-headers.mbox')
 
     def test_invalid_utf8_headers(self):
         """Validate behaviour when invalid encoded UTF-8 is in headers."""
-        mail = read_mail('0015-with-invalid-utf8-headers.mbox')
-        parse_mail(mail, list_id=self.project.listid)
-        self.assertEqual(Patch.objects.all().count(), 1)
+        self._test_encoded_patch_parse('0015-with-invalid-utf8-headers.mbox')
 
 
 class DelegateRequestTest(TestCase):