from django.test import SimpleTestCase
from unittest import mock

from apps.lyric.tasks import send_login_email_task


class SendLoginEmailTaskTest(SimpleTestCase):
    @mock.patch("apps.lyric.tasks.requests.post")
    def test_sends_mail_via_mailgun(self, mock_post):
        send_login_email_task("discoman@example.com", "http://example.com/login?token=abc123")
        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.com")
        self.assertEqual(data["to"], "discoman@example.com")
        self.assertIn("http://example.com/login?token=abc123", data["text"])
