Mercurial > public > madeira
diff madeira/email_list/tests/view_tests.py @ 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 |
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 = []