Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ba5645a

Browse files
committedFeb 8, 2020
finish tests and revert format of utils.send_email_with_callback_token
1 parent 663cc28 commit ba5645a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed
 

‎drfpasswordless/utils.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,17 @@ def send_email_with_callback_token(user, email_token, **kwargs):
119119
# Get email subject and message
120120
email_subject = kwargs.get('email_subject',
121121
api_settings.PASSWORDLESS_EMAIL_SUBJECT)
122+
email_plaintext = kwargs.get('email_plaintext',
123+
api_settings.PASSWORDLESS_EMAIL_PLAINTEXT_MESSAGE)
124+
email_html = kwargs.get('email_html',
125+
api_settings.PASSWORDLESS_EMAIL_TOKEN_HTML_TEMPLATE_NAME)
122126

123-
# Inject context if user specifies.
127+
# Inject context if user specifies & determine if token is within a url
124128
if api_settings.PASSWORDLESS_LOGIN_URL_DOMAIN:
125129
context = inject_template_context({'callback_token': api_settings.PASSWORDLESS_LOGIN_URL_DOMAIN + api_settings.PASSWORDLESS_AUTH_PREFIX + 'login/' + user.email + '/' + email_token.key, })
126130
else:
127131
context = inject_template_context({'callback_token': email_token.key, })
128132

129-
email_html = kwargs.get('email_html')
130-
email_plaintext = kwargs.get('email_plaintext')
131-
132133
html_message = loader.render_to_string(email_html, context,)
133134
send_mail(
134135
email_subject,

‎tests/test_settings.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ def test_email_sender_required(self):
4747
email_response = self.client.post(self.email_url, self.email_data)
4848
self.assertEqual(email_response.status_code, status.HTTP_400_BAD_REQUEST)
4949

50-
def test_mobile_sender_required(self):
50+
def test_email_tokon_as_url(self):
5151
"""
52-
Check to make sure user has a send address if mobile is selected.
52+
Check selecting send token within URL does not fail
5353
"""
54-
api_settings.PASSWORDLESS_AUTH_TYPES = ['MOBILE']
55-
email_response = self.client.post(self.mobile_url, self.mobile_data)
56-
self.assertEqual(email_response.status_code, status.HTTP_400_BAD_REQUEST)
54+
api_settings.PASSWORDLESS_AUTH_TYPES = ['EMAIL']
55+
api_settings.PASSWORDLESS_LOGIN_URL_DOMAIN = 'https://domain.com/'
56+
api_settings.PASSWORDLESS_EMAIL_NOREPLY_ADDRESS = 'email@example.com'
57+
58+
email_response = self.client.post(self.email_url, self.email_data)
59+
self.assertEqual(email_response.status_code, status.HTTP_200_OK)
5760

58-
def test_tokon_as_url(self):
61+
def test_mobile_sender_required(self):
5962
"""
6063
Check to make sure user has a send address if mobile is selected.
6164
"""

0 commit comments

Comments
 (0)
Please sign in to comment.