<s> """<STR_LIT>""" <EOL> from facebook . graph import GraphAPIError <EOL> from facebook . fb import TestUser , User <EOL> from facebook . testusers import TestUsers <EOL> from facebook import get_app_dict , get_static_graph <EOL> from scaffolding . tubes import Tube <EOL> class FacebookTestUser ( Tube ) : <EOL> def __init__ ( self , app_name = None , unique = False , ** kwargs ) : <EOL> super ( FacebookTestUser , self ) . __init__ ( ** kwargs ) <EOL> self . app_name = app_name <EOL> self . unique = unique <EOL> self . graph = get_static_graph ( self . app_name ) <EOL> self . testusers = TestUsers ( self . graph ) <EOL> self . users = [ ] <EOL> self . index = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def set_up ( self , cls , count , ** kwargs ) : <EOL> testuser_list = self . testusers . get_test_users ( ) <EOL> if count and count > len ( testuser_list ) : <EOL> remaining = count - len ( testuser_list ) <EOL> try : <EOL> print '<STR_LIT>' % ( len ( testuser_list ) , <EOL> count - len ( testuser_list ) ) <EOL> except IOError : <EOL> pass <EOL> for i in range ( remaining ) : <EOL> self . _generate_new_user ( ) <EOL> self . _user_for_testuser ( testuser_list ) <EOL> def _user_for_testuser ( self , testuser_list ) : <EOL> try : <EOL> print u'<STR_LIT>' <EOL> except IOError : <EOL> pass <EOL> for testuser in testuser_list : <EOL> user , created = User . objects . get_or_create ( id = int ( testuser . id ) ) <EOL> if created : <EOL> user . get_from_facebook ( self . graph , save = True ) <EOL> self . users . append ( user ) <EOL> try : <EOL> print u'<STR_LIT>' % len ( testuser_list ) <EOL> except IOError : <EOL> pass <EOL> def _generate_new_user ( self ) : <EOL> newuser = self . testusers . generate_new_test_user ( installed = True , permissions = [ '<STR_LIT:email>' ] ) <EOL> try : <EOL> print u'<STR_LIT>' % newuser <EOL> except IOError : <EOL> pass <EOL> user , created = User . objects . get_or_create ( id = int ( newuser . id ) ) <EOL> if created : <EOL> user . get_from_facebook ( self . graph , save = True ) <EOL> self . users . append ( user ) <EOL> return user <EOL> def next ( self ) : <EOL> if self . index == len ( self . users ) - <NUM_LIT:1> : <EOL> if self . unique : <EOL> try : <EOL> return self . _generate_new_user ( ) <EOL> except GraphAPIError : <EOL> raise StopIteration <EOL> else : <EOL> self . index = <NUM_LIT:0> <EOL> return self . users [ self . index ] <EOL> self . index += <NUM_LIT:1> <EOL> return self . users [ self . index ] </s>
