2021-03-21 19:30:53 +00:00
|
|
|
""" test creating emails """
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.test.client import RequestFactory
|
|
|
|
|
|
|
|
from bookwyrm import emailing, models
|
|
|
|
|
|
|
|
|
|
|
|
@patch("bookwyrm.emailing.send_email.delay")
|
|
|
|
class Emailing(TestCase):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""every response to a get request, html or json"""
|
2021-03-21 19:30:53 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""we need basic test data and mocks"""
|
2021-03-21 19:30:53 +00:00
|
|
|
self.factory = RequestFactory()
|
2021-09-06 21:48:45 +00:00
|
|
|
with patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"), patch(
|
|
|
|
"bookwyrm.activitystreams.populate_stream_task.delay"
|
2021-12-09 21:01:50 +00:00
|
|
|
), patch("bookwyrm.lists_stream.populate_lists_task.delay"):
|
2021-08-03 15:48:15 +00:00
|
|
|
self.local_user = models.User.objects.create_user(
|
|
|
|
"mouse@local.com",
|
|
|
|
"mouse@mouse.mouse",
|
|
|
|
"password",
|
|
|
|
local=True,
|
|
|
|
localname="mouse",
|
|
|
|
)
|
2021-08-02 23:05:40 +00:00
|
|
|
models.SiteSettings.objects.create()
|
2021-03-21 19:30:53 +00:00
|
|
|
|
|
|
|
def test_invite_email(self, email_mock):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""load the invite email"""
|
2021-03-21 19:30:53 +00:00
|
|
|
invite_request = models.InviteRequest.objects.create(
|
|
|
|
email="test@email.com",
|
|
|
|
invite=models.SiteInvite.objects.create(user=self.local_user),
|
|
|
|
)
|
|
|
|
|
|
|
|
emailing.invite_email(invite_request)
|
|
|
|
|
|
|
|
self.assertEqual(email_mock.call_count, 1)
|
|
|
|
args = email_mock.call_args[0]
|
|
|
|
self.assertEqual(args[0], "test@email.com")
|
|
|
|
self.assertEqual(args[1], "You're invited to join BookWyrm!")
|
|
|
|
self.assertEqual(len(args), 4)
|
|
|
|
|
|
|
|
def test_password_reset_email(self, email_mock):
|
2021-04-26 16:15:42 +00:00
|
|
|
"""load the password reset email"""
|
2021-03-21 19:30:53 +00:00
|
|
|
reset = models.PasswordReset.objects.create(user=self.local_user)
|
|
|
|
emailing.password_reset_email(reset)
|
|
|
|
|
|
|
|
self.assertEqual(email_mock.call_count, 1)
|
|
|
|
args = email_mock.call_args[0]
|
|
|
|
self.assertEqual(args[0], "mouse@mouse.mouse")
|
|
|
|
self.assertEqual(args[1], "Reset your BookWyrm password")
|
|
|
|
self.assertEqual(len(args), 4)
|