<s> from random import choice <EOL> from django . conf import settings <EOL> from django . db import connection <EOL> from django . utils . six import text_type <EOL> from actstream . compat import get_user_model <EOL> from actstream . signals import action <EOL> from actstream . models import model_stream <EOL> from actstream . tests . base import ActivityBaseTestCase <EOL> class ZombieTest ( ActivityBaseTestCase ) : <EOL> human = <NUM_LIT:10> <EOL> zombie = <NUM_LIT:1> <EOL> def setUp ( self ) : <EOL> self . User = get_user_model ( ) <EOL> super ( ZombieTest , self ) . setUp ( ) <EOL> settings . DEBUG = True <EOL> player_generator = lambda n , count : [ self . User . objects . create ( <EOL> username = '<STR_LIT>' % ( n , i ) ) for i in range ( count ) ] <EOL> self . humans = player_generator ( '<STR_LIT>' , self . human ) <EOL> self . zombies = player_generator ( '<STR_LIT>' , self . zombie ) <EOL> self . zombie_apocalypse ( ) <EOL> def tearDown ( self ) : <EOL> settings . DEBUG = False <EOL> super ( ZombieTest , self ) . tearDown ( ) <EOL> def zombie_apocalypse ( self ) : <EOL> humans = self . humans [ : ] <EOL> zombies = self . zombies [ : ] <EOL> while humans : <EOL> for z in self . zombies : <EOL> victim = choice ( humans ) <EOL> humans . remove ( victim ) <EOL> zombies . append ( victim ) <EOL> action . send ( z , verb = '<STR_LIT>' , target = victim ) <EOL> if not humans : <EOL> break <EOL> def check_query_count ( self , queryset ) : <EOL> ci = len ( connection . queries ) <EOL> result = list ( [ map ( text_type , ( x . actor , x . target , x . action_object ) ) <EOL> for x in queryset ] ) <EOL> self . assertTrue ( len ( connection . queries ) - ci <= <NUM_LIT:4> , <EOL> '<STR_LIT>' % <EOL> len ( connection . queries ) ) <EOL> return result <EOL> def test_query_count ( self ) : <EOL> queryset = model_stream ( self . User ) <EOL> result = self . check_query_count ( queryset ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:10> ) <EOL> def test_query_count_sliced ( self ) : <EOL> queryset = model_stream ( self . User ) [ : <NUM_LIT:5> ] <EOL> result = self . check_query_count ( queryset ) <EOL> self . assertEqual ( len ( result ) , <NUM_LIT:5> ) </s>
