Projet

Général

Profil

0001-misc-inject-TEMPLATE_VARS-in-mail-template-context-4.patch

Benjamin Dauvergne, 02 juillet 2020 23:13

Télécharger (3,02 ko)

Voir les différences:

Subject: [PATCH] misc: inject TEMPLATE_VARS in mail template context (#43469)

 src/authentic2/utils/__init__.py          |  4 +++-
 tests/templates/template_vars_body.html   |  1 +
 tests/templates/template_vars_body.txt    |  1 +
 tests/templates/template_vars_subject.txt |  1 +
 tests/test_utils.py                       | 15 +++++++++++++++
 5 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 tests/templates/template_vars_body.html
 create mode 100644 tests/templates/template_vars_body.txt
 create mode 100644 tests/templates/template_vars_subject.txt
src/authentic2/utils/__init__.py
634 634
    if not request:
635 635
        request = middleware.StoreRequestMiddleware().get_request()
636 636

  
637
    ctx = context or {}
637
    ctx = copy.copy(app_settings.TEMPLATE_VARS)
638
    if context:
639
        ctx.update(context)
638 640

  
639 641
    subject_template_names = [template_name + '_subject.txt' for template_name in template_names]
640 642
    subject_template_names += legacy_subject_templates or []
tests/templates/template_vars_body.html
1
{{ template_vars_body_html }}
tests/templates/template_vars_body.txt
1
{{ template_vars_body_txt }}
tests/templates/template_vars_subject.txt
1
{{ template_vars_subject_txt }}
tests/test_utils.py
161 161
    assert sent_mail.body == specific_template_ou
162 162

  
163 163

  
164
def test_send_templated_mail_template_vars(settings, simple_user):
165
    settings.TEMPLATE_VARS = {
166
        'template_vars_subject_txt': 'here is the subject',
167
        'template_vars_body_txt': 'here is the text body',
168
        'template_vars_body_html': 'here is the html body',
169
    }
170
    send_templated_mail(simple_user, ['template_vars'])
171

  
172
    assert len(mail.outbox) == 1
173
    sent_mail = mail.outbox.pop()
174
    assert sent_mail.subject == 'here is the subject'
175
    assert sent_mail.body == 'here is the text body\n'
176
    assert sent_mail.alternatives == [('here is the html body\n', 'text/html')]
177

  
178

  
164 179
def test_lazy_join():
165 180
    a = 'a'
166 181

  
167
-