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 test_validate_template(self): self.assertTrue(validate_template('{{ text|lower }}')) self.assertFalse(validate_template('{{ text|lower:"a" }}')) # TemplateSyntaxError
def clean_body(self): if not validate_template(template=self.cleaned_data['body']): raise ValidationError('De body is niet valide') return self.cleaned_data['body']
def clean_title(self): if not validate_template(template=self.cleaned_data['title']): raise ValidationError('De titel is niet valide') return self.cleaned_data['title']