|
@@ -21,7 +21,8 @@ from django.core.mail import (
|
|
|
)
|
|
|
from django.core.mail.backends import console, dummy, filebased, locmem, smtp
|
|
|
from django.core.mail.message import BadHeaderError, sanitize_address
|
|
|
-from django.test import SimpleTestCase, override_settings
|
|
|
+from django.test import SimpleTestCase, TestCase, override_settings
|
|
|
+from django.test.utils import requires_tz_support
|
|
|
from django.utils._os import upath
|
|
|
from django.utils.encoding import force_bytes, force_text
|
|
|
from django.utils.six import PY3, StringIO, binary_type
|
|
@@ -605,6 +606,27 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
|
|
|
)
|
|
|
|
|
|
|
|
|
+@requires_tz_support
|
|
|
+class MailTimeZoneTests(TestCase):
|
|
|
+
|
|
|
+ # setting the timezone requires a database query on PostgreSQL.
|
|
|
+ @override_settings(EMAIL_USE_LOCALTIME=False, USE_TZ=True, TIME_ZONE='Africa/Algiers')
|
|
|
+ def test_date_header_utc(self):
|
|
|
+ """
|
|
|
+ EMAIL_USE_LOCALTIME=False creates a datetime in UTC.
|
|
|
+ """
|
|
|
+ email = EmailMessage('Subject', 'Body', 'bounce@example.com', ['to@example.com'])
|
|
|
+ self.assertTrue(email.message()['Date'].endswith('-0000'))
|
|
|
+
|
|
|
+ @override_settings(EMAIL_USE_LOCALTIME=True, USE_TZ=True, TIME_ZONE='Africa/Algiers')
|
|
|
+ def test_date_header_localtime(self):
|
|
|
+ """
|
|
|
+ EMAIL_USE_LOCALTIME=True creates a datetime in the local time zone.
|
|
|
+ """
|
|
|
+ email = EmailMessage('Subject', 'Body', 'bounce@example.com', ['to@example.com'])
|
|
|
+ self.assertTrue(email.message()['Date'].endswith('+0100')) # Africa/Algiers is UTC+1
|
|
|
+
|
|
|
+
|
|
|
class PythonGlobalState(SimpleTestCase):
|
|
|
"""
|
|
|
Tests for #12422 -- Django smarts (#2472/#11212) with charset of utf-8 text
|