[PATCH 6/6] parsemail tests: add test for mail with utf-8

Daniel Axtens dja at axtens.net
Fri Sep 23 10:06:17 AEST 2016


This is designed to ensure we don't have any more hiccups with
decoding UTF-8 under arbitrary locales, which can occur under
Python 3.

Signed-off-by: Daniel Axtens <dja at axtens.net>
---
 patchwork/tests/test_management.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/patchwork/tests/test_management.py b/patchwork/tests/test_management.py
index 5f97aa76866f..4b49131a72c2 100644
--- a/patchwork/tests/test_management.py
+++ b/patchwork/tests/test_management.py
@@ -81,3 +81,32 @@ class ParsemailTest(TestCase):
 
         count = models.Patch.objects.filter(project=project.id).count()
         self.assertEqual(count, 1)
+
+    def test_utf8_path(self):
+        project = utils.create_project()
+        utils.create_state()
+
+        path = os.path.join(TEST_MAIL_DIR, '0013-with-utf8-body.mbox')
+        with self.assertRaises(SystemExit) as exc:
+            call_command('parsemail', infile=path, list_id=project.listid)
+
+        self.assertEqual(exc.exception.code, 0)
+
+        count = models.Patch.objects.filter(project=project.id).count()
+        self.assertEqual(count, 1)
+
+    def test_utf8_stdin(self):
+        project = utils.create_project()
+        utils.create_state()
+
+        path = os.path.join(TEST_MAIL_DIR, '0013-with-utf8-body.mbox')
+        sys.stdin.close()
+        sys.stdin = open(path)
+        with self.assertRaises(SystemExit) as exc:
+            call_command('parsemail', infile=None,
+                         list_id=project.listid)
+
+        self.assertEqual(exc.exception.code, 0)
+
+        count = models.Patch.objects.filter(project=project.id).count()
+        self.assertEqual(count, 1)
-- 
2.7.4



More information about the Patchwork mailing list