annotate contact/tests/test_views.py @ 1157:e4f2d6a4b401

Rework S3 connection logic for latest versions of Python 2.7. Had to make these changes for Ubuntu 16.04. Seems backward compatible with production.
author Brian Neal <bgneal@gmail.com>
date Thu, 19 Jan 2017 18:35:53 -0600
parents 79a71b9d0a2a
children b957e4829a03
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@892 30 self.assertEqual(email.extra_headers['Reply-To'], post_data['email'])
bgneal@892 31 self.assertEqual(email.from_email, 'no_reply@example.com')
bgneal@819 32 self.assertEqual(email.recipients()[0], 'admin@surfguitar101.com')
bgneal@819 33 self.assertTrue(post_data['subject'] in email.subject)
bgneal@819 34 msg = email.message().as_string()
bgneal@819 35 self.assertTrue(post_data['name'] in msg)
bgneal@819 36 self.assertTrue(post_data['email'] in msg)
bgneal@819 37 self.assertTrue(post_data['message'] in msg)
bgneal@819 38
bgneal@819 39 def test_honeypot(self):
bgneal@819 40 url = reverse('contact-form')
bgneal@819 41 post_data = {
bgneal@819 42 'name': 'John Doe',
bgneal@819 43 'email': 'jdoe@example.com',
bgneal@819 44 'subject': 'Test message',
bgneal@819 45 'message': 'Testing contact form.',
bgneal@819 46 'honeypot': 'some spam',
bgneal@819 47 }
bgneal@819 48 response = self.client.post(url, data=post_data)
bgneal@819 49 self.assertEqual(response.status_code, 200)
bgneal@819 50 self.assertEqual(len(mail.outbox), 0)