|
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
from django.contrib.sites.models import Site
|
|
2
|
2
|
from django.core import mail
|
|
3
|
|
-from django.test import TestCase
|
|
|
3
|
+from django.core.exceptions import ImproperlyConfigured
|
|
|
4
|
+from django.test import TestCase, override_settings
|
|
4
|
5
|
|
|
5
|
6
|
from oscar.core.loading import get_class
|
|
6
|
7
|
from oscar.test.factories import (
|
|
|
@@ -17,55 +18,109 @@ class TestCustomerConcreteEmailsSending(EmailsMixin, TestCase):
|
|
17
|
18
|
super().setUp()
|
|
18
|
19
|
self.dispatcher = CustomerDispatcher()
|
|
19
|
20
|
|
|
20
|
|
- def test_send_registration_email_for_user(self):
|
|
|
21
|
+ def test_send_registration_email_for_user(self, additional_context=None):
|
|
21
|
22
|
extra_context = {'user': self.user}
|
|
|
23
|
+
|
|
|
24
|
+ if additional_context:
|
|
|
25
|
+ extra_context.update(additional_context)
|
|
|
26
|
+
|
|
22
|
27
|
self.dispatcher.send_registration_email_for_user(self.user, extra_context)
|
|
23
|
28
|
|
|
24
|
29
|
self._test_common_part()
|
|
25
|
30
|
self.assertEqual('Thank you for registering.', mail.outbox[0].subject)
|
|
26
|
31
|
self.assertIn('Thank you for registering.', mail.outbox[0].body)
|
|
27
|
32
|
|
|
28
|
|
- def test_send_password_reset_email_for_user(self):
|
|
|
33
|
+ @override_settings(SITE_ID=None, ALLOWED_HOSTS=["example.com"])
|
|
|
34
|
+ def test_send_registration_email_for_user_multisite(self):
|
|
|
35
|
+ with self.assertRaises(ImproperlyConfigured, msg=self.DJANGO_IMPROPERLY_CONFIGURED_MSG):
|
|
|
36
|
+ self.test_send_registration_email_for_user()
|
|
|
37
|
+
|
|
|
38
|
+ additional_context = {"request": self.request}
|
|
|
39
|
+ self.test_send_registration_email_for_user(additional_context=additional_context)
|
|
|
40
|
+
|
|
|
41
|
+ def test_send_password_reset_email_for_user(self, additional_context=None):
|
|
29
|
42
|
extra_context = {
|
|
30
|
43
|
'user': self.user,
|
|
31
|
44
|
'reset_url': '/django-oscar/django-oscar',
|
|
32
|
45
|
}
|
|
|
46
|
+
|
|
|
47
|
+ request = None
|
|
|
48
|
+ if additional_context:
|
|
|
49
|
+ request = additional_context.get("request")
|
|
|
50
|
+ extra_context.update(additional_context)
|
|
|
51
|
+
|
|
33
|
52
|
self.dispatcher.send_password_reset_email_for_user(self.user, extra_context)
|
|
34
|
53
|
|
|
35
|
54
|
self._test_common_part()
|
|
36
|
|
- expected_subject = 'Resetting your password at {}.'.format(Site.objects.get_current())
|
|
|
55
|
+ expected_subject = 'Resetting your password at {}.'.format(Site.objects.get_current(request))
|
|
37
|
56
|
self.assertEqual(expected_subject, mail.outbox[0].subject)
|
|
38
|
57
|
self.assertIn('Please go to the following page and choose a new password:', mail.outbox[0].body)
|
|
39
|
58
|
self.assertIn('http://example.com/django-oscar/django-oscar', mail.outbox[0].body)
|
|
40
|
59
|
|
|
41
|
|
- def test_send_password_changed_email_for_user(self):
|
|
|
60
|
+ @override_settings(SITE_ID=None, ALLOWED_HOSTS=["example.com"])
|
|
|
61
|
+ def test_send_password_reset_email_for_user_multisite(self):
|
|
|
62
|
+ with self.assertRaises(ImproperlyConfigured, msg=self.DJANGO_IMPROPERLY_CONFIGURED_MSG):
|
|
|
63
|
+ self.test_send_password_reset_email_for_user()
|
|
|
64
|
+
|
|
|
65
|
+ additional_context = {"request": self.request}
|
|
|
66
|
+ self.test_send_password_reset_email_for_user(additional_context=additional_context)
|
|
|
67
|
+
|
|
|
68
|
+ def test_send_password_changed_email_for_user(self, additional_context=None):
|
|
42
|
69
|
extra_context = {
|
|
43
|
70
|
'user': self.user,
|
|
44
|
71
|
'reset_url': '/django-oscar/django-oscar',
|
|
45
|
72
|
}
|
|
|
73
|
+
|
|
|
74
|
+ request = None
|
|
|
75
|
+ if additional_context:
|
|
|
76
|
+ request = additional_context.get("request")
|
|
|
77
|
+ extra_context.update(additional_context)
|
|
|
78
|
+
|
|
46
|
79
|
self.dispatcher.send_password_changed_email_for_user(self.user, extra_context)
|
|
47
|
80
|
|
|
48
|
81
|
self._test_common_part()
|
|
49
|
|
- expected_subject = 'Your password changed at {}.'.format(Site.objects.get_current())
|
|
|
82
|
+ expected_subject = 'Your password changed at {}.'.format(Site.objects.get_current(request))
|
|
50
|
83
|
self.assertEqual(expected_subject, mail.outbox[0].subject)
|
|
51
|
84
|
self.assertIn('your password has been changed', mail.outbox[0].body)
|
|
52
|
85
|
self.assertIn('http://example.com/django-oscar/django-oscar', mail.outbox[0].body)
|
|
53
|
86
|
|
|
54
|
|
- def test_send_email_changed_email_for_user(self):
|
|
|
87
|
+ @override_settings(SITE_ID=None, ALLOWED_HOSTS=["example.com"])
|
|
|
88
|
+ def test_send_password_changed_email_for_user_multisite(self):
|
|
|
89
|
+ with self.assertRaises(ImproperlyConfigured, msg=self.DJANGO_IMPROPERLY_CONFIGURED_MSG):
|
|
|
90
|
+ self.test_send_password_changed_email_for_user()
|
|
|
91
|
+
|
|
|
92
|
+ additional_context = {"request": self.request}
|
|
|
93
|
+ self.test_send_password_changed_email_for_user(additional_context=additional_context)
|
|
|
94
|
+
|
|
|
95
|
+ def test_send_email_changed_email_for_user(self, additional_context=None):
|
|
55
|
96
|
extra_context = {
|
|
56
|
97
|
'user': self.user,
|
|
57
|
98
|
'reset_url': '/django-oscar/django-oscar',
|
|
58
|
99
|
'new_email': 'some_new@mail.com',
|
|
59
|
100
|
}
|
|
|
101
|
+
|
|
|
102
|
+ request = None
|
|
|
103
|
+ if additional_context:
|
|
|
104
|
+ request = additional_context.get("request")
|
|
|
105
|
+ extra_context.update(additional_context)
|
|
|
106
|
+
|
|
60
|
107
|
self.dispatcher.send_email_changed_email_for_user(self.user, extra_context)
|
|
61
|
108
|
|
|
62
|
109
|
self._test_common_part()
|
|
63
|
|
- expected_subject = 'Your email address has changed at {}.'.format(Site.objects.get_current())
|
|
|
110
|
+ expected_subject = 'Your email address has changed at {}.'.format(Site.objects.get_current(request))
|
|
64
|
111
|
self.assertEqual(expected_subject, mail.outbox[0].subject)
|
|
65
|
112
|
self.assertIn('your email address has been changed', mail.outbox[0].body)
|
|
66
|
113
|
self.assertIn('http://example.com/django-oscar/django-oscar', mail.outbox[0].body)
|
|
67
|
114
|
self.assertIn('some_new@mail.com', mail.outbox[0].body)
|
|
68
|
115
|
|
|
|
116
|
+ @override_settings(SITE_ID=None, ALLOWED_HOSTS=["example.com"])
|
|
|
117
|
+ def test_send_email_changed_email_for_user_multisite(self):
|
|
|
118
|
+ with self.assertRaises(ImproperlyConfigured, msg=self.DJANGO_IMPROPERLY_CONFIGURED_MSG):
|
|
|
119
|
+ self.test_send_email_changed_email_for_user()
|
|
|
120
|
+
|
|
|
121
|
+ additional_context = {"request": self.request}
|
|
|
122
|
+ self.test_send_email_changed_email_for_user(additional_context=additional_context)
|
|
|
123
|
+
|
|
69
|
124
|
|
|
70
|
125
|
class TestAlertsConcreteEmailsSending(EmailsMixin, TestCase):
|
|
71
|
126
|
|