def test_invalid_block_templated_message_templates(app_with_mail): """Test invalid templates.""" with app_with_mail.app_context(): with pytest.raises(TemplateError) as ex: BlockTemplatedMessage("mail/blank.html") assert "No block with name 'subject'" in str(ex.value) with pytest.raises(TemplateError) as ex: BlockTemplatedMessage("mail/subject_only.html") assert "No block with name 'body_plain'" in str(ex.value)
def test_block_templated_message_body_same_as_html(app_with_mail): """Test that the subject and body are read correctly.""" with app_with_mail.app_context(): blank = BlockTemplatedMessage("mail/subject_body.html") assert blank.subject == "Test subject." assert "Test body." in blank.body assert "Test body." in blank.html
def test_block_templated_message_full(app_with_mail): """Test that the subject, body and html are read correctly.""" with app_with_mail.app_context(): full = BlockTemplatedMessage("mail/subject_body_html.html") assert full.subject == "Test subject." assert "Test body." in full.body assert "Test html." in full.html
def test_block_templated_message_full(app): """Test that the subject, body and html are read correctly.""" with app.app_context(): blank = BlockTemplatedMessage("tests/subject_body_html.html") assert blank.subject == "Test subject." assert blank.body == "Test body." assert blank.html == "Test html."
def test_block_templated_message_body_same_as_html(app_with_mail): """Test that the subject and body are read correctly.""" with app_with_mail.app_context(): # remove footer app_with_mail.config["ILS_GLOBAL_MAIL_TEMPLATES"] = {} blank = BlockTemplatedMessage("mail/subject_body.html") assert blank.subject == "Test subject." assert "Test body." == blank.body assert "Test body." == blank.html
def test_block_templated_message_full(app_with_mail): """Test that the subject, body and html are read correctly.""" with app_with_mail.app_context(): # remove footer app_with_mail.config["ILS_GLOBAL_MAIL_TEMPLATES"] = {} full = BlockTemplatedMessage("mail/subject_body_html.html") assert full.subject == "Test subject." assert "Test body." == full.body assert "Test html." == full.html
def test_message_templates_escaping(app_with_mail): """Test templates escaping.""" title = "Spèciâl chäráctèrs: " \ "`,~,!,@,#,$,%,^,&,*,(,),_,-,+,=,{,[,},},|,\\,:,;,',<,>,.,?,/,º,ª " \ "<script>alert('test');</script>" ctx = dict(title=title) with app_with_mail.app_context(): # remove footer app_with_mail.config["ILS_GLOBAL_MAIL_TEMPLATES"] = {} full = BlockTemplatedMessage("mail/subject_body_html_ctx.html", ctx) assert full.subject == "Test \"{0}\" subject.".format(title) from jinja2 import escape escaped = escape(title) assert "Test \"{0}\" body.".format(escaped) == full.body assert "Test \"{0}\" html.".format(escaped) == full.html
def test_block_template_with_missing_template(app_with_mail): """Test that a missing template raises an exception.""" with app_with_mail.app_context(): with pytest.raises(TemplateNotFound): BlockTemplatedMessage("missing.html")