<s> from django . core . urlresolvers import reverse <EOL> from django . template import Template , Context <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from pinax . comments . forms import CommentForm <EOL> from pinax . comments . models import Comment <EOL> from . models import Demo <EOL> from . test import TestCase <EOL> class TestCaseMixin ( TestCase ) : <EOL> def get ( self , url_name , * args , ** kwargs ) : <EOL> data = kwargs . pop ( "<STR_LIT:data>" , { } ) <EOL> return self . get ( reverse ( url_name , args = args , kwargs = kwargs ) , data ) <EOL> def getajax ( self , url_name , * args , ** kwargs ) : <EOL> data = kwargs . pop ( "<STR_LIT:data>" , { } ) <EOL> return self . get ( reverse ( url_name , args = args , kwargs = kwargs ) , data , <EOL> HTTP_X_REQUESTED_WITH = "<STR_LIT>" ) <EOL> def post_comment_2 ( self , url_name , * args , ** kwargs ) : <EOL> url_name = "<STR_LIT>" + url_name <EOL> return self . post ( url_name , args = args , kwargs = kwargs ) <EOL> def postajax ( self , url_name , * args , ** kwargs ) : <EOL> data = kwargs . pop ( "<STR_LIT:data>" , { } ) <EOL> return self . post ( reverse ( url_name , args = args , kwargs = kwargs ) , data , <EOL> HTTP_X_REQUESTED_WITH = "<STR_LIT>" ) <EOL> def reload ( self , obj ) : <EOL> return obj . __class__ . _default_manager . get ( pk = obj . pk ) <EOL> def assert_renders ( self , tmpl , context , value ) : <EOL> tmpl = Template ( tmpl ) <EOL> self . assertEqual ( tmpl . render ( context ) , value ) <EOL> class CommentTests ( TestCaseMixin ) : <EOL> def setUp ( self ) : <EOL> super ( CommentTests , self ) . setUp ( ) <EOL> self . gimli = self . make_user ( username = "<STR_LIT>" ) <EOL> self . aragorn = self . make_user ( username = "<STR_LIT>" ) <EOL> def assert_renders ( self , tmpl , context , value ) : <EOL> tmpl = Template ( tmpl ) <EOL> self . assertEqual ( tmpl . render ( context ) , value ) <EOL> def post_comment ( self , obj , data ) : <EOL> return self . post ( <EOL> "<STR_LIT>" , <EOL> content_type_id = ContentType . objects . get_for_model ( obj ) . pk , <EOL> object_id = obj . pk , <EOL> data = data <EOL> ) <EOL> def test_post_comment ( self ) : <EOL> d = Demo . objects . create ( name = "<STR_LIT>" ) <EOL> response = self . post_comment ( d , data = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> self . response_302 ( response ) <EOL> self . assertEqual ( Comment . objects . count ( ) , <NUM_LIT:1> ) <EOL> c = Comment . objects . get ( ) <EOL> self . assertEqual ( c . author , None ) <EOL> self . assertEqual ( c . name , "<STR_LIT>" ) <EOL> response = self . post_comment ( d , data = { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ) <EOL> self . assertEqual ( Comment . objects . count ( ) , <NUM_LIT:1> ) <EOL> with self . login ( self . gimli ) : <EOL> response = self . post_comment ( d , data = { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ) <EOL> self . response_302 ( response ) <EOL> self . assertEqual ( Comment . objects . count ( ) , <NUM_LIT:2> ) <EOL> c = Comment . objects . order_by ( "<STR_LIT:id>" ) [ <NUM_LIT:1> ] <EOL> self . assertEqual ( c . comment , "<STR_LIT>" ) <EOL> self . assertEqual ( c . author , self . gimli ) <EOL> def test_delete_comment ( self ) : <EOL> d = Demo . objects . create ( name = "<STR_LIT>" ) <EOL> with self . login ( self . gimli ) : <EOL> response = self . post_comment ( d , data = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> comment = Comment . objects . get ( ) <EOL> response = self . post ( "<STR_LIT>" , pk = comment . pk ) <EOL> self . response_404 ( response ) <EOL> self . assertEqual ( Comment . objects . count ( ) , <NUM_LIT:1> ) <EOL> with self . login ( self . aragorn ) : <EOL> response = self . post ( "<STR_LIT>" , pk = comment . pk ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Comment . objects . count ( ) , <NUM_LIT:1> ) <EOL> with self . login ( self . gimli ) : <EOL> response = self . post ( "<STR_LIT>" , pk = comment . pk ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( Comment . objects . count ( ) , <NUM_LIT:0> ) <EOL> def test_ttag_comment_count ( self ) : <EOL> d = Demo . objects . create ( name = "<STR_LIT>" ) <EOL> self . post_comment ( d , data = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> self . post_comment ( d , data = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> self . assert_renders ( <EOL> "<STR_LIT>" , <EOL> Context ( { "<STR_LIT:o>" : d } ) , <EOL> "<STR_LIT:2>" <EOL> ) <EOL> def test_ttag_comments ( self ) : <EOL> d = Demo . objects . create ( name = "<STR_LIT>" ) <EOL> self . post_comment ( d , data = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> self . post_comment ( d , data = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } ) <EOL> c = Context ( { "<STR_LIT:o>" : d } ) <EOL> self . assert_renders ( <EOL> "<STR_LIT>" , <EOL> c , <EOL> "<STR_LIT>" <EOL> ) <EOL> self . assertEqual ( list ( c [ "<STR_LIT>" ] ) , list ( Comment . objects . all ( ) ) ) <EOL> def test_ttag_comment_form ( self ) : <EOL> d = Demo . objects . create ( name = "<STR_LIT>" ) <EOL> c = Context ( { "<STR_LIT:o>" : d } ) <EOL> self . assert_renders ( <EOL> "<STR_LIT>" , <EOL> c , <EOL> "<STR_LIT>" <EOL> ) <EOL> self . assertTrue ( isinstance ( c [ "<STR_LIT>" ] , CommentForm ) ) <EOL> with self . login ( self . gimli ) : <EOL> c = Context ( { "<STR_LIT:o>" : d , "<STR_LIT:user>" : self . user } ) <EOL> self . assert_renders ( <EOL> "<STR_LIT>" , <EOL> c , <EOL> "<STR_LIT>" <EOL> ) <EOL> self . assertTrue ( isinstance ( c [ "<STR_LIT>" ] , CommentForm ) ) <EOL> def test_ttag_comment_target ( self ) : <EOL> d = Demo . objects . create ( name = "<STR_LIT>" ) <EOL> self . assert_renders ( <EOL> "<STR_LIT>" , <EOL> Context ( { "<STR_LIT:o>" : d } ) , <EOL> "<STR_LIT>" % ( ContentType . objects . get_for_model ( d ) . pk , d . pk ) <EOL> ) </s>
