mocking added thruout apps.lyric.tests.test_views, where UTs mock message sending; status message loop added to base.html below navbar; hardcoded assert and model/view values aligned across lyric app, UTs & FTs
This commit is contained in:
@@ -1,30 +1,35 @@
|
||||
from django.test import TestCase
|
||||
from .. import views as lyric_views
|
||||
from unittest import mock
|
||||
|
||||
class SendLoginEmailViewTest(TestCase):
|
||||
def test_redirects_to_home_page(self):
|
||||
response = self.client.post(
|
||||
"/apps/lyric/send_login_email", data={"email": "disco@example.com"}
|
||||
"/apps/lyric/send_login_email", data={"email": "discoman@example.com"}
|
||||
)
|
||||
self.assertRedirects(response, "/")
|
||||
|
||||
def test_sends_mail_to_address_from_post(self):
|
||||
self.send_mail_called = False
|
||||
|
||||
def fake_send_mail(subject, body, from_email, to_list):
|
||||
self.send_mail_called = True
|
||||
self.subject = subject
|
||||
self.body = body
|
||||
self.from_email = from_email
|
||||
self.to_list = to_list
|
||||
|
||||
lyric_views.send_mail = fake_send_mail
|
||||
|
||||
@mock.patch("apps.lyric.views.send_mail")
|
||||
def test_sends_mail_to_address_from_post(self, mock_send_mail):
|
||||
self.client.post(
|
||||
"/apps/lyric/send_login_email", data={"email": "disco@example.com"}
|
||||
"/apps/lyric/send_login_email", data={"email": "discoman@example.com"}
|
||||
)
|
||||
|
||||
self.assertTrue(self.send_mail_called)
|
||||
self.assertEqual(self.subject, "A magic login link for your Dashboard")
|
||||
self.assertEqual(self.from_email, "adman@howdy.earthmanrpg.me")
|
||||
self.assertEqual(self.to_list, ["disco@example.com"])
|
||||
self.assertEqual(mock_send_mail.called, True)
|
||||
(subject, body, from_email, to_list), kwargs = mock_send_mail.call_args
|
||||
self.assertEqual(subject, "A magic login link to your Dashboard")
|
||||
self.assertEqual(from_email, "adman@howdy.earthmanrpg.me")
|
||||
self.assertEqual(to_list, ["discoman@example.com"])
|
||||
|
||||
def test_adds_success_message(self):
|
||||
response = self.client.post(
|
||||
"/apps/lyric/send_login_email",
|
||||
data={"email": "discoman@example.com"},
|
||||
follow=True
|
||||
)
|
||||
|
||||
message = list(response.context["messages"])[0]
|
||||
self.assertEqual(
|
||||
message.message,
|
||||
"Check your email!—there you'll find a magic login link. But hurry… it's only temporary!",
|
||||
)
|
||||
self.assertEqual(message.tags, "success")
|
||||
|
||||
Reference in New Issue
Block a user