-
-
Notifications
You must be signed in to change notification settings - Fork 939
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
210 additions
and
170 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
from __future__ import unicode_literals | ||
|
||
import logging | ||
|
||
from datetime import timedelta | ||
|
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,57 @@ | ||
from unittest import skipIf | ||
|
||
import requests | ||
from django.core import mail | ||
from django.test import TestCase | ||
from django.test.utils import override_settings | ||
|
||
|
||
@override_settings(AKISMET_API_KEY='') # Disable Akismet in tests | ||
def check_network_connection(): | ||
try: | ||
requests.get('https://djangoproject.com') | ||
except requests.exceptions.ConnectionError: | ||
return False | ||
return True | ||
|
||
|
||
has_network_connection = check_network_connection() | ||
print(has_network_connection) | ||
|
||
|
||
@override_settings(AKISMET_TESTING=True) | ||
class ContactFormTests(TestCase): | ||
def test_foundation_contact(self): | ||
data = { | ||
def setUp(self): | ||
self.url = '/contact/foundation/' | ||
|
||
@override_settings(AKISMET_API_KEY='') # Disable Akismet in tests | ||
def test_without_akismet(self): | ||
response = self.client.post(self.url, { | ||
'name': 'A. Random Hacker', | ||
'email': 'a.random@example.com', | ||
'message_subject': 'Hello', | ||
'body': 'Hello, World!' | ||
} | ||
resp = self.client.post('/contact/foundation/', data) | ||
self.assertRedirects(resp, '/contact/sent/') | ||
}) | ||
self.assertRedirects(response, '/contact/sent/') | ||
self.assertEqual(mail.outbox[-1].subject, '[Contact form] Hello') | ||
|
||
@skipIf(not has_network_connection, 'Requires a network connection') | ||
def test_akismet_detect_spam(self): | ||
response = self.client.post(self.url, { | ||
'name': 'viagra-test-123', # according to akismet this should flag as spam | ||
'email': 'a.random@example.com', | ||
'message_subject': 'Hello', | ||
'body': 'Hello, World!' | ||
}) | ||
self.assertContains(response, 'Akismet thinks this message is spam') | ||
self.assertEqual(len(mail.outbox), 0) | ||
|
||
@skipIf(not has_network_connection, 'Requires a network connection') | ||
def test_akismet_not_spam(self): | ||
response = self.client.post(self.url, { | ||
'name': 'administrator', | ||
'email': 'a.random@example.com', | ||
'message_subject': 'Hello', | ||
'body': 'Hello, World!' | ||
}) | ||
self.assertRedirects(response, '/contact/sent/') | ||
self.assertEqual(mail.outbox[-1].subject, '[Contact form] Hello') |
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
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
Oops, something went wrong.