This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
generated from ieeeuoft/hackathon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
79 lines (59 loc) · 2.66 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from django.test import TestCase
from unittest.mock import MagicMock
from registration.views import SignUpView
class CustomSignUpViewTestCase(TestCase):
"""
Tests the aspects of ``registration.views.SignUpView`` which relate to
class behaviour, and not to to rendering templates.
"""
def test_sends_email_html_body_template(self):
"""
When both ``email_body_template`` and ``html_body_template`` are defined,
an email should be sent with the former as the plaintext alternative and
the latter as the html alternative.
"""
class SignUpViewWithHTMLEmailTemplate(SignUpView):
email_body_template = (
"registration/test_emails/test_activation_email_body.txt"
)
html_email_body_template = (
"registration/test_emails/test_activation_email_body.html"
)
email_subject_template = (
"registration/test_emails/test_activation_email_subject.txt"
)
request = MagicMock()
user = MagicMock()
user.get_username.return_value = "username"
view = SignUpViewWithHTMLEmailTemplate()
view.send_activation_email(user)
user.email_user.assert_called()
subject, plain_message, _ = user.email_user.call_args[0]
html_message = user.email_user.call_args[1]["html_message"]
# Test that the subject had the newline removed
self.assertEqual(len(subject.splitlines()), 1)
# Test that the plaintext email is not the same as the html email
self.assertNotEqual(plain_message, html_message)
self.assertIn("<p>", html_message)
def test_sends_single_email_template_as_html(self):
"""
When only ``email_body_template`` is set, it should be used as the
plaintext and html message alternatives.
"""
class SignUpViewWithSingleEmailTemplate(SignUpView):
email_body_template = (
"registration/test_emails/test_activation_email_body.txt"
)
email_subject_template = (
"registration/test_emails/test_activation_email_subject.txt"
)
request = MagicMock()
user = MagicMock()
user.get_username.return_value = "username"
view = SignUpViewWithSingleEmailTemplate()
view.send_activation_email(user)
user.email_user.assert_called()
subject, plain_message, _ = user.email_user.call_args[0]
html_message = user.email_user.call_args[1]["html_message"]
# Test that the plaintext email is the same as the html email
self.assertEqual(plain_message, html_message)