mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #12666 -- Added EMAIL_USE_LOCALTIME setting.
When EMAIL_USE_LOCALTIME=True, send emails with a Date header in the local time zone.
This commit is contained in:
committed by
Tim Graham
parent
b9c04801d4
commit
c3495bb984
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user