apps.lyric.views and .tests.test_views updated for better Mailgun API post mocking; UTs passing locally
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
@@ -2,5 +2,6 @@ Django==6.0
|
|||||||
django-stubs==5.2.8
|
django-stubs==5.2.8
|
||||||
django-stubs-ext==5.2.8
|
django-stubs-ext==5.2.8
|
||||||
gunicorn==23.0.0
|
gunicorn==23.0.0
|
||||||
|
lxml==6.0.2
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
whitenoise==6.11.0
|
whitenoise==6.11.0
|
||||||
|
|||||||
@@ -10,17 +10,17 @@ class SendLoginEmailViewTest(TestCase):
|
|||||||
)
|
)
|
||||||
self.assertRedirects(response, "/")
|
self.assertRedirects(response, "/")
|
||||||
|
|
||||||
@mock.patch("apps.lyric.views.send_mail")
|
@mock.patch("apps.lyric.views.requests.post")
|
||||||
def test_sends_mail_to_address_from_post(self, mock_send_mail):
|
def test_sends_mail_to_address_from_post(self, mock_post):
|
||||||
self.client.post(
|
self.client.post(
|
||||||
"/apps/lyric/send_login_email", data={"email": "discoman@example.com"}
|
"/apps/lyric/send_login_email", data={"email": "discoman@example.com"}
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(mock_send_mail.called, True)
|
self.assertEqual(mock_post.called, True)
|
||||||
(subject, body, from_email, to_list), kwargs = mock_send_mail.call_args
|
data = mock_post.call_args.kwargs["data"]
|
||||||
self.assertEqual(subject, "A magic login link to your Dashboard")
|
self.assertEqual(data["subject"], "A magic login link to your Dashboard")
|
||||||
self.assertEqual(from_email, "adman@howdy.earthmanrpg.me")
|
self.assertEqual(data["from"], "adman@howdy.earthmanrpg.me")
|
||||||
self.assertEqual(to_list, ["discoman@example.com"])
|
self.assertEqual(data["to"], "discoman@example.com")
|
||||||
|
|
||||||
def test_adds_success_message(self):
|
def test_adds_success_message(self):
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
@@ -44,16 +44,16 @@ class SendLoginEmailViewTest(TestCase):
|
|||||||
self.assertEqual(token.email, "discoman@example.com")
|
self.assertEqual(token.email, "discoman@example.com")
|
||||||
|
|
||||||
|
|
||||||
@mock.patch("apps.lyric.views.send_mail")
|
@mock.patch("apps.lyric.views.requests.post")
|
||||||
def test_sends_link_to_login_using_token_uid(self, mock_send_mail):
|
def test_sends_link_to_login_using_token_uid(self, mock_post):
|
||||||
self.client.post(
|
self.client.post(
|
||||||
"/apps/lyric/send_login_email", data={"email": "discoman@example.com"}
|
"/apps/lyric/send_login_email", data={"email": "discoman@example.com"}
|
||||||
)
|
)
|
||||||
|
|
||||||
token = Token.objects.get()
|
token = Token.objects.get()
|
||||||
expected_url = f"http://testserver/apps/lyric/login?token={token.uid}"
|
expected_url = f"http://testserver/apps/lyric/login?token={token.uid}"
|
||||||
(subject, body, from_email, to_list), kwargs = mock_send_mail.call_args
|
data = mock_post.call_args.kwargs["data"]
|
||||||
self.assertIn(expected_url, body)
|
self.assertIn(expected_url, data["text"])
|
||||||
|
|
||||||
class LoginViewTest(TestCase):
|
class LoginViewTest(TestCase):
|
||||||
def test_redirects_to_home_page(self):
|
def test_redirects_to_home_page(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user