|
|
@@ -3,6 +3,8 @@ import os
|
|
3
|
3
|
import warnings
|
|
4
|
4
|
|
|
5
|
5
|
from django_webtest import WebTest
|
|
|
6
|
+
|
|
|
7
|
+from django.contrib.auth.models import AnonymousUser
|
|
6
|
8
|
from django.core.urlresolvers import reverse
|
|
7
|
9
|
from django.core import mail
|
|
8
|
10
|
from django.test import TestCase
|
|
|
@@ -10,9 +12,10 @@ from oscar.utils.deprecation import RemovedInOscar20Warning
|
|
10
|
12
|
|
|
11
|
13
|
from oscar.apps.customer.alerts.utils import (send_alert_confirmation,
|
|
12
|
14
|
send_product_alerts)
|
|
|
15
|
+from oscar.apps.customer.forms import ProductAlertForm
|
|
13
|
16
|
from oscar.apps.customer.models import ProductAlert
|
|
14
|
|
-from oscar.test.factories import create_product, create_stockrecord
|
|
15
|
|
-from oscar.test.factories import UserFactory
|
|
|
17
|
+from oscar.test.factories import (
|
|
|
18
|
+ create_product, create_stockrecord, ProductAlertFactory, UserFactory)
|
|
16
|
19
|
|
|
17
|
20
|
|
|
18
|
21
|
class TestAUser(WebTest):
|
|
|
@@ -87,6 +90,31 @@ class TestAnAnonymousUser(WebTest):
|
|
87
|
90
|
self.assertEqual(ProductAlert.UNCONFIRMED, alert.status)
|
|
88
|
91
|
self.assertEqual(alert.product, product)
|
|
89
|
92
|
|
|
|
93
|
+ def test_can_cancel_unconfirmed_stock_alert(self):
|
|
|
94
|
+ alert = ProductAlertFactory(
|
|
|
95
|
+ user=None, email='john@smith.com', status=ProductAlert.UNCONFIRMED)
|
|
|
96
|
+ self.app.get(
|
|
|
97
|
+ reverse('customer:alerts-cancel-by-key', kwargs={'key': alert.key}))
|
|
|
98
|
+ alert.refresh_from_db()
|
|
|
99
|
+ self.assertTrue(alert.is_cancelled)
|
|
|
100
|
+
|
|
|
101
|
+ def test_cannot_create_multiple_unconfirmed_alerts(self):
|
|
|
102
|
+ # Create an unconfirmed alert
|
|
|
103
|
+ alert = ProductAlertFactory(
|
|
|
104
|
+ user=None, email='john@smith.com', status=ProductAlert.UNCONFIRMED)
|
|
|
105
|
+
|
|
|
106
|
+ # Alert form should not allow creation of additional alerts.
|
|
|
107
|
+ form = ProductAlertForm(
|
|
|
108
|
+ user=AnonymousUser(),
|
|
|
109
|
+ product=create_product(num_in_stock=0),
|
|
|
110
|
+ data={'email': 'john@smith.com'},
|
|
|
111
|
+ )
|
|
|
112
|
+
|
|
|
113
|
+ self.assertFalse(form.is_valid())
|
|
|
114
|
+ self.assertIn(
|
|
|
115
|
+ "john@smith.com has been sent a confirmation email for another "
|
|
|
116
|
+ "product alert on this site.", form.errors['__all__'][0])
|
|
|
117
|
+
|
|
90
|
118
|
|
|
91
|
119
|
class TestHurryMode(TestCase):
|
|
92
|
120
|
|