def test_validate_email_template(self): email_template_valid = EmailTemplateFactory.create(key=EmailTemplate.SIGNAL_CREATED) result = validate_email_template(email_template_valid) self.assertTrue(result) email_template_invalid = EmailTemplateFactory.create(key=EmailTemplate.SIGNAL_STATUS_CHANGED_AFGEHANDELD, title='{{ text|lower:"a" }}', # TemplateSyntaxError body='{{ created_at|date:"PO" }}') # NotImplementedError result = validate_email_template(email_template_invalid) self.assertFalse(result)
def test_validate_email_template_date_filter_tag(self): # Django 3.2 has different behavior from Django 2.2, it no longer raises # an exception on unsupported options to the date filter tag. # This test is kept around (marked a expected failure) in case that this # new behavior is regression in Django 3.2 and to document it. self.assertFalse(validate_template('{{ created_at|date:"B" }}')) email_template_invalid_title = EmailTemplateFactory.create(key=EmailTemplate.SIGNAL_STATUS_CHANGED_HEROPEND, title='{{ created_at|date:"B" }}') # noqa NotImplementedError result = validate_email_template(email_template_invalid_title) self.assertFalse(result) email_template_invalid_body = EmailTemplateFactory.create(key=EmailTemplate.SIGNAL_STATUS_CHANGED_OPTIONAL, body='{{ created_at|date:"B" }}') # noqa NotImplementedError result = validate_email_template(email_template_invalid_body) self.assertFalse(result)
def validate_templates(self, request, queryset): for email_template in queryset.all(): if validate_email_template(email_template=email_template): self.message_user( request, f"De E-mail template '{email_template}', is valide.", messages.SUCCESS) else: self.message_user( request, f"De E-mail template '{email_template}', is NIET valide.", messages.ERROR)