<s> from __future__ import absolute_import <EOL> import time <EOL> from django . conf import settings <EOL> from django . contrib . comments . forms import CommentForm <EOL> from django . contrib . comments . models import Comment <EOL> from . import CommentTestCase <EOL> from . . models import Article <EOL> class CommentFormTests ( CommentTestCase ) : <EOL> def testInit ( self ) : <EOL> f = CommentForm ( Article . objects . get ( pk = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( f . initial [ '<STR_LIT>' ] , str ( Article . _meta ) ) <EOL> self . assertEqual ( f . initial [ '<STR_LIT>' ] , "<STR_LIT:1>" ) <EOL> self . assertNotEqual ( f . initial [ '<STR_LIT>' ] , None ) <EOL> self . assertNotEqual ( f . initial [ '<STR_LIT>' ] , None ) <EOL> def testValidPost ( self ) : <EOL> a = Article . objects . get ( pk = <NUM_LIT:1> ) <EOL> f = CommentForm ( a , data = self . getValidData ( a ) ) <EOL> self . assertTrue ( f . is_valid ( ) , f . errors ) <EOL> return f <EOL> def tamperWithForm ( self , ** kwargs ) : <EOL> a = Article . objects . get ( pk = <NUM_LIT:1> ) <EOL> d = self . getValidData ( a ) <EOL> d . update ( kwargs ) <EOL> f = CommentForm ( Article . objects . get ( pk = <NUM_LIT:1> ) , data = d ) <EOL> self . assertFalse ( f . is_valid ( ) ) <EOL> return f <EOL> def testHoneypotTampering ( self ) : <EOL> self . tamperWithForm ( honeypot = "<STR_LIT>" ) <EOL> def testTimestampTampering ( self ) : <EOL> self . tamperWithForm ( timestamp = str ( time . time ( ) - <NUM_LIT> ) ) <EOL> def testSecurityHashTampering ( self ) : <EOL> self . tamperWithForm ( security_hash = "<STR_LIT>" ) <EOL> def testContentTypeTampering ( self ) : <EOL> self . tamperWithForm ( content_type = "<STR_LIT>" ) <EOL> def testObjectPKTampering ( self ) : <EOL> self . tamperWithForm ( object_pk = "<STR_LIT:3>" ) <EOL> def testSecurityErrors ( self ) : <EOL> f = self . tamperWithForm ( honeypot = "<STR_LIT>" ) <EOL> self . assertTrue ( "<STR_LIT>" in f . security_errors ( ) ) <EOL> def testGetCommentObject ( self ) : <EOL> f = self . testValidPost ( ) <EOL> c = f . get_comment_object ( ) <EOL> self . assertIsInstance ( c , Comment ) <EOL> self . assertEqual ( c . content_object , Article . objects . get ( pk = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( c . comment , "<STR_LIT>" ) <EOL> c . save ( ) <EOL> self . assertEqual ( Comment . objects . count ( ) , <NUM_LIT:1> ) <EOL> def testProfanities ( self ) : <EOL> """<STR_LIT>""" <EOL> a = Article . objects . get ( pk = <NUM_LIT:1> ) <EOL> d = self . getValidData ( a ) <EOL> saved = settings . PROFANITIES_LIST , settings . COMMENTS_ALLOW_PROFANITIES <EOL> settings . PROFANITIES_LIST = [ "<STR_LIT>" ] <EOL> settings . COMMENTS_ALLOW_PROFANITIES = False <EOL> f = CommentForm ( a , data = dict ( d , comment = "<STR_LIT>" ) ) <EOL> self . assertFalse ( f . is_valid ( ) ) <EOL> settings . COMMENTS_ALLOW_PROFANITIES = True <EOL> f = CommentForm ( a , data = dict ( d , comment = "<STR_LIT>" ) ) <EOL> self . assertTrue ( f . is_valid ( ) ) <EOL> settings . PROFANITIES_LIST , settings . COMMENTS_ALLOW_PROFANITIES = saved </s>
