Commit 0102f77e authored by Pino Toscano's avatar Pino Toscano

Fix usage of EMAIL_SUBJECT_PREFIX

In Django [1] this string is supposed to include a trailing space, and
indeed internal Django functions assume there is one.
Hence, adapt damnedlies to this assuption.

[1] https://docs.djangoproject.com/en/2.2/ref/settings/#email-subject-prefix
parent b002fcbc
Pipeline #77791 passed with stage
in 3 minutes and 30 seconds
......@@ -91,5 +91,5 @@ def get_user_locale(request):
def send_mail(subject, message, **kwargs):
"""Wrapper to Django's send_mail allowing all EmailMessage init arguments."""
if not subject.startswith(settings.EMAIL_SUBJECT_PREFIX):
subject = '%s %s' % (settings.EMAIL_SUBJECT_PREFIX, subject)
subject = '%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject)
EmailMessage(subject, message, **kwargs).send()
......@@ -24,7 +24,7 @@ DATABASES = {
EMAIL_HOST = 'localhost'
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_SUBJECT_PREFIX = '[Damned Lies]'
EMAIL_SUBJECT_PREFIX = '[Damned Lies] '
EMAIL_HEADER_NAME= 'X-Vertimus'
DEFAULT_FROM_EMAIL = 'gnomeweb@gnome.org'
SERVER_EMAIL = 'gnomeweb@gnome.org'
......
......@@ -205,14 +205,14 @@ class TeamTests(TeamsAndRolesMixin, TestCase):
def test_send_mail_to_coordinator(self):
self.t.send_mail_to_coordinator(subject="foo", message="bar")
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, "%s foo" % settings.EMAIL_SUBJECT_PREFIX)
self.assertEqual(mail.outbox[0].subject, "%sfoo" % settings.EMAIL_SUBJECT_PREFIX)
self.assertEqual(mail.outbox[0].extra_headers, {settings.EMAIL_HEADER_NAME: 'coordinator-mail'})
# the message is sent in the language of the team
self.t.send_mail_to_coordinator(subject=ugettext_lazy("About Damned Lies"), message="...")
self.assertEqual(len(mail.outbox), 2)
self.assertEqual(
mail.outbox[1].subject,
"%s À propos de Damned Lies" % settings.EMAIL_SUBJECT_PREFIX
"%sÀ propos de Damned Lies" % settings.EMAIL_SUBJECT_PREFIX
)
......
......@@ -305,7 +305,7 @@ class VertimusTest(TeamsAndRolesMixin, TestCase):
# Mail sent to mailing list
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].recipients(), [self.l.team.mailing_list])
self.assertEqual(mail.outbox[0].subject, "%s gnome-hello - gnome-2-24" % settings.EMAIL_SUBJECT_PREFIX)
self.assertEqual(mail.outbox[0].subject, "%sgnome-hello - gnome-2-24" % settings.EMAIL_SUBJECT_PREFIX)
self.assertEqual(mail.outbox[0].extra_headers, {settings.EMAIL_HEADER_NAME: 'Translated'})
# Testing if the role was activated
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment