1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
from nose.tools import *
from lamson import view
import jinja2
def test_load():
template = view.load("template.txt")
assert template
assert template.render()
def test_render():
# try with some empty vars
text = view.render({}, "template.txt")
assert text
def test_most_basic_form():
msg = view.respond(locals(), 'template.txt')
assert msg.Body
def test_respond_cadillac_version():
dude = 'Tester'
msg = view.respond(locals(), Body='template.txt',
Html='template.html',
From='test@localhost',
To='receiver@localhost',
Subject='Test body from "%(dude)s".')
assert msg.Body
assert msg.Html
for k in ['From', 'To', 'Subject']:
assert k in msg
def test_respond_plain_text():
dude = 'Tester'
msg = view.respond(locals(), Body='template.txt',
From='test@localhost',
To='receiver@localhost',
Subject='Test body from "%(dude)s".')
assert msg.Body
assert not msg.Html
for k in ['From', 'To', 'Subject']:
assert k in msg
def test_respond_html_only():
dude = 'Tester'
msg = view.respond(locals(), Html='template.html',
From='test@localhost',
To='receiver@localhost',
Subject='Test body from "%(dude)s".')
assert not msg.Body
assert msg.Html
for k in ['From', 'To', 'Subject']:
assert k in msg
def test_respond_attach():
dude = "hello"
mail = view.respond(locals(), Body="template.txt",
From="test@localhost",
To="receiver@localhost",
Subject='Test body from someone.')
view.attach(mail, locals(), 'template.html', content_type="text/html",
filename="template.html", disposition='attachment')
assert_equal(len(mail.attachments), 1)
msg = mail.to_message()
assert_equal(len(msg.get_payload()), 2)
assert str(msg)
mail.clear()
view.attach(mail, locals(), 'template.html', content_type="text/html")
assert_equal(len(mail.attachments), 1)
msg = mail.to_message()
assert_equal(len(msg.get_payload()), 2)
assert str(msg)
def test_unicode():
dude = u'H\xe9avy M\xe9t\xe5l Un\xeec\xf8d\xe9'
mail = view.respond(locals(), Html="unicode.html",
From="test@localhost",
To="receiver@localhost",
Subject='Test body from someone.')
assert str(mail)
view.attach(mail, locals(), "unicode.html", filename="attached.html")
assert str(mail)
|