test send_downgrade_email.

normally called as a celery task, it is tested normally, synchronously.
This commit is contained in:
fiatjaf 2018-05-17 14:20:58 +00:00
parent 4d281c94e1
commit a62e7387f5
3 changed files with 10 additions and 0 deletions

View File

@ -5,9 +5,11 @@ from formspree import settings
from formspree.stuff import celery
from formspree.utils import send_email
def hash_pwd(password):
return generate_password_hash(password)
def check_password(hashed, password):
return check_password_hash(hashed, password)

View File

@ -24,6 +24,7 @@ def msend():
with \
patch('formspree.users.models.send_email', side_effect=side_effect), \
patch('formspree.users.views.send_email', side_effect=side_effect), \
patch('formspree.users.helpers.send_email', side_effect=side_effect), \
patch('formspree.forms.models.send_email', side_effect=side_effect):
yield msend

View File

@ -1,4 +1,5 @@
from formspree.utils import next_url
from formspree.users.helpers import send_downgrade_email
def test_next_url(client):
# thanks route should have the referrer as its 'next'
@ -18,3 +19,9 @@ def test_next_url(client):
# Referrer set and absolute next url should result in proper absolute next url.
assert 'https://morefun.net/awesome.php' == next_url(referrer='https://fun.io', next='//morefun.net/awesome.php')
assert 'http://morefun.net/awesome.php' == next_url(referrer='http://fun.io', next='//morefun.net/awesome.php')
def test_send_downgrade_email(msend):
send_downgrade_email('whatever@example.com')
assert msend.called
assert msend.call_args[1]['to'] == 'whatever@example.com'
assert 'Successfully downgraded from' in msend.call_args[1]['subject']