annotate contact/tests/test_views.py @ 859:fca9281c535c

Started work on command to update posts for SSL.
author Brian Neal <bgneal@gmail.com>
date Tue, 25 Nov 2014 20:06:40 -0600
parents 38db6ec61af3
children 79a71b9d0a2a
rev   line source
bgneal@819 1 """
bgneal@819 2 Unit tests for the contact application views.
bgneal@819 3
bgneal@819 4 """
bgneal@819 5 from django.test import TestCase
bgneal@819 6 from django.core.urlresolvers import reverse
bgneal@819 7 from django.core import mail
bgneal@819 8
bgneal@819 9
bgneal@819 10 class BaseTestCase(TestCase):
bgneal@819 11 """Simple tests to ensure basic functionality."""
bgneal@819 12
bgneal@819 13 def test_usage(self):
bgneal@819 14 url = reverse('contact-form')
bgneal@819 15 response = self.client.get(url)
bgneal@819 16 self.assertEqual(response.status_code, 200)
bgneal@819 17
bgneal@819 18 post_data = {
bgneal@819 19 'name': 'John Doe',
bgneal@819 20 'email': 'jdoe@example.com',
bgneal@819 21 'subject': 'Test message',
bgneal@819 22 'message': 'Testing contact form.',
bgneal@819 23 }
bgneal@819 24 response = self.client.post(url, data=post_data, follow=True)
bgneal@819 25 self.assertRedirects(response, reverse('contact-thanks'))
bgneal@819 26
bgneal@819 27 self.assertEqual(len(mail.outbox), 1)
bgneal@819 28 email = mail.outbox[0]
bgneal@819 29 self.assertEqual(len(email.recipients()), 1)
bgneal@819 30 self.assertEqual(email.from_email, post_data['email'])
bgneal@819 31 self.assertEqual(email.recipients()[0], 'admin@surfguitar101.com')
bgneal@819 32 self.assertTrue(post_data['subject'] in email.subject)
bgneal@819 33 msg = email.message().as_string()
bgneal@819 34 self.assertTrue(post_data['name'] in msg)
bgneal@819 35 self.assertTrue(post_data['email'] in msg)
bgneal@819 36 self.assertTrue(post_data['message'] in msg)
bgneal@819 37
bgneal@819 38 def test_honeypot(self):
bgneal@819 39 url = reverse('contact-form')
bgneal@819 40 post_data = {
bgneal@819 41 'name': 'John Doe',
bgneal@819 42 'email': 'jdoe@example.com',
bgneal@819 43 'subject': 'Test message',
bgneal@819 44 'message': 'Testing contact form.',
bgneal@819 45 'honeypot': 'some spam',
bgneal@819 46 }
bgneal@819 47 response = self.client.post(url, data=post_data)
bgneal@819 48 self.assertEqual(response.status_code, 200)
bgneal@819 49 self.assertEqual(len(mail.outbox), 0)