Fixes tests
This commit is contained in:
parent
4575fe24c7
commit
33b5639af0
|
@ -29,15 +29,19 @@ def password_reset_email(reset_code):
|
||||||
@app.task
|
@app.task
|
||||||
def send_email(recipient, message_name, data):
|
def send_email(recipient, message_name, data):
|
||||||
""" use a task to send the email """
|
""" use a task to send the email """
|
||||||
subject = get_template(
|
subject = (
|
||||||
"email/{}/subject.html".format(message_name)
|
get_template("email/{}/subject.html".format(message_name)).render(data).strip()
|
||||||
).render(data).strip()
|
)
|
||||||
html_content = get_template(
|
html_content = (
|
||||||
"email/{}/html_content.html".format(message_name)
|
get_template("email/{}/html_content.html".format(message_name))
|
||||||
).render(data).strip()
|
.render(data)
|
||||||
text_content = get_template(
|
.strip()
|
||||||
"email/{}/text_content.html".format(message_name)
|
)
|
||||||
).render(data).strip()
|
text_content = (
|
||||||
|
get_template("email/{}/text_content.html".format(message_name))
|
||||||
|
.render(data)
|
||||||
|
.strip()
|
||||||
|
)
|
||||||
|
|
||||||
email = EmailMultiAlternatives(subject, text_content, None, [recipient])
|
email = EmailMultiAlternatives(subject, text_content, None, [recipient])
|
||||||
email.attach_alternative(html_content, "text/html")
|
email.attach_alternative(html_content, "text/html")
|
||||||
|
|
|
@ -101,14 +101,15 @@ class InviteViews(TestCase):
|
||||||
""" send an invite """
|
""" send an invite """
|
||||||
req = models.InviteRequest.objects.create(email="fish@example.com")
|
req = models.InviteRequest.objects.create(email="fish@example.com")
|
||||||
|
|
||||||
view = views.InviteRequest.as_view()
|
view = views.ManageInviteRequests.as_view()
|
||||||
request = self.factory.post("", {"id": req.id})
|
request = self.factory.post("", {"invite-request": req.id})
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
request.user.is_superuser = True
|
request.user.is_superuser = True
|
||||||
|
|
||||||
with patch("bookwyrm.emailing.send_email.delay") as mock:
|
with patch("bookwyrm.emailing.send_email.delay") as mock:
|
||||||
view(request)
|
view(request)
|
||||||
self.assertEqual(mock.call_count, 1)
|
self.assertEqual(mock.call_count, 1)
|
||||||
|
req.refresh_from_db()
|
||||||
self.assertIsNotNone(req.invite)
|
self.assertIsNotNone(req.invite)
|
||||||
|
|
||||||
def test_ignore_invite_request(self):
|
def test_ignore_invite_request(self):
|
||||||
|
|
|
@ -118,7 +118,7 @@ class ManageInviteRequests(View):
|
||||||
|
|
||||||
invite_request.save()
|
invite_request.save()
|
||||||
emailing.invite_email(invite_request)
|
emailing.invite_email(invite_request)
|
||||||
return redirect('settings-invite-requests')
|
return redirect("settings-invite-requests")
|
||||||
|
|
||||||
|
|
||||||
class InviteRequest(View):
|
class InviteRequest(View):
|
||||||
|
|
Loading…
Reference in New Issue