changeset 52:7f9e76e7eb4d

For issue #7, another commit for a mailing list application. In this commit we add to the tests to check for the confirmation email. Also realized the request coming from the email is a GET, not a POST.
author Brian Neal <bgneal@gmail.com>
date Thu, 29 Mar 2012 20:01:13 -0500
parents 13b2561c909d
children 9b40a8d300a4
files madeira/email_list/tests/view_tests.py madeira/email_list/views.py
diffstat 2 files changed, 23 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/madeira/email_list/tests/view_tests.py	Wed Mar 28 21:13:05 2012 -0500
+++ b/madeira/email_list/tests/view_tests.py	Thu Mar 29 20:01:13 2012 -0500
@@ -4,6 +4,7 @@
 """
 from django.test import TestCase
 from django.core.urlresolvers import reverse
+from django.core import mail
 
 from email_list.models import Subscriber
 import email_list.forms
@@ -18,7 +19,7 @@
 
 UNSUB_PARAMS = {
     'name': '',
-    'email': 'j.doe@example.com',
+    'email': SUB_PARAMS['email'],
     'location': '',
     'option': 'unsub'
 }
@@ -127,13 +128,13 @@
 
         self.assertTrue(subscriber.is_pending())
 
-        # TODO: test email sent
+        # test email sent
+        self.do_test_email(subscriber)
 
-        # post to confirm
+        # simulate a confirm click
 
-        response = self.client.post(
+        response = self.client.get(
                 reverse('email_list-confirm', kwargs={'key': subscriber.key}),
-                {},
                 follow=True)
 
         self.assertTrue(response.status_code, 200)
@@ -178,13 +179,13 @@
 
         self.assertTrue(subscriber.is_leaving())
 
-        # TODO: test email sent
+        # test email sent
+        self.do_test_email(subscriber)
 
-        # post to confirm unsubscribe
+        # simulate a click to unsubscribe
 
-        response = self.client.post(
+        response = self.client.get(
                 reverse('email_list-confirm', kwargs={'key': subscriber.key}),
-                {},
                 follow=True)
 
         self.assertTrue(response.status_code, 200)
@@ -197,3 +198,16 @@
 
         self.assertRaises(Subscriber.DoesNotExist, Subscriber.objects.get,
                 email=UNSUB_PARAMS['email'])
+
+    def do_test_email(self, subscriber):
+        """
+        Tests to see if the confirmation email was sent.
+
+        """
+        self.assertEqual(len(mail.outbox), 1)
+        self.assertEqual(len(mail.outbox[0].to), 1)
+        self.assertEqual(mail.outbox[0].to[0], subscriber.email)
+        self.assertTrue(str(mail.outbox[0].message()).count(subscriber.key) > 0)
+
+        # clear outbox
+        mail.outbox = []
--- a/madeira/email_list/views.py	Wed Mar 28 21:13:05 2012 -0500
+++ b/madeira/email_list/views.py	Thu Mar 29 20:01:13 2012 -0500
@@ -6,7 +6,6 @@
 
 from django.http import HttpResponseServerError
 from django.shortcuts import render, redirect, get_object_or_404
-from django.views.decorators.http import require_POST
 
 from email_list.forms import SubscriberForm
 from email_list.models import Subscriber
@@ -36,7 +35,6 @@
     return render(request, 'email_list/subscribe_form.html', {'form': form})
 
 
-@require_POST
 def confirm(request, key):
     """
     This view handles the confirmation of a subscribe or unsubscribe action.