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 = getattr(settings, 'PROFANITIES_LIST', []), getattr(settings, 'COMMENTS_ALLOW_PROFANITIES', False) # 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()) # 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
def tamperWithForm(self, **kwargs): a = Article.objects.get(pk=1) d = self.getValidData(a) d.update(kwargs) f = CommentForm(Article.objects.get(pk=1), data=d) self.assertFalse(f.is_valid()) return f
def testValidPost(self): a = Article.objects.get(pk=1) f = CommentForm(a, data=self.getValidData(a)) self.assertTrue(f.is_valid(), f.errors) return f