From 3565efaa451db6eb735a085ea6aae3fe86e6d283 Mon Sep 17 00:00:00 2001 From: Bouke Haarsma Date: Mon, 14 Oct 2013 15:14:17 +0200 Subject: Removed some direct settings manipulations in tests; refs #21230. --- tests/comment_tests/tests/test_comment_form.py | 23 ++++++++--------------- tests/comment_tests/tests/test_comment_view.py | 19 ++++++++----------- 2 files changed, 16 insertions(+), 26 deletions(-) (limited to 'tests/comment_tests') diff --git a/tests/comment_tests/tests/test_comment_form.py b/tests/comment_tests/tests/test_comment_form.py index bca339fd3d..205b4150e8 100644 --- a/tests/comment_tests/tests/test_comment_form.py +++ b/tests/comment_tests/tests/test_comment_form.py @@ -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()) diff --git a/tests/comment_tests/tests/test_comment_view.py b/tests/comment_tests/tests/test_comment_view.py index 731776a1e2..653419d168 100644 --- a/tests/comment_tests/tests/test_comment_view.py +++ b/tests/comment_tests/tests/test_comment_view.py @@ -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" -- cgit v1.3