From 5a633dccee0de23b9fa7c9d5eddc2784360094bb Mon Sep 17 00:00:00 2001 From: Disco DeDisco Date: Tue, 10 Feb 2026 21:42:15 -0500 Subject: [PATCH] apps.lyric.views and .tests.test_views updated for better Mailgun API post mocking; UTs passing locally --- requirements.txt | 1 + src/apps/lyric/tests/test_views.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/requirements.txt b/requirements.txt index f95ac92..ac8ccd0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,6 @@ Django==6.0 django-stubs==5.2.8 django-stubs-ext==5.2.8 gunicorn==23.0.0 +lxml==6.0.2 requests==2.31.0 whitenoise==6.11.0 diff --git a/src/apps/lyric/tests/test_views.py b/src/apps/lyric/tests/test_views.py index 4d28b36..191d483 100644 --- a/src/apps/lyric/tests/test_views.py +++ b/src/apps/lyric/tests/test_views.py @@ -10,17 +10,17 @@ class SendLoginEmailViewTest(TestCase): ) self.assertRedirects(response, "/") - @mock.patch("apps.lyric.views.send_mail") - def test_sends_mail_to_address_from_post(self, mock_send_mail): + @mock.patch("apps.lyric.views.requests.post") + def test_sends_mail_to_address_from_post(self, mock_post): self.client.post( "/apps/lyric/send_login_email", data={"email": "discoman@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"]) + self.assertEqual(mock_post.called, True) + data = mock_post.call_args.kwargs["data"] + self.assertEqual(data["subject"], "A magic login link to your Dashboard") + self.assertEqual(data["from"], "adman@howdy.earthmanrpg.me") + self.assertEqual(data["to"], "discoman@example.com") def test_adds_success_message(self): response = self.client.post( @@ -44,16 +44,16 @@ class SendLoginEmailViewTest(TestCase): 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): + @mock.patch("apps.lyric.views.requests.post") + def test_sends_link_to_login_using_token_uid(self, mock_post): 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) + data = mock_post.call_args.kwargs["data"] + self.assertIn(expected_url, data["text"]) class LoginViewTest(TestCase): def test_redirects_to_home_page(self):