mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Removed some direct settings manipulations in tests; refs #21230.
This commit is contained in:
committed by
Tim Graham
parent
499cd912ca
commit
3565efaa45
@@ -3,6 +3,7 @@ import time
|
||||
from django.conf import settings
|
||||
from django.contrib.comments.forms import CommentForm
|
||||
from django.contrib.comments.models import Comment
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from . import CommentTestCase
|
||||
from ..models import Article
|
||||
@@ -58,26 +59,18 @@ class CommentFormTests(CommentTestCase):
|
||||
c.save()
|
||||
self.assertEqual(Comment.objects.count(), 1)
|
||||
|
||||
@override_settings(PROFANITIES_LIST=["rooster"])
|
||||
def testProfanities(self):
|
||||
"""Test COMMENTS_ALLOW_PROFANITIES and PROFANITIES_LIST settings"""
|
||||
a = Article.objects.get(pk=1)
|
||||
d = self.getValidData(a)
|
||||
|
||||
# Save settings in case other tests need 'em
|
||||
saved = settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES
|
||||
|
||||
# Don't wanna swear in the unit tests if we don't have to...
|
||||
settings.PROFANITIES_LIST = ["rooster"]
|
||||
|
||||
# Try with COMMENTS_ALLOW_PROFANITIES off
|
||||
settings.COMMENTS_ALLOW_PROFANITIES = False
|
||||
f = CommentForm(a, data=dict(d, comment="What a rooster!"))
|
||||
self.assertFalse(f.is_valid())
|
||||
with self.settings(COMMENTS_ALLOW_PROFANITIES=False):
|
||||
f = CommentForm(a, data=dict(d, comment="What a rooster!"))
|
||||
self.assertFalse(f.is_valid())
|
||||
|
||||
# Now with COMMENTS_ALLOW_PROFANITIES on
|
||||
settings.COMMENTS_ALLOW_PROFANITIES = True
|
||||
f = CommentForm(a, data=dict(d, comment="What a rooster!"))
|
||||
self.assertTrue(f.is_valid())
|
||||
|
||||
# Restore settings
|
||||
settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES = saved
|
||||
with self.settings(COMMENTS_ALLOW_PROFANITIES=True):
|
||||
f = CommentForm(a, data=dict(d, comment="What a rooster!"))
|
||||
self.assertTrue(f.is_valid())
|
||||
|
||||
@@ -83,22 +83,19 @@ class CommentViewTests(CommentTestCase):
|
||||
|
||||
def testDebugCommentErrors(self):
|
||||
"""The debug error template should be shown only if DEBUG is True"""
|
||||
olddebug = settings.DEBUG
|
||||
|
||||
settings.DEBUG = True
|
||||
a = Article.objects.get(pk=1)
|
||||
data = self.getValidData(a)
|
||||
data["security_hash"] = "Nobody expects the Spanish Inquisition!"
|
||||
response = self.client.post("/post/", data)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertTemplateUsed(response, "comments/400-debug.html")
|
||||
|
||||
settings.DEBUG = False
|
||||
response = self.client.post("/post/", data)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertTemplateNotUsed(response, "comments/400-debug.html")
|
||||
with self.settings(DEBUG=True):
|
||||
response = self.client.post("/post/", data)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertTemplateUsed(response, "comments/400-debug.html")
|
||||
|
||||
settings.DEBUG = olddebug
|
||||
with self.settings(DEBUG=False):
|
||||
response = self.client.post("/post/", data)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertTemplateNotUsed(response, "comments/400-debug.html")
|
||||
|
||||
def testCreateValidComment(self):
|
||||
address = "1.2.3.4"
|
||||
|
||||
Reference in New Issue
Block a user