<s> from django . contrib . auth . models import User <EOL> from django . core . urlresolvers import reverse <EOL> from django . test . client import Client <EOL> from django_lean . experiments . models import ( AnonymousVisitor , Experiment , <EOL> GoalRecord , GoalType ) <EOL> from django_lean . experiments . tests . utils import TestCase <EOL> from django_lean . experiments . views import TRANSPARENT_1X1_PNG <EOL> class BugViewTest ( TestCase ) : <EOL> urls = '<STR_LIT>' <EOL> def call_goal ( self , client , goal ) : <EOL> url = reverse ( '<STR_LIT>' , <EOL> args = [ goal ] ) <EOL> response = client . get ( url ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEquals ( response [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> self . assertEquals ( response [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> self . assertEquals ( response . content , TRANSPARENT_1X1_PNG ) <EOL> def testPngResponse ( self ) : <EOL> experiment = Experiment ( name = "<STR_LIT>" ) <EOL> experiment . save ( ) <EOL> experiment . state = Experiment . ENABLED_STATE <EOL> experiment . save ( ) <EOL> goal_type = GoalType ( name = '<STR_LIT>' ) <EOL> goal_type . save ( ) <EOL> experiment_url = reverse ( "<STR_LIT>" , <EOL> args = [ experiment . name ] ) <EOL> confirm_human_url = reverse ( "<STR_LIT>" ) <EOL> client = Client ( ) <EOL> self . call_goal ( client , '<STR_LIT>' ) <EOL> self . call_goal ( client , '<STR_LIT>' ) <EOL> self . call_goal ( client , goal_type . name ) <EOL> self . assertEquals ( <NUM_LIT:0> , GoalRecord . objects . filter ( goal_type = goal_type ) . count ( ) ) <EOL> nb_anonymous_visitors = AnonymousVisitor . objects . count ( ) <EOL> response = client . get ( confirm_human_url ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> response = client . get ( experiment_url ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEquals ( nb_anonymous_visitors + <NUM_LIT:1> , <EOL> AnonymousVisitor . objects . count ( ) ) <EOL> client . get ( '<STR_LIT>' % experiment . name ) <EOL> self . assertEquals ( nb_anonymous_visitors + <NUM_LIT:1> , <EOL> AnonymousVisitor . objects . count ( ) ) <EOL> self . call_goal ( client , goal_type . name ) <EOL> self . assertEquals ( <NUM_LIT:1> , GoalRecord . objects . filter ( goal_type = goal_type ) . count ( ) ) <EOL> self . call_goal ( client , goal_type . name ) <EOL> self . assertEquals ( <NUM_LIT:2> , GoalRecord . objects . filter ( goal_type = goal_type ) . count ( ) ) <EOL> two_goal_records = GoalRecord . objects . filter ( goal_type = goal_type ) <EOL> self . assertEquals ( two_goal_records [ <NUM_LIT:0> ] . anonymous_visitor , <EOL> two_goal_records [ <NUM_LIT:1> ] . anonymous_visitor ) <EOL> client = Client ( ) <EOL> user = User ( username = "<STR_LIT>" , email = "<STR_LIT>" ) <EOL> user . set_password ( "<STR_LIT:password>" ) <EOL> user . save ( ) <EOL> response = client . login ( username = user . username , password = '<STR_LIT:password>' ) <EOL> self . assertTrue ( response ) <EOL> client . get ( '<STR_LIT>' % experiment . name ) <EOL> self . call_goal ( client , goal_type . name ) <EOL> self . assertEquals ( <NUM_LIT:2> , GoalRecord . objects . filter ( goal_type = goal_type ) . count ( ) ) </s>
