<s> import django <EOL> import time <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . sites . models import Site <EOL> from django . test import TestCase , Client <EOL> from django . utils import timezone <EOL> from fluent_comments import get_model as get_comment_model <EOL> from fluent_comments . compat import CommentForm <EOL> from article . models import Article <EOL> class CommentsTests ( TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> super ( CommentsTests , cls ) . setUpClass ( ) <EOL> Comment = get_comment_model ( ) <EOL> now = timezone . now ( ) <EOL> cls . site = Site . objects . get ( pk = <NUM_LIT:1> ) <EOL> cls . admin = User . objects . create_superuser ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> cls . article = Article . objects . create ( <EOL> title = "<STR_LIT>" , <EOL> slug = "<STR_LIT>" , <EOL> content = "<STR_LIT>" , <EOL> publication_date = now , <EOL> enable_comments = True , <EOL> ) <EOL> cls . article_ctype = ContentType . objects . get_for_model ( cls . article ) <EOL> cls . comment = Comment . objects . create ( <EOL> content_type = cls . article_ctype , <EOL> object_pk = cls . article . pk , <EOL> user = cls . admin , <EOL> user_name = "<STR_LIT>" , <EOL> user_email = "<STR_LIT>" , <EOL> user_url = "<STR_LIT>" , <EOL> comment = "<STR_LIT>" , <EOL> submit_date = now , <EOL> site = cls . site , <EOL> is_public = True , <EOL> is_removed = False , <EOL> ) <EOL> def test_admin_comments_access ( self ) : <EOL> self . client . login ( username = self . admin . username , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertContains ( response , "<STR_LIT>" , status_code = <NUM_LIT:200> ) <EOL> def test_get_article_with_comment ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , kwargs = { "<STR_LIT>" : "<STR_LIT>" } ) ) <EOL> self . assertContains ( response , "<STR_LIT>" , status_code = <NUM_LIT:200> ) <EOL> def test_get_article_with_comment ( self ) : <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , kwargs = { "<STR_LIT>" : "<STR_LIT>" } ) ) <EOL> self . assertContains ( response , "<STR_LIT>" , status_code = <NUM_LIT:200> ) <EOL> def test_comment_post ( self ) : <EOL> content_type = "<STR_LIT>" <EOL> object_pk = "<STR_LIT:1>" <EOL> timestamp = str ( int ( time . time ( ) ) ) <EOL> form = CommentForm ( Article ( ) ) <EOL> security_hash = form . generate_security_hash ( content_type , object_pk , timestamp ) <EOL> post_data = { <EOL> "<STR_LIT>" : content_type , <EOL> "<STR_LIT>" : object_pk , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : timestamp , <EOL> "<STR_LIT>" : security_hash , <EOL> } <EOL> response = self . client . post ( reverse ( "<STR_LIT>" ) , post_data , HTTP_X_REQUESTED_WITH = '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" , status_code = <NUM_LIT:200> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> , response . content . decode ( "<STR_LIT:utf-8>" ) ) </s>
