forked from mirrors/bookwyrm
Adds emailing tests
This commit is contained in:
parent
da2d146f0b
commit
a0b106f6bb
2 changed files with 52 additions and 2 deletions
51
bookwyrm/tests/test_emailing.py
Normal file
51
bookwyrm/tests/test_emailing.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
""" test creating emails """
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.test.client import RequestFactory
|
||||||
|
import responses
|
||||||
|
|
||||||
|
from bookwyrm import emailing, models
|
||||||
|
|
||||||
|
|
||||||
|
@patch("bookwyrm.emailing.send_email.delay")
|
||||||
|
class Emailing(TestCase):
|
||||||
|
""" every response to a get request, html or json """
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
""" we need basic test data and mocks """
|
||||||
|
self.factory = RequestFactory()
|
||||||
|
self.local_user = models.User.objects.create_user(
|
||||||
|
"mouse@local.com",
|
||||||
|
"mouse@mouse.mouse",
|
||||||
|
"password",
|
||||||
|
local=True,
|
||||||
|
localname="mouse",
|
||||||
|
)
|
||||||
|
models.SiteSettings.objects.create()
|
||||||
|
|
||||||
|
def test_invite_email(self, email_mock):
|
||||||
|
""" load the invite email """
|
||||||
|
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):
|
||||||
|
""" load the password reset email """
|
||||||
|
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)
|
|
@ -9,7 +9,6 @@ import responses
|
||||||
|
|
||||||
from bookwyrm import models, importer
|
from bookwyrm import models, importer
|
||||||
from bookwyrm.goodreads_import import GoodreadsImporter
|
from bookwyrm.goodreads_import import GoodreadsImporter
|
||||||
from bookwyrm import importer
|
|
||||||
from bookwyrm.settings import DOMAIN
|
from bookwyrm.settings import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,8 +16,8 @@ class GoodreadsImport(TestCase):
|
||||||
""" importing from goodreads csv """
|
""" importing from goodreads csv """
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.importer = GoodreadsImporter()
|
|
||||||
""" use a test csv """
|
""" use a test csv """
|
||||||
|
self.importer = GoodreadsImporter()
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("data/goodreads.csv")
|
datafile = pathlib.Path(__file__).parent.joinpath("data/goodreads.csv")
|
||||||
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
self.csv = open(datafile, "r", encoding=self.importer.encoding)
|
||||||
self.user = models.User.objects.create_user(
|
self.user = models.User.objects.create_user(
|
||||||
|
|
Loading…
Reference in a new issue