Created
February 7, 2013 17:31
-
-
Save epicserve/4732605 to your computer and use it in GitHub Desktop.
An example on how to test emails. The last two lines I would remove before committing to your repository, but if your working on an HTML email the last two lines are nice because you can see what the email would look like.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from djagno.test import TestCase, Client | |
from django.core.urlresolvers import reverse | |
from django.core import mail | |
c = Client() | |
class TestEmails(TestCase): | |
def test_submit_event(self): | |
resp = c.post(reverse('submit_event'), { | |
'title': 'Test Event', | |
'start_0': '2/6/2013', | |
'start_1': '1:00 pm', | |
'end_0': '2/6/2013', | |
'end_1': '2:00 pm', | |
'one_off_location': "Gold's Gym (East Wenatchee, WA)", | |
}) | |
self.assertRedirects(resp, 'http://testserver%s' % reverse('submit_event_success')) | |
self.assertEqual(len(mail.outbox), 1) | |
self.assertEqual(mail.outbox[0].subject, 'New Event Submitted') | |
self.assertEqual(mail.outbox[0].to, [u'admin@test.com']) | |
self.assertTrue('Test Event' in mail.outbox[0].alternatives[0][0]) | |
with open('/Users/oconnor/Desktop/temp.html', 'w') as f: | |
f.write(mail.outbox[0].alternatives[0][0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment