test/mboxviews: Add test for header-supplied dates
authorJeremy Kerr <jk@ozlabs.org>
Mon, 10 Jun 2013 04:29:34 +0000 (12:29 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 10 Jun 2013 04:31:52 +0000 (12:31 +0800)
Check that a Date: header in the original message is equivalent to the
header generated in the mbox output.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/tests/mboxviews.py

index 8c469a1ae76787c50b0a52be7dbed4449dff0056..6209513934d176aa07cfe8fb9e9ed391a518fdea 100644 (file)
@@ -21,6 +21,7 @@
 
 import unittest
 import email
+import datetime
 import dateutil.parser, dateutil.tz
 from django.test import TestCase
 from django.test.client import Client
@@ -164,3 +165,17 @@ class MboxDateHeaderTest(TestCase):
         patch_date = self.patch.date.replace(tzinfo=dateutil.tz.tzutc(),
                                             microsecond=0)
         self.assertEqual(mail_date, patch_date)
+
+    def testSuppliedDateHeader(self):
+        hour_offset = 3
+        tz = dateutil.tz.tzoffset(None, hour_offset * 60 * 60)
+        date = datetime.datetime.utcnow() - datetime.timedelta(days = 1)
+        date = date.replace(tzinfo=tz, microsecond=0)
+
+        self.patch.headers = 'Date: %s\n' % date.strftime("%a, %d %b %Y %T %z")
+        self.patch.save()
+
+        response = self.client.get('/patch/%d/mbox/' % self.patch.id)
+        mail = email.message_from_string(response.content)
+        mail_date = dateutil.parser.parse(mail['Date'])
+        self.assertEqual(mail_date, date)