<s> from __future__ import absolute_import , unicode_literals <EOL> from django . contrib . auth . models import User , Permission <EOL> from django . contrib . comments import signals <EOL> from django . contrib . comments . models import Comment , CommentFlag <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . utils import translation <EOL> from . import CommentTestCase <EOL> class FlagViewTests ( CommentTestCase ) : <EOL> def testFlagGet ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . get ( "<STR_LIT>" % pk ) <EOL> self . assertTemplateUsed ( response , "<STR_LIT>" ) <EOL> def testFlagPost ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . post ( "<STR_LIT>" % pk ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , "<STR_LIT>" % pk ) <EOL> c = Comment . objects . get ( pk = pk ) <EOL> self . assertEqual ( c . flags . filter ( flag = CommentFlag . SUGGEST_REMOVAL ) . count ( ) , <NUM_LIT:1> ) <EOL> return c <EOL> def testFlagPostNext ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . post ( "<STR_LIT>" % pk , { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" % pk ) <EOL> def testFlagPostUnsafeNext ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . post ( "<STR_LIT>" % pk , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" % pk ) <EOL> def testFlagPostTwice ( self ) : <EOL> """<STR_LIT>""" <EOL> c = self . testFlagPost ( ) <EOL> self . client . post ( "<STR_LIT>" % c . pk ) <EOL> self . client . post ( "<STR_LIT>" % c . pk ) <EOL> self . assertEqual ( c . flags . filter ( flag = CommentFlag . SUGGEST_REMOVAL ) . count ( ) , <NUM_LIT:1> ) <EOL> def testFlagAnon ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> response = self . client . get ( "<STR_LIT>" % pk ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , "<STR_LIT>" % pk ) <EOL> response = self . client . post ( "<STR_LIT>" % pk ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , "<STR_LIT>" % pk ) <EOL> def testFlaggedView ( self ) : <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> response = self . client . get ( "<STR_LIT>" , data = { "<STR_LIT:c>" : pk } ) <EOL> self . assertTemplateUsed ( response , "<STR_LIT>" ) <EOL> def testFlagSignals ( self ) : <EOL> """<STR_LIT>""" <EOL> def receive ( sender , ** kwargs ) : <EOL> self . assertEqual ( kwargs [ '<STR_LIT>' ] . flag , CommentFlag . SUGGEST_REMOVAL ) <EOL> self . assertEqual ( kwargs [ '<STR_LIT>' ] . user . username , "<STR_LIT>" ) <EOL> received_signals . append ( kwargs . get ( '<STR_LIT>' ) ) <EOL> received_signals = [ ] <EOL> signals . comment_was_flagged . connect ( receive ) <EOL> self . testFlagPost ( ) <EOL> self . assertEqual ( received_signals , [ signals . comment_was_flagged ] ) <EOL> signals . comment_was_flagged . disconnect ( receive ) <EOL> def makeModerator ( username ) : <EOL> u = User . objects . get ( username = username ) <EOL> ct = ContentType . objects . get_for_model ( Comment ) <EOL> p = Permission . objects . get ( content_type = ct , codename = "<STR_LIT>" ) <EOL> u . user_permissions . add ( p ) <EOL> class DeleteViewTests ( CommentTestCase ) : <EOL> def testDeletePermissions ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . get ( "<STR_LIT>" % pk ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , "<STR_LIT>" % pk ) <EOL> makeModerator ( "<STR_LIT>" ) <EOL> response = self . client . get ( "<STR_LIT>" % pk ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def testDeletePost ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> makeModerator ( "<STR_LIT>" ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . post ( "<STR_LIT>" % pk ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , "<STR_LIT>" % pk ) <EOL> c = Comment . objects . get ( pk = pk ) <EOL> self . assertTrue ( c . is_removed ) <EOL> self . assertEqual ( c . flags . filter ( flag = CommentFlag . MODERATOR_DELETION , user__username = "<STR_LIT>" ) . count ( ) , <NUM_LIT:1> ) <EOL> def testDeletePostNext ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> makeModerator ( "<STR_LIT>" ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . post ( "<STR_LIT>" % pk , { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" % pk ) <EOL> def testDeletePostUnsafeNext ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> makeModerator ( "<STR_LIT>" ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . post ( "<STR_LIT>" % pk , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" % pk ) <EOL> def testDeleteSignals ( self ) : <EOL> def receive ( sender , ** kwargs ) : <EOL> received_signals . append ( kwargs . get ( '<STR_LIT>' ) ) <EOL> received_signals = [ ] <EOL> signals . comment_was_flagged . connect ( receive ) <EOL> self . testDeletePost ( ) <EOL> self . assertEqual ( received_signals , [ signals . comment_was_flagged ] ) <EOL> signals . comment_was_flagged . disconnect ( receive ) <EOL> def testDeletedView ( self ) : <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> response = self . client . get ( "<STR_LIT>" , data = { "<STR_LIT:c>" : pk } ) <EOL> self . assertTemplateUsed ( response , "<STR_LIT>" ) <EOL> class ApproveViewTests ( CommentTestCase ) : <EOL> def testApprovePermissions ( self ) : <EOL> """<STR_LIT>""" <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . get ( "<STR_LIT>" % pk ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , "<STR_LIT>" % pk ) <EOL> makeModerator ( "<STR_LIT>" ) <EOL> response = self . client . get ( "<STR_LIT>" % pk ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def testApprovePost ( self ) : <EOL> """<STR_LIT>""" <EOL> c1 , c2 , c3 , c4 = self . createSomeComments ( ) <EOL> c1 . is_public = False ; c1 . save ( ) <EOL> makeModerator ( "<STR_LIT>" ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . post ( "<STR_LIT>" % c1 . pk ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , "<STR_LIT>" % c1 . pk ) <EOL> c = Comment . objects . get ( pk = c1 . pk ) <EOL> self . assertTrue ( c . is_public ) <EOL> self . assertEqual ( c . flags . filter ( flag = CommentFlag . MODERATOR_APPROVAL , user__username = "<STR_LIT>" ) . count ( ) , <NUM_LIT:1> ) <EOL> def testApprovePostNext ( self ) : <EOL> """<STR_LIT>""" <EOL> c1 , c2 , c3 , c4 = self . createSomeComments ( ) <EOL> c1 . is_public = False ; c1 . save ( ) <EOL> makeModerator ( "<STR_LIT>" ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . post ( "<STR_LIT>" % c1 . pk , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" % c1 . pk ) <EOL> def testApprovePostUnsafeNext ( self ) : <EOL> """<STR_LIT>""" <EOL> c1 , c2 , c3 , c4 = self . createSomeComments ( ) <EOL> c1 . is_public = False ; c1 . save ( ) <EOL> makeModerator ( "<STR_LIT>" ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . post ( "<STR_LIT>" % c1 . pk , <EOL> { '<STR_LIT>' : "<STR_LIT>" } ) <EOL> self . assertEqual ( response [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" % c1 . pk ) <EOL> def testApproveSignals ( self ) : <EOL> def receive ( sender , ** kwargs ) : <EOL> received_signals . append ( kwargs . get ( '<STR_LIT>' ) ) <EOL> received_signals = [ ] <EOL> signals . comment_was_flagged . connect ( receive ) <EOL> self . testApprovePost ( ) <EOL> self . assertEqual ( received_signals , [ signals . comment_was_flagged ] ) <EOL> signals . comment_was_flagged . disconnect ( receive ) <EOL> def testApprovedView ( self ) : <EOL> comments = self . createSomeComments ( ) <EOL> pk = comments [ <NUM_LIT:0> ] . pk <EOL> response = self . client . get ( "<STR_LIT>" , data = { "<STR_LIT:c>" : pk } ) <EOL> self . assertTemplateUsed ( response , "<STR_LIT>" ) <EOL> class AdminActionsTests ( CommentTestCase ) : <EOL> urls = "<STR_LIT>" <EOL> def setUp ( self ) : <EOL> super ( AdminActionsTests , self ) . setUp ( ) <EOL> u = User . objects . get ( username = "<STR_LIT>" ) <EOL> u . is_staff = True <EOL> perms = Permission . objects . filter ( <EOL> content_type__app_label = '<STR_LIT>' , <EOL> codename__endswith = '<STR_LIT>' <EOL> ) <EOL> for perm in perms : <EOL> u . user_permissions . add ( perm ) <EOL> u . save ( ) <EOL> def testActionsNonModerator ( self ) : <EOL> comments = self . createSomeComments ( ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . get ( "<STR_LIT>" ) <EOL> self . assertNotContains ( response , "<STR_LIT>" ) <EOL> def testActionsModerator ( self ) : <EOL> comments = self . createSomeComments ( ) <EOL> makeModerator ( "<STR_LIT>" ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . get ( "<STR_LIT>" ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def testActionsDisabledDelete ( self ) : <EOL> "<STR_LIT>" <EOL> comments = self . createSomeComments ( ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertNotContains ( response , '<STR_LIT>' ) <EOL> def performActionAndCheckMessage ( self , action , action_params , expected_message ) : <EOL> response = self . client . post ( '<STR_LIT>' , <EOL> data = { '<STR_LIT>' : action_params , <EOL> '<STR_LIT:action>' : action , <EOL> '<STR_LIT:index>' : <NUM_LIT:0> } , <EOL> follow = True ) <EOL> self . assertContains ( response , expected_message ) <EOL> def testActionsMessageTranslations ( self ) : <EOL> c1 , c2 , c3 , c4 = self . createSomeComments ( ) <EOL> one_comment = c1 . pk <EOL> many_comments = [ c2 . pk , c3 . pk , c4 . pk ] <EOL> makeModerator ( "<STR_LIT>" ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> with translation . override ( '<STR_LIT>' ) : <EOL> self . performActionAndCheckMessage ( '<STR_LIT>' , one_comment , '<STR_LIT>' ) <EOL> self . performActionAndCheckMessage ( '<STR_LIT>' , many_comments , '<STR_LIT>' ) <EOL> self . performActionAndCheckMessage ( '<STR_LIT>' , one_comment , '<STR_LIT>' ) <EOL> self . performActionAndCheckMessage ( '<STR_LIT>' , many_comments , '<STR_LIT>' ) <EOL> self . performActionAndCheckMessage ( '<STR_LIT>' , one_comment , '<STR_LIT>' ) <EOL> self . performActionAndCheckMessage ( '<STR_LIT>' , many_comments , '<STR_LIT>' ) </s>
