Skip to content

Commit

Permalink
finish tests and revert format of utils.send_email_with_callback_token
Browse files Browse the repository at this point in the history
  • Loading branch information
firstTimeCaller committed Feb 8, 2020
1 parent 663cc28 commit ba5645a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
9 changes: 5 additions & 4 deletions drfpasswordless/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,17 @@ def send_email_with_callback_token(user, email_token, **kwargs):
# Get email subject and message
email_subject = kwargs.get('email_subject',
api_settings.PASSWORDLESS_EMAIL_SUBJECT)
email_plaintext = kwargs.get('email_plaintext',
api_settings.PASSWORDLESS_EMAIL_PLAINTEXT_MESSAGE)
email_html = kwargs.get('email_html',
api_settings.PASSWORDLESS_EMAIL_TOKEN_HTML_TEMPLATE_NAME)

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

email_html = kwargs.get('email_html')
email_plaintext = kwargs.get('email_plaintext')

html_message = loader.render_to_string(email_html, context,)
send_mail(
email_subject,
Expand Down
15 changes: 9 additions & 6 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ def test_email_sender_required(self):
email_response = self.client.post(self.email_url, self.email_data)
self.assertEqual(email_response.status_code, status.HTTP_400_BAD_REQUEST)

def test_mobile_sender_required(self):
def test_email_tokon_as_url(self):
"""
Check to make sure user has a send address if mobile is selected.
Check selecting send token within URL does not fail
"""
api_settings.PASSWORDLESS_AUTH_TYPES = ['MOBILE']
email_response = self.client.post(self.mobile_url, self.mobile_data)
self.assertEqual(email_response.status_code, status.HTTP_400_BAD_REQUEST)
api_settings.PASSWORDLESS_AUTH_TYPES = ['EMAIL']
api_settings.PASSWORDLESS_LOGIN_URL_DOMAIN = 'https://domain.com/'
api_settings.PASSWORDLESS_EMAIL_NOREPLY_ADDRESS = '[email protected]'

email_response = self.client.post(self.email_url, self.email_data)
self.assertEqual(email_response.status_code, status.HTTP_200_OK)

def test_tokon_as_url(self):
def test_mobile_sender_required(self):
"""
Check to make sure user has a send address if mobile is selected.
"""
Expand Down

0 comments on commit ba5645a

Please sign in to comment.