# HG changeset patch # User Brian Neal # Date 1333069273 18000 # Node ID 7f9e76e7eb4d0e4c6ec57320de10fc7c6eb9cd07 # Parent 13b2561c909d6602686fa6c1b9f3d26183792a78 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. diff -r 13b2561c909d -r 7f9e76e7eb4d madeira/email_list/tests/view_tests.py --- 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 = [] diff -r 13b2561c909d -r 7f9e76e7eb4d madeira/email_list/views.py --- 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.