apps.lyric.views now generates a token associated w. the user-entered email & includes a link w. the token to login to the testserver; .tests.test_views asserts the association and the inclusion
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from django.test import TestCase
|
||||
from unittest import mock
|
||||
from ..models import Token
|
||||
|
||||
class SendLoginEmailViewTest(TestCase):
|
||||
def test_redirects_to_home_page(self):
|
||||
@@ -34,6 +35,25 @@ class SendLoginEmailViewTest(TestCase):
|
||||
)
|
||||
self.assertEqual(message.tags, "success")
|
||||
|
||||
def test_creates_token_associated_with_email(self):
|
||||
self.client.post(
|
||||
"/apps/lyric/send_login_email", data={"email": "discoman@example.com"}
|
||||
)
|
||||
token = Token.objects.get()
|
||||
self.assertEqual(token.email, "discoman@example.com")
|
||||
|
||||
|
||||
@mock.patch("apps.lyric.views.send_mail")
|
||||
def test_sends_link_to_login_using_token_uid(self, mock_send_mail):
|
||||
self.client.post(
|
||||
"/apps/lyric/send_login_email", data={"email": "discoman@example.com"}
|
||||
)
|
||||
|
||||
token = Token.objects.get()
|
||||
expected_url = f"http://testserver/apps/lyric/login?token={token.uid}"
|
||||
(subject, body, from_email, to_list), kwargs = mock_send_mail.call_args
|
||||
self.assertIn(expected_url, body)
|
||||
|
||||
class LoginViewTest(TestCase):
|
||||
def test_redirects_to_home_page(self):
|
||||
response = self.client.get("/apps/lyric/login?token=abc123")
|
||||
|
||||
Reference in New Issue
Block a user