<gh_stars>0
from models import *
from random import randint


FFBSKT_URL = '<KEY>'
BASKETBALL_GROUP_URL = '<KEY>'

def start(self):
    self.Clear(Answer())
    #key = ndb.Key(Group, '<EMAIL>', Group, 'General parametrs')
    group = GroupStat(name='General parametrs', st_name=['name', 'content','rate'], st_opt=['name','0','hist'], st_ifbase=[True, True, True], role_propertys_add=[{'name':'admin', 'change':['content', 'rate', '@name'], 'visible': []}, {'name':'user' , 'change':['@content'], 'visible': ['name', 'content','rate']}])
    self.create_group(group)	
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='General parametrs', group_creator='<EMAIL>', role='admin'))
    self.add_user(User(mail='@unknown', name='unknown')) # write timer for unknown  

    group = GroupStat(name='Basketball', st_name=['name', 'rate', 'visit'], st_opt=['name','hist', 'hist'], st_ifbase=[True, True, False], role_propertys_add=[{'name':'admin', 'change':['visit', '@invite'], 'visible': ['name', 'rate']}, {'name':'user' , 'change':[], 'visible': ['name', 'rate', 'visit']}])
    self.create_group(group)	
    group = GroupStat(name='Math', st_name=['name', 'rate','lesson_plus', 'hom_work', 'hom_work'], st_opt=['name','hist', '0','nero','ranking'], st_ifbase=[True, True, False, False, False], role_propertys_add=[{'name':'admin', 'change':['lesson_plus', 'hom_work'], 'visible': ['name']}, {'name':'user' , 'change':[], 'visible': ['name','rate', 'lesson_plus', 'hom_work']}])
    self.create_group(group)	
    group = GroupStat(name='Gim', st_name=['name', 'visit', 'all_tickets'], st_opt=['name','0','0'], st_ifbase=[True, False, False], role_propertys_add=[{'name':'admin', 'change':['visit'], 'visible': ['name','all_tickets']}, {'name':'user' , 'change':[], 'visible': ['name', 'visit', 'all_tickets']}])
    self.create_group(group)
    group = GroupStat(name='Tmp', st_name=['name'], st_opt=['name'], st_ifbase=[True], role_propertys_add=[{'name':'admin', 'change':[], 'visible': []}, {'name':'user' , 'change':[], 'visible': ['name']}])
    self.create_group(group)
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='admin'))

    group = GroupStat(name='Verify', st_name=['name', 'rate', 'name_verify',  'name_verify'], st_opt=['name','hist', 'nero','ranking'], st_ifbase=[True, True, False, False], role_propertys_add=[{'name':'admin', 'change':[], 'visible': ['name']}, {'name':'user' , 'change':['name_verify'], 'visible': ['name','rate']}])
    self.create_group(group)
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Verify', group_creator='<EMAIL>', role='admin'))
    
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='admin'))
	#group = GroupStat(name='Tornament', st_name=['name', 'avatar', 'content', 'rate'], st_opt=['0','0','photo','points'], st_ifbase=[True, True, True, True], role_propertys_add=[{'name':'referi', 'change':['points'], 'visible': ['name', 'avatar']}, {'name':'team' , 'change':[], 'visible': ['name', 'visit', 'all_tickets']}])
	    #self.create_group(group)			
	#st_name - add all teams score, and points 

#------------------------------------------------------TESTS__________________________________________------
def T_f(self, param={'mail':'<EMAIL>'}, mescls=User, f='add_user'):
    print '$$ T_f ', f
    u = mescls(**param)
    T={}		
    getattr(self, f)(u)
    

def T_rating_test(self):
    param={'name':'RT La', 'st_name':['name', 'avatar', '1km', '400m', 'jump'], 'st_opt':['0', 'photo', 'ranking','ranking','ranking'], 'st_place':[1,1,2], 'st_w':[2.0,3.0,4.0], 'st_ifbase':[True,True,False,False,False], 'role_propertys_add':[{'name':'admin', 'change':['1km', '400m', 'jump','@invite'] , 'visible': ['name']}, {'name':'@open', 'change':[],'visible': ['name','1km', '400m', 'jump']}]}	
    T_f(self, param=param, mescls=GroupStat, f='create_group')
    print "TEST______________"	
    T_f(self,  param={'child_object':'<EMAIL>', 'group_name':'RT La', 'group_creator':'<EMAIL>', 'role':'admin'}, mescls=PutObjectTo, f='put_object_to_group')
    T_f(self, param={'child_object':'<EMAIL>', 'group_name':'RT La', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')
    #Need group url in st_block and obj url	
    T_f(self, param={'url':'<KEY>', 'stat_block':[{'group_url':'<KEY>', 'return_ch':[0], 'st_name':['1km'], 'st_def':['456'], 'st_opt':['ranking']},  ]}, mescls=User, f='edit_user')
    
    T_f(self, param={'group_url':'<KEY>'}, mescls=Show, f='compute_rate')
    group_url = ndb.Key(Group, '<EMAIL>', Group, 'RT La').urlsafe()			
    for user in ['a@','b@','c@','d@']:
	T_f(self, param={'child_object':user, 'group_name':'RT La', 'group_creator':'<EMAIL>', 'role':'admin'}, mescls=PutObjectTo, f='put_object_to_group')
    #param={'url':ndb.Key(Base, user).urlsafe(), 'stat_block':[{'group_url':group_url, 'return_ch':[0,1,2], 'st_name':['1km', '400m', 'jump'], 'st_def':[str(randint(240, 340)/60.0), str(randint(45, 80)), str(randint(140, 240))], 'st_opt':['ranking', 'ranking', 'ranking']},  ]}
    for res in range(3):
	add_stat(['a@','b@','c@','d@', '<EMAIL>'], 'RT La', param, self, )
	T_f(self, param={'group_url':ndb.Key(Group, '<EMAIL>', Group, 'RT La').urlsafe()}, mescls=Show, f='compute_rate')
	

def add_stat(users, group, param, self, athors=[], group_creator='<EMAIL>'):
    urls = []	
    group_url = ndb.Key(Group, group_creator, Group, group).urlsafe()	
    if athors == []:
	for user in users:
	    urls.append(ndb.Key(Base, user).urlsafe())
    else:
	for user, auth in zip(users, athors):
	    urls.append(ndb.Key(Group, auth, Group, user).urlsafe())
     		 	
    for url in urls:	
	print "-__________", urls, group, group_url, ndb.Key(ObjectToGroup, group_url, ObjectToGroup, url).get()
	#user_url = ndb.Key(ObjectToGroup, group_url, ObjectToGroup, url).urlsafe()
	user_param={'url':url, 'stat_block':[{'group_url':group_url, 'return_ch':[], 'st_name':[], 'st_def':[], 'st_opt':[]}]}
	j=0
	for i, par in enumerate(param['st_opt']):
	    if par == 'ranking':
		user_param['stat_block'][0]['st_def'].append(str(randint(0, 40)))
		user_param['stat_block'][0]['return_ch'].append(j)
		user_param['stat_block'][0]['st_name'].append(param['st_name'][i])
		user_param['stat_block'][0]['st_opt'].append('ranking')
		j+=1 
	T_f(self, param=user_param, mescls=User, f='edit_user')
	print "ADD STAT", user_param
 	


#-----------------------Group Structure Test---------------------------------------------------------
def put_to(child, gr_name, ch_aut='<EMAIL>', gr_aut='<EMAIL>', role='group'):
    param={'child_object':child, 'child_gr_author':ch_aut, 'group_name':gr_name, 'group_creator':gr_aut, 'role':role} 
    return {'param':param, 'mescls':PutObjectTo, 'f':'put_object_to_group'}	  
    #T_f(self, , param=param, mescls=PutObjectTo, f='put_object_to_group')	
    
def T_group_structure(self, ):
    T_f(self, param={'name':'Sport', 'st_name':['name', 'popularity', 'activity'], 'st_opt':['name', 'ranking','ranking'], 'st_place':[2,2], 'st_w':[1.0,2.0], 'st_ifbase':[True,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name','popularity', 'activity']}]}, mescls=GroupStat, f='create_group')
    # Add weight like for level	
    T_f(self,  param={'name':'Bskt', 'st_name':['name', 'level'], 'st_opt':['0', 'ranking'], 'st_place':[2], 'st_w':[1.0], 'st_ifbase':[True,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name','level']}]}, mescls=GroupStat, f='create_group')
    T_f(self,  param={'name':'Normatives', 'st_name':['name', '1km', '400m', 'jump'], 'st_opt':['name', 'ranking', 'ranking', 'ranking'], 'st_place':[1,1,2], 'st_w':[2.0,3.0,4.0], 'st_ifbase':[True,False,False,False], 'role_propertys_add':[{'name':'participant', 'change':[],'visible': ['name','1km', '400m', 'jump']}, {'name':'@open', 'change':[],'visible': ['name','1km', '400m', 'jump']}]}, mescls=GroupStat, f='create_group')	
    T_f(self,  param={'name':'Referi', 'st_name':['name', 'games', 'mark', 'mark'], 'st_opt':['name', 'ranking', 'ranking', 'nero'], 'st_place':[2,2], 'st_w':[1.0, 2.0], 'st_ifbase':[True,False,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name', 'games', 'mark']}]}, mescls=GroupStat, f='create_group')	
    T_f(self,  param={'name':'BsktNormatives', 'st_name':['name', 'freethrow', '3points', '8flors'], 'st_opt':['name', 'ranking','ranking','ranking'], 'st_place':[2,2,1], 'st_w':[1.0,1.3,1.4], 'st_ifbase':[True,False,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name', 'freethrow', '3points', '8flors']}]}, mescls=GroupStat, f='create_group')
    T_f(self,  param={'name':'Tornament', 'st_name':['name', 'games', 'vin'], 'st_opt':['name', '0', 'ranking'], 'st_place':[2], 'st_w':[1.0], 'st_ifbase':[True,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name', 'games', 'vin']}]}, mescls=GroupStat, f='create_group')

    param={'name':'Team2', 'st_name':['name', 'games', 'points', 'role', 'cr'], 'st_opt':['name', '0', 'ranking', '0','0'], 'st_place':[2], 'st_w':[1.0], 'st_ifbase':[True,False,False,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name', 'games', 'points', 'role']}, {'name':'player', 'change':[],'visible': ['name', 'games', 'points', 'role']}, {'name':'crowd','change':[],'visible': ['name', 'cr', 'points']}]}
    for team in ['Team1', 'Team2', 'Team3']:
	param['name'] = team	
        T_f(self, param=param, mescls=GroupStat, f='create_group')
    #T_f(self,  param=param, mescls=GroupStat, f='create_group')
    #T_f(self,  param=param, mescls=GroupStat, f='create_group')

    #put groups
    T_f(self,  **put_to(child='Normatives', gr_name='Sport'))
    T_f(self,  **put_to(child='Referi', gr_name='Normatives'))	
    T_f(self,  **put_to(child='Bskt', gr_name='Sport'))
    T_f(self,  **put_to(child='Referi', gr_name='Bskt'))
    T_f(self, **put_to(child='BsktNormatives', gr_name='Bskt'))
    T_f(self, **put_to(child='Tornament', gr_name='Bskt'))
    T_f(self, **put_to(child='Team1', gr_name='Tornament'))
    T_f(self,  **put_to(child='Team2', gr_name='Tornament'))
    T_f(self,  **put_to(child='Team3', gr_name='Tornament'))		
    
    #put users
    T_f(self,  param={'child_object':'<EMAIL>', 'group_name':'General parametrs', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')	
    T_f(self,  param={'child_object':'<EMAIL>', 'group_name':'Tornament', 'group_creator':'<EMAIL>', 'role':'__creator'}, mescls=PutObjectTo, f='put_object_to_group')			
    for user in ['cr1@','cr2@','cr3@','cr4@','cr5@','bpl1@','bpl2@','bpl3@','bpl4@','bpl5@',
		'bpl6@','bpl7@','bpl8@','bpl9@','bpl10@','la1@','la2@','la3@']:
	T_f(self,  param={'child_object':user, 'group_name':'General parametrs', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')
    #for user in ['bpl1@','bpl2@','bpl3@']:
	#T_f(self,  param={'child_object':user, 'group_name':'Team3', 'group_creator':'<EMAIL>', 'role':'player'}, mescls=PutObjectTo, f='put_object_to_group')
    for user in ['bpl4@','bpl5@','bpl6@']:
	T_f(self,  param={'child_object':user, 'group_name':'Team1', 'group_creator':'<EMAIL>', 'role':'player'}, mescls=PutObjectTo, f='put_object_to_group')
    for user in ['cr1@','cr2@','cr3@','<EMAIL>']:
	T_f(self,  param={'child_object':user, 'group_name':'Team1', 'group_creator':'<EMAIL>', 'role':'crowd'}, mescls=PutObjectTo, f='put_object_to_group')		
    for user in ['bpl7@','bpl8@','bpl9@']:
	T_f(self,  param={'child_object':user, 'group_name':'Team2', 'group_creator':'<EMAIL>', 'role':'player'}, mescls=PutObjectTo, f='put_object_to_group')			
    for user in ['bpl1@','la1@','la2@','la3@']:
	T_f(self,  param={'child_object':user, 'group_name':'Normatives', 'group_creator':'<EMAIL>', 'role':'participant'}, mescls=PutObjectTo, f='put_object_to_group')
    #T_f(self,  param={'child_object':'<EMAIL>', 'group_name':'RT La', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')	
    add_stat(['bpl7@','bpl8@','bpl9@'], 'Team2', param, self)


#___________________________________________________________________________________________________	

def T_high_perfomance(self):
    #print '111', 'qwertyuiopasdfghjklzxcvbnm'
	 
    #T_f(self,  param={'user_url':FFBSKT_URL, 'is_add': True, 'group':BASKETBALL_GROUP_URL, 'role':'__id'}, mescls=EditRole, f='edit_role')	
    for i in 'qwertyuiopas':
	for j in 'qwertyuiopasdfghjklz':
	    #print i+j+k+'@'
	    pass
	    #T_f(self, param={'child_object':i+j+'@', 'group_name':'General parametrs', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')
	    #T_f(self,  param={'child_object':i+j+'@', 'group_name':'Basketball', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')
	    url = ndb.Key(Base, i+j+'@').urlsafe()	
	    #T_f(self,  param={'child_object':url, 'attribute_name': 'name', 'value':i+j}, mescls=EditEntityAttr, f='edit_entity_value')	
    cid = 34		
    for i in 'qwertyuiopas':
	for j in 'qwertyuiopasdfghjklz':	
	    T_f(self,  param={'card_id':str(cid), 'child_object':i+j+'@', 'group_url':BASKETBALL_GROUP_URL, 'stat_pls':'visit'}, mescls=CardId, f='use_card')
	    cid += 1	


def T_show(self, name1, name2, p=None):
    if not p:
        p=name2
    #print '--T Show', repr(name1)	
    #print len(ndb.Key(Base, name1).get().a_f)
    print 'group = ', ndb.Key(Group, name2).get()
    print ndb.Key(ObjectToGroup, name1, ObjectToGroup, p).get()
    print '\no b j ', (ObjectToGroup.query(ObjectToGroup.name==name1, ObjectToGroup.group_name==name2).fetch())
#(ObjectToGroup.query(ObjectToGroup.name==name1).filter(ObjectToGroup.group_name==name2).fetch())
def T_remove_all(self, message):
    s = 1000 
    entr = Base.query().fetch()
    list_of_keys = ndb.put_multi(entr)	
    #for i in entr:
    #    memcache.delete(i.mail, s)
    ndb.delete_multi(list_of_keys)
    entr = ObjectToGroup.query().fetch()
    list_of_keys = ndb.put_multi(entr)	
    #for i in entr:
    #    memcache.delete(i.key, s)
    ndb.delete_multi(list_of_keys)
    entr = Group.query().fetch()
    list_of_keys = ndb.put_multi(entr)	
    ndb.delete_multi(list_of_keys) 
    entr = NeroStat.query().fetch()
    list_of_keys = ndb.put_multi(entr)	
    ndb.delete_multi(list_of_keys) 	  
    #for i in entr:
    #    memcache.delete(i.key, s)
    

def T_in_out_group(self, message):
    gp=GroupStat(name='Tparent', st_name=['lesson_remain', 'lesson_value'], role_propertys_add=[{'name':'admin' , 'change':['lesson_value','@invite', 'lesson_remain'] , 'visible': ['name']},{'name':'user' , 'change':['@name','@content'] , 'visible': ['lesson_remain', 'lesson_value']}])
    self.create_group(gp)
    ga=GroupStat(name='TchildA', parent_group='Tparent', st_name=['lesson_remain', 'lesson_value'], role_propertys_add=[{'name':'admin' , 'change':['lesson_value','@invite', 'lesson_remain'] , 'visible': ['name']},{'name':'user' , 'change':['@name','@content'] , 'visible': ['lesson_remain', 'lesson_value']}])
    self.create_group(ga)
    gb=GroupStat(name='TchildB', parent_group='Tparent', st_name=['lesson_remain', 'lesson_value'], role_propertys_add=[{'name':'admin' , 'change':['@invite'] , 'visible': ['name']},{'name':'user' , 'change':['@name','@content', 'lesson_value', 'lesson_remain'] , 'visible': ['lesson_remain', 'lesson_value']}])
    self.create_group(gb)
    gc=GroupStat(name='TchildC', parent_group='Tparent', st_name=[], role_propertys_add=[{'name':'ara' , 'change':['content'] , 'visible': ['name']}])
    self.create_group(gc)
    
    test_ask_put(self, gname='Tparent', observer='test_a_u@')
    #print
    
    test_ask_put(self, gname='TchildA',observer='test_a_u@', invite=True)
    #time.sleep(3)
    test_ask_put(self, gname='TchildB',observer='test_a_u@') 	
    #time.sleep(3)
    test_ask_put(self, gname='TchildC',observer='test_a_u@')
    test_ask_put(self, gname='TchildA',observer='test_a_u@', invite=True)


def card_test_prepare(self, message):
    ga=GroupStat(name='A', st_name=['u_f', 'a_f', 'lesson_in'], role_propertys_add=[{'name':'admin' , 'change':['a_f','@invite'] , 'visible': ['u_f', 'a_f']}])
    self.create_group(ga)
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='A', role='admin'))
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='A', role='user'))
    print "++create group + 2 users nomad & ff"
    #gupd = GroupStat(name='A', st_name=['card'], st_opt=['+@u_f'], role_propertys_add=[{'name':'admin', 'change':['card'], 'visible': []}])
    #self.update_group(gupd)
    self.use_card(CardId(card_id='123', child_object='<EMAIL>', stat_pls='u_f'))
    self.use_card(CardId(card_id='123', stat_pls='u_f'))

def T_fill_attr(self):
    self.start(Answer())
    ga=GroupStat(name='A', st_name=['name', 'name', 'lesson_in', 'lesson_in', 'jump'], st_opt=['0','like','nero',"ranking","ranking"], st_ifbase=[True, True, False,False,False], st_place=[0], role_propertys_add=[{'name':'admin' , 'change':['name', 'lesson_in', 'jump', '@invite'], 'visible': []}, {'name':'user' , 'change':['lesson_in','jump'] , 'visible': []}])
    self.create_group(ga)
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='A', group_creator='<EMAIL>', role='admin'))	
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='A', group_creator='<EMAIL>', role='user'))
    #self.put_object_to_group(PutObjectTo(child_object='1@', group_name='A', role='user', kind='user'))
    print "TEST CREATE GROUP COPY TMP"
    gb=CopyGroup(old_name='A', old_author='<EMAIL>', new_name='b')
    self.copy_template(gb)
    print "TEST PUT USER AND GROUP"	
    #self.put_object_to_group(PutObjectTo(child_object='b', group_name='A', kind='group'))
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='b', role='admin', kind='user'))	
    #-self.create_group(gb)	
    #-self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='B', role='admin', kind='user'))
    gp=GroupStat(name='U', st_name=['hw', 'lesson_in2', 'name'], st_opt=['photo',"nero",'0'], st_ifbase=[False,False,True], role_propertys_add=[{'name':'admin' , 'change':[], 'visible': []}])
    self.create_group(gp)	
    self.put_object_to_group(PutObjectTo(child_object='U', child_gr_author='<EMAIL>', group_name='A', group_creator='<EMAIL>'))	
    T_show_user(self, Answer(), u='ahFkZXZ-dW5pdmVyc2l0eWdpbXIaCxIEQmFzZSIQZmZic2t0QGdtYWlsLmNvbQw', s='<EMAIL>')


def T_Nero(self):
    print '--T Edit Nero stat'
    u1 = User(mail='<EMAIL>', return_ch=[0,], st_def=['23',], st_name=['lesson_in',], st_opt=['nero',])
    self.edit_user(u1)
    u1.mail = '1@'
    self.edit_user(u1)
    entity = ndb.Key(Base, '1@').get()
    self.fill_attr({'st_name':['lesson_in',], 'value':['203',], 'opt':['nero',]}, entity, upgrade=True, group_name=1, auth_mail='<EMAIL>')
    entity.put()

#param={'name':'Bskt', 'st_name':['name', 'level'], 'st_opt':['0', 'ranking'], 'st_place':[2], 'st_w':[1.0], 'st_ifbase':[True,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name','level']}]}, mescls=GroupStat, f='create_group')

def T_Normativ(self):
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='referi'))
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='General parametrs', group_creator='<EMAIL>', role='user'))	
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='user'))
    param_add_stat={'name':'Basketball', 'st_name':['normativ'], 'st_opt':['ranking'], 'st_place':[1], 'st_w':[1.0], 'st_ifbase':[False], 'role_propertys_add':[{'name':'referi', 'change':['normativ'], 'visible':[]},{'name':'admin', 'change':['normativ'], 'visible':[]},{'name':'user', 'change':[], 'visible':['normativ']} ]}	
    #T_f(self, param=param_add_stat, mescls=GroupStat, f='create_group')	
    #T_f(self, param={'creator_mail':'<EMAIL>','name':'Basketball'}, mescls=GroupStat, f='update_group')
    T_f(self, param={'group_url':BASKETBALL_GROUP_URL}, mescls=Show, f='compute_top')	
    	


def tl(self):
    line = '<EMAIL>, 22557695, <EMAIL>, 19650399, <EMAIL>, 19149119, <EMAIL>, 16943455, <EMAIL>, 16843263, <EMAIL>, 15840495, <EMAIL>, 15238975, <EMAIL>, 14938148, <EMAIL>, 14336612, me.scribe.<EMAIL>, 11930623, <EMAIL>, 11028383, <EMAIL>, 10827839, <EMAIL>, 7719716, <EMAIL>, 7018047, <EMAIL>, 7018047, <EMAIL>, 7017983, <EMAIL>, 5113183, <EMAIL>, 4411519, <EMAIL>, 4411455, <EMAIL>, 3709727, <EMAIL>, 3208415, <EMAIL>, 3208319, <EMAIL>, 1804687, <EMAIL>, 701807, <EMAIL>, 401215, <EMAIL>, 401151'
    print line.split(', ')	
    arr = line.split(', ')
    ml = ''
    for i, d in enumerate(arr):
	print '@', i, d, i%2	
	if not i%2:		
            self.put_object_to_group(PutObjectTo(child_object=d, group_name='Basketball', group_creator='<EMAIL>', role='user'))
	    ml = d
 	else:
	    print '--', ml
	    ent = ndb.Key(Base, ml).get()
	    ent.card_id = d
	    ent.put()
    	

from models import *
from random import randint


FFBSKT_URL = '<KEY>'
BASKETBALL_GROUP_URL = '<KEY>'

def start(self):
    self.Clear(Answer())
    #key = ndb.Key(Group, '<EMAIL>', Group, 'General parametrs')
    group = GroupStat(name='General parametrs', st_name=['name', 'content','rate'], st_opt=['name','0','hist'], st_ifbase=[True, True, True], role_propertys_add=[{'name':'admin', 'change':['content', 'rate', '@name'], 'visible': []}, {'name':'user' , 'change':['@content'], 'visible': ['name', 'content','rate']}])
    self.create_group(group)	
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='General parametrs', group_creator='<EMAIL>', role='admin'))
    self.add_user(User(mail='@unknown', name='unknown')) # write timer for unknown  

    group = GroupStat(name='Basketball', st_name=['name', 'rate', 'visit'], st_opt=['name','hist', 'hist'], st_ifbase=[True, True, False], role_propertys_add=[{'name':'admin', 'change':['visit', '@invite'], 'visible': ['name', 'rate']}, {'name':'user' , 'change':[], 'visible': ['name', 'rate', 'visit']}])
    self.create_group(group)	
    group = GroupStat(name='Math', st_name=['name', 'rate','lesson_plus', 'hom_work', 'hom_work'], st_opt=['name','hist', '0','nero','ranking'], st_ifbase=[True, True, False, False, False], role_propertys_add=[{'name':'admin', 'change':['lesson_plus', 'hom_work'], 'visible': ['name']}, {'name':'user' , 'change':[], 'visible': ['name','rate', 'lesson_plus', 'hom_work']}])
    self.create_group(group)	
    group = GroupStat(name='Gim', st_name=['name', 'visit', 'all_tickets'], st_opt=['name','0','0'], st_ifbase=[True, False, False], role_propertys_add=[{'name':'admin', 'change':['visit'], 'visible': ['name','all_tickets']}, {'name':'user' , 'change':[], 'visible': ['name', 'visit', 'all_tickets']}])
    self.create_group(group)
    group = GroupStat(name='Tmp', st_name=['name'], st_opt=['name'], st_ifbase=[True], role_propertys_add=[{'name':'admin', 'change':[], 'visible': []}, {'name':'user' , 'change':[], 'visible': ['name']}])
    self.create_group(group)
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='admin'))

    group = GroupStat(name='Verify', st_name=['name', 'rate', 'name_verify',  'name_verify'], st_opt=['name','hist', 'nero','ranking'], st_ifbase=[True, True, False, False], role_propertys_add=[{'name':'admin', 'change':[], 'visible': ['name']}, {'name':'user' , 'change':['name_verify'], 'visible': ['name','rate']}])
    self.create_group(group)
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Verify', group_creator='<EMAIL>', role='admin'))
    
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='admin'))
	#group = GroupStat(name='Tornament', st_name=['name', 'avatar', 'content', 'rate'], st_opt=['0','0','photo','points'], st_ifbase=[True, True, True, True], role_propertys_add=[{'name':'referi', 'change':['points'], 'visible': ['name', 'avatar']}, {'name':'team' , 'change':[], 'visible': ['name', 'visit', 'all_tickets']}])
	    #self.create_group(group)			
	#st_name - add all teams score, and points 

#------------------------------------------------------TESTS__________________________________________------
def T_f(self, param={'mail':'<EMAIL>'}, mescls=User, f='add_user'):
    print '$$ T_f ', f
    u = mescls(**param)
    T={}		
    getattr(self, f)(u)
    

def T_rating_test(self):
    param={'name':'RT La', 'st_name':['name', 'avatar', '1km', '400m', 'jump'], 'st_opt':['0', 'photo', 'ranking','ranking','ranking'], 'st_place':[1,1,2], 'st_w':[2.0,3.0,4.0], 'st_ifbase':[True,True,False,False,False], 'role_propertys_add':[{'name':'admin', 'change':['1km', '400m', 'jump','@invite'] , 'visible': ['name']}, {'name':'@open', 'change':[],'visible': ['name','1km', '400m', 'jump']}]}	
    T_f(self, param=param, mescls=GroupStat, f='create_group')
    print "TEST______________"	
    T_f(self,  param={'child_object':'<EMAIL>', 'group_name':'RT La', 'group_creator':'<EMAIL>', 'role':'admin'}, mescls=PutObjectTo, f='put_object_to_group')
    T_f(self, param={'child_object':'<EMAIL>', 'group_name':'RT La', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')
    #Need group url in st_block and obj url	
    T_f(self, param={'url':'<KEY>', 'stat_block':[{'group_url':'<KEY>', 'return_ch':[0], 'st_name':['1km'], 'st_def':['456'], 'st_opt':['ranking']},  ]}, mescls=User, f='edit_user')
    
    T_f(self, param={'group_url':'<KEY>'}, mescls=Show, f='compute_rate')
    group_url = ndb.Key(Group, '<EMAIL>', Group, 'RT La').urlsafe()			
    for user in ['a@','b@','c@','d@']:
	T_f(self, param={'child_object':user, 'group_name':'RT La', 'group_creator':'<EMAIL>', 'role':'admin'}, mescls=PutObjectTo, f='put_object_to_group')
    #param={'url':ndb.Key(Base, user).urlsafe(), 'stat_block':[{'group_url':group_url, 'return_ch':[0,1,2], 'st_name':['1km', '400m', 'jump'], 'st_def':[str(randint(240, 340)/60.0), str(randint(45, 80)), str(randint(140, 240))], 'st_opt':['ranking', 'ranking', 'ranking']},  ]}
    for res in range(3):
	add_stat(['a@','b@','c@','d@', '<EMAIL>'], 'RT La', param, self, )
	T_f(self, param={'group_url':ndb.Key(Group, '<EMAIL>', Group, 'RT La').urlsafe()}, mescls=Show, f='compute_rate')
	

def add_stat(users, group, param, self, athors=[], group_creator='<EMAIL>'):
    urls = []	
    group_url = ndb.Key(Group, group_creator, Group, group).urlsafe()	
    if athors == []:
	for user in users:
	    urls.append(ndb.Key(Base, user).urlsafe())
    else:
	for user, auth in zip(users, athors):
	    urls.append(ndb.Key(Group, auth, Group, user).urlsafe())
     		 	
    for url in urls:	
	print "-__________", urls, group, group_url, ndb.Key(ObjectToGroup, group_url, ObjectToGroup, url).get()
	#user_url = ndb.Key(ObjectToGroup, group_url, ObjectToGroup, url).urlsafe()
	user_param={'url':url, 'stat_block':[{'group_url':group_url, 'return_ch':[], 'st_name':[], 'st_def':[], 'st_opt':[]}]}
	j=0
	for i, par in enumerate(param['st_opt']):
	    if par == 'ranking':
		user_param['stat_block'][0]['st_def'].append(str(randint(0, 40)))
		user_param['stat_block'][0]['return_ch'].append(j)
		user_param['stat_block'][0]['st_name'].append(param['st_name'][i])
		user_param['stat_block'][0]['st_opt'].append('ranking')
		j+=1 
	T_f(self, param=user_param, mescls=User, f='edit_user')
	print "ADD STAT", user_param
 	


#-----------------------Group Structure Test---------------------------------------------------------
def put_to(child, gr_name, ch_aut='<EMAIL>', gr_aut='<EMAIL>', role='group'):
    param={'child_object':child, 'child_gr_author':ch_aut, 'group_name':gr_name, 'group_creator':gr_aut, 'role':role} 
    return {'param':param, 'mescls':PutObjectTo, 'f':'put_object_to_group'}	  
    #T_f(self, , param=param, mescls=PutObjectTo, f='put_object_to_group')	
    
def T_group_structure(self, ):
    T_f(self, param={'name':'Sport', 'st_name':['name', 'popularity', 'activity'], 'st_opt':['name', 'ranking','ranking'], 'st_place':[2,2], 'st_w':[1.0,2.0], 'st_ifbase':[True,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name','popularity', 'activity']}]}, mescls=GroupStat, f='create_group')
    # Add weight like for level	
    T_f(self,  param={'name':'Bskt', 'st_name':['name', 'level'], 'st_opt':['0', 'ranking'], 'st_place':[2], 'st_w':[1.0], 'st_ifbase':[True,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name','level']}]}, mescls=GroupStat, f='create_group')
    T_f(self,  param={'name':'Normatives', 'st_name':['name', '1km', '400m', 'jump'], 'st_opt':['name', 'ranking', 'ranking', 'ranking'], 'st_place':[1,1,2], 'st_w':[2.0,3.0,4.0], 'st_ifbase':[True,False,False,False], 'role_propertys_add':[{'name':'participant', 'change':[],'visible': ['name','1km', '400m', 'jump']}, {'name':'@open', 'change':[],'visible': ['name','1km', '400m', 'jump']}]}, mescls=GroupStat, f='create_group')	
    T_f(self,  param={'name':'Referi', 'st_name':['name', 'games', 'mark', 'mark'], 'st_opt':['name', 'ranking', 'ranking', 'nero'], 'st_place':[2,2], 'st_w':[1.0, 2.0], 'st_ifbase':[True,False,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name', 'games', 'mark']}]}, mescls=GroupStat, f='create_group')	
    T_f(self,  param={'name':'BsktNormatives', 'st_name':['name', 'freethrow', '3points', '8flors'], 'st_opt':['name', 'ranking','ranking','ranking'], 'st_place':[2,2,1], 'st_w':[1.0,1.3,1.4], 'st_ifbase':[True,False,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name', 'freethrow', '3points', '8flors']}]}, mescls=GroupStat, f='create_group')
    T_f(self,  param={'name':'Tornament', 'st_name':['name', 'games', 'vin'], 'st_opt':['name', '0', 'ranking'], 'st_place':[2], 'st_w':[1.0], 'st_ifbase':[True,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name', 'games', 'vin']}]}, mescls=GroupStat, f='create_group')

    param={'name':'Team2', 'st_name':['name', 'games', 'points', 'role', 'cr'], 'st_opt':['name', '0', 'ranking', '0','0'], 'st_place':[2], 'st_w':[1.0], 'st_ifbase':[True,False,False,False,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name', 'games', 'points', 'role']}, {'name':'player', 'change':[],'visible': ['name', 'games', 'points', 'role']}, {'name':'crowd','change':[],'visible': ['name', 'cr', 'points']}]}
    for team in ['Team1', 'Team2', 'Team3']:
	param['name'] = team	
        T_f(self, param=param, mescls=GroupStat, f='create_group')
    #T_f(self,  param=param, mescls=GroupStat, f='create_group')
    #T_f(self,  param=param, mescls=GroupStat, f='create_group')

    #put groups
    T_f(self,  **put_to(child='Normatives', gr_name='Sport'))
    T_f(self,  **put_to(child='Referi', gr_name='Normatives'))	
    T_f(self,  **put_to(child='Bskt', gr_name='Sport'))
    T_f(self,  **put_to(child='Referi', gr_name='Bskt'))
    T_f(self, **put_to(child='BsktNormatives', gr_name='Bskt'))
    T_f(self, **put_to(child='Tornament', gr_name='Bskt'))
    T_f(self, **put_to(child='Team1', gr_name='Tornament'))
    T_f(self,  **put_to(child='Team2', gr_name='Tornament'))
    T_f(self,  **put_to(child='Team3', gr_name='Tornament'))		
    
    #put users
    T_f(self,  param={'child_object':'<EMAIL>', 'group_name':'General parametrs', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')	
    T_f(self,  param={'child_object':'<EMAIL>', 'group_name':'Tornament', 'group_creator':'<EMAIL>', 'role':'__creator'}, mescls=PutObjectTo, f='put_object_to_group')			
    for user in ['cr1@','cr2@','cr3@','cr4@','cr5@','bpl1@','bpl2@','bpl3@','bpl4@','bpl5@',
		'bpl6@','bpl7@','bpl8@','bpl9@','bpl10@','la1@','la2@','la3@']:
	T_f(self,  param={'child_object':user, 'group_name':'General parametrs', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')
    #for user in ['bpl1@','bpl2@','bpl3@']:
	#T_f(self,  param={'child_object':user, 'group_name':'Team3', 'group_creator':'<EMAIL>', 'role':'player'}, mescls=PutObjectTo, f='put_object_to_group')
    for user in ['bpl4@','bpl5@','bpl6@']:
	T_f(self,  param={'child_object':user, 'group_name':'Team1', 'group_creator':'<EMAIL>', 'role':'player'}, mescls=PutObjectTo, f='put_object_to_group')
    for user in ['cr1@','cr2@','cr3@','<EMAIL>']:
	T_f(self,  param={'child_object':user, 'group_name':'Team1', 'group_creator':'<EMAIL>', 'role':'crowd'}, mescls=PutObjectTo, f='put_object_to_group')		
    for user in ['bpl7@','bpl8@','bpl9@']:
	T_f(self,  param={'child_object':user, 'group_name':'Team2', 'group_creator':'<EMAIL>', 'role':'player'}, mescls=PutObjectTo, f='put_object_to_group')			
    for user in ['bpl1@','la1@','la2@','la3@']:
	T_f(self,  param={'child_object':user, 'group_name':'Normatives', 'group_creator':'<EMAIL>', 'role':'participant'}, mescls=PutObjectTo, f='put_object_to_group')
    #T_f(self,  param={'child_object':'<EMAIL>', 'group_name':'RT La', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')	
    add_stat(['bpl7@','bpl8@','bpl9@'], 'Team2', param, self)


#___________________________________________________________________________________________________	

def T_high_perfomance(self):
    #print '111', 'qwertyuiopasdfghjklzxcvbnm'
	 
    #T_f(self,  param={'user_url':FFBSKT_URL, 'is_add': True, 'group':BASKETBALL_GROUP_URL, 'role':'__id'}, mescls=EditRole, f='edit_role')	
    for i in 'qwertyuiopas':
	for j in 'qwertyuiopasdfghjklz':
	    #print i+j+k+'@'
	    pass
	    #T_f(self, param={'child_object':i+j+'@', 'group_name':'General parametrs', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')
	    #T_f(self,  param={'child_object':i+j+'@', 'group_name':'Basketball', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group')
	    url = ndb.Key(Base, i+j+'@').urlsafe()	
	    #T_f(self,  param={'child_object':url, 'attribute_name': 'name', 'value':i+j}, mescls=EditEntityAttr, f='edit_entity_value')	
    cid = 34		
    for i in 'qwertyuiopas':
	for j in 'qwertyuiopasdfghjklz':	
	    T_f(self,  param={'card_id':str(cid), 'child_object':i+j+'@', 'group_url':BASKETBALL_GROUP_URL, 'stat_pls':'visit'}, mescls=CardId, f='use_card')
	    cid += 1	


def T_show(self, name1, name2, p=None):
    if not p:
        p=name2
    #print '--T Show', repr(name1)	
    #print len(ndb.Key(Base, name1).get().a_f)
    print 'group = ', ndb.Key(Group, name2).get()
    print ndb.Key(ObjectToGroup, name1, ObjectToGroup, p).get()
    print '\no b j ', (ObjectToGroup.query(ObjectToGroup.name==name1, ObjectToGroup.group_name==name2).fetch())
#(ObjectToGroup.query(ObjectToGroup.name==name1).filter(ObjectToGroup.group_name==name2).fetch())
def T_remove_all(self, message):
    s = 1000 
    entr = Base.query().fetch()
    list_of_keys = ndb.put_multi(entr)	
    #for i in entr:
    #    memcache.delete(i.mail, s)
    ndb.delete_multi(list_of_keys)
    entr = ObjectToGroup.query().fetch()
    list_of_keys = ndb.put_multi(entr)	
    #for i in entr:
    #    memcache.delete(i.key, s)
    ndb.delete_multi(list_of_keys)
    entr = Group.query().fetch()
    list_of_keys = ndb.put_multi(entr)	
    ndb.delete_multi(list_of_keys) 
    entr = NeroStat.query().fetch()
    list_of_keys = ndb.put_multi(entr)	
    ndb.delete_multi(list_of_keys) 	  
    #for i in entr:
    #    memcache.delete(i.key, s)
    

def T_in_out_group(self, message):
    gp=GroupStat(name='Tparent', st_name=['lesson_remain', 'lesson_value'], role_propertys_add=[{'name':'admin' , 'change':['lesson_value','@invite', 'lesson_remain'] , 'visible': ['name']},{'name':'user' , 'change':['@name','@content'] , 'visible': ['lesson_remain', 'lesson_value']}])
    self.create_group(gp)
    ga=GroupStat(name='TchildA', parent_group='Tparent', st_name=['lesson_remain', 'lesson_value'], role_propertys_add=[{'name':'admin' , 'change':['lesson_value','@invite', 'lesson_remain'] , 'visible': ['name']},{'name':'user' , 'change':['@name','@content'] , 'visible': ['lesson_remain', 'lesson_value']}])
    self.create_group(ga)
    gb=GroupStat(name='TchildB', parent_group='Tparent', st_name=['lesson_remain', 'lesson_value'], role_propertys_add=[{'name':'admin' , 'change':['@invite'] , 'visible': ['name']},{'name':'user' , 'change':['@name','@content', 'lesson_value', 'lesson_remain'] , 'visible': ['lesson_remain', 'lesson_value']}])
    self.create_group(gb)
    gc=GroupStat(name='TchildC', parent_group='Tparent', st_name=[], role_propertys_add=[{'name':'ara' , 'change':['content'] , 'visible': ['name']}])
    self.create_group(gc)
    
    test_ask_put(self, gname='Tparent', observer='test_a_u@')
    #print
    
    test_ask_put(self, gname='TchildA',observer='test_a_u@', invite=True)
    #time.sleep(3)
    test_ask_put(self, gname='TchildB',observer='test_a_u@') 	
    #time.sleep(3)
    test_ask_put(self, gname='TchildC',observer='test_a_u@')
    test_ask_put(self, gname='TchildA',observer='test_a_u@', invite=True)


def card_test_prepare(self, message):
    ga=GroupStat(name='A', st_name=['u_f', 'a_f', 'lesson_in'], role_propertys_add=[{'name':'admin' , 'change':['a_f','@invite'] , 'visible': ['u_f', 'a_f']}])
    self.create_group(ga)
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='A', role='admin'))
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='A', role='user'))
    print "++create group + 2 users nomad & ff"
    #gupd = GroupStat(name='A', st_name=['card'], st_opt=['+@u_f'], role_propertys_add=[{'name':'admin', 'change':['card'], 'visible': []}])
    #self.update_group(gupd)
    self.use_card(CardId(card_id='123', child_object='<EMAIL>', stat_pls='u_f'))
    self.use_card(CardId(card_id='123', stat_pls='u_f'))

def T_fill_attr(self):
    self.start(Answer())
    ga=GroupStat(name='A', st_name=['name', 'name', 'lesson_in', 'lesson_in', 'jump'], st_opt=['0','like','nero',"ranking","ranking"], st_ifbase=[True, True, False,False,False], st_place=[0], role_propertys_add=[{'name':'admin' , 'change':['name', 'lesson_in', 'jump', '@invite'], 'visible': []}, {'name':'user' , 'change':['lesson_in','jump'] , 'visible': []}])
    self.create_group(ga)
    self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='A', group_creator='<EMAIL>', role='admin'))	
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='A', group_creator='<EMAIL>', role='user'))
    #self.put_object_to_group(PutObjectTo(child_object='1@', group_name='A', role='user', kind='user'))
    print "TEST CREATE GROUP COPY TMP"
    gb=CopyGroup(old_name='A', old_author='<EMAIL>', new_name='b')
    self.copy_template(gb)
    print "TEST PUT USER AND GROUP"	
    #self.put_object_to_group(PutObjectTo(child_object='b', group_name='A', kind='group'))
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='b', role='admin', kind='user'))	
    #-self.create_group(gb)	
    #-self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='B', role='admin', kind='user'))
    gp=GroupStat(name='U', st_name=['hw', 'lesson_in2', 'name'], st_opt=['photo',"nero",'0'], st_ifbase=[False,False,True], role_propertys_add=[{'name':'admin' , 'change':[], 'visible': []}])
    self.create_group(gp)	
    self.put_object_to_group(PutObjectTo(child_object='U', child_gr_author='<EMAIL>', group_name='A', group_creator='<EMAIL>'))	
    T_show_user(self, Answer(), u='ahFkZXZ-dW5pdmVyc2l0eWdpbXIaCxIEQmFzZSIQZmZic2t0QGdtYWlsLmNvbQw', s='<EMAIL>')


def T_Nero(self):
    print '--T Edit Nero stat'
    u1 = User(mail='<EMAIL>', return_ch=[0,], st_def=['23',], st_name=['lesson_in',], st_opt=['nero',])
    self.edit_user(u1)
    u1.mail = '1@'
    self.edit_user(u1)
    entity = ndb.Key(Base, '1@').get()
    self.fill_attr({'st_name':['lesson_in',], 'value':['203',], 'opt':['nero',]}, entity, upgrade=True, group_name=1, auth_mail='<EMAIL>')
    entity.put()

#param={'name':'Bskt', 'st_name':['name', 'level'], 'st_opt':['0', 'ranking'], 'st_place':[2], 'st_w':[1.0], 'st_ifbase':[True,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name','level']}]}, mescls=GroupStat, f='create_group')

def T_Normativ(self):
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='referi'))
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='General parametrs', group_creator='<EMAIL>', role='user'))	
    #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='user'))
    param_add_stat={'name':'Basketball', 'st_name':['normativ'], 'st_opt':['ranking'], 'st_place':[1], 'st_w':[1.0], 'st_ifbase':[False], 'role_propertys_add':[{'name':'referi', 'change':['normativ'], 'visible':[]},{'name':'admin', 'change':['normativ'], 'visible':[]},{'name':'user', 'change':[], 'visible':['normativ']} ]}	
    #T_f(self, param=param_add_stat, mescls=GroupStat, f='create_group')	
    #T_f(self, param={'creator_mail':'<EMAIL>','name':'Basketball'}, mescls=GroupStat, f='update_group')
    T_f(self, param={'group_url':BASKETBALL_GROUP_URL}, mescls=Show, f='compute_top')	
    	


def tl(self):
    line = '<EMAIL>, 22557695, <EMAIL>, 19650399, <EMAIL>, 19149119, <EMAIL>, 16943455, <EMAIL>, 16843263, <EMAIL>, 15840495, <EMAIL>, 15238975, <EMAIL>, 14938148, <EMAIL>, 14336612, me.scribe.<EMAIL>, 11930623, <EMAIL>, 11028383, <EMAIL>, 10827839, <EMAIL>, 7719716, <EMAIL>, 7018047, <EMAIL>, 7018047, <EMAIL>, 7017983, <EMAIL>, 5113183, <EMAIL>, 4411519, <EMAIL>, 4411455, <EMAIL>, 3709727, <EMAIL>, 3208415, <EMAIL>, 3208319, <EMAIL>, 1804687, <EMAIL>, 701807, <EMAIL>, 401215, <EMAIL>, 401151'
    print line.split(', ')	
    arr = line.split(', ')
    ml = ''
    for i, d in enumerate(arr):
	print '@', i, d, i%2	
	if not i%2:		
            self.put_object_to_group(PutObjectTo(child_object=d, group_name='Basketball', group_creator='<EMAIL>', role='user'))
	    ml = d
 	else:
	    print '--', ml
	    ent = ndb.Key(Base, ml).get()
	    ent.card_id = d
	    ent.put()
#key = ndb.Key(Group, '<EMAIL>', Group, 'General parametrs') # write timer for unknown #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='admin')) #group = GroupStat(name='Tornament', st_name=['name', 'avatar', 'content', 'rate'], st_opt=['0','0','photo','points'], st_ifbase=[True, True, True, True], role_propertys_add=[{'name':'referi', 'change':['points'], 'visible': ['name', 'avatar']}, {'name':'team' , 'change':[], 'visible': ['name', 'visit', 'all_tickets']}]) #self.create_group(group) #st_name - add all teams score, and points #------------------------------------------------------TESTS__________________________________________------ #Need group url in st_block and obj url #param={'url':ndb.Key(Base, user).urlsafe(), 'stat_block':[{'group_url':group_url, 'return_ch':[0,1,2], 'st_name':['1km', '400m', 'jump'], 'st_def':[str(randint(240, 340)/60.0), str(randint(45, 80)), str(randint(140, 240))], 'st_opt':['ranking', 'ranking', 'ranking']},  ]} #user_url = ndb.Key(ObjectToGroup, group_url, ObjectToGroup, url).urlsafe() #-----------------------Group Structure Test--------------------------------------------------------- #T_f(self, , param=param, mescls=PutObjectTo, f='put_object_to_group') # Add weight like for level #T_f(self,  param=param, mescls=GroupStat, f='create_group') #T_f(self,  param=param, mescls=GroupStat, f='create_group') #put groups #put users #for user in ['bpl1@','bpl2@','bpl3@']: #T_f(self,  param={'child_object':user, 'group_name':'Team3', 'group_creator':'<EMAIL>', 'role':'player'}, mescls=PutObjectTo, f='put_object_to_group') #T_f(self,  param={'child_object':'<EMAIL>', 'group_name':'RT La', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group') #___________________________________________________________________________________________________ #print '111', 'qwertyuiopasdfghjklzxcvbnm' #T_f(self,  param={'user_url':FFBSKT_URL, 'is_add': True, 'group':BASKETBALL_GROUP_URL, 'role':'__id'}, mescls=EditRole, f='edit_role') #print i+j+k+'@' #T_f(self, param={'child_object':i+j+'@', 'group_name':'General parametrs', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group') #T_f(self,  param={'child_object':i+j+'@', 'group_name':'Basketball', 'group_creator':'<EMAIL>', 'role':'user'}, mescls=PutObjectTo, f='put_object_to_group') #T_f(self,  param={'child_object':url, 'attribute_name': 'name', 'value':i+j}, mescls=EditEntityAttr, f='edit_entity_value') #print '--T Show', repr(name1) #print len(ndb.Key(Base, name1).get().a_f) #(ObjectToGroup.query(ObjectToGroup.name==name1).filter(ObjectToGroup.group_name==name2).fetch()) #for i in entr: #    memcache.delete(i.mail, s) #for i in entr: #    memcache.delete(i.key, s) #for i in entr: #    memcache.delete(i.key, s) #print #time.sleep(3) #time.sleep(3) #gupd = GroupStat(name='A', st_name=['card'], st_opt=['+@u_f'], role_propertys_add=[{'name':'admin', 'change':['card'], 'visible': []}]) #self.update_group(gupd) #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='A', group_creator='<EMAIL>', role='user')) #self.put_object_to_group(PutObjectTo(child_object='1@', group_name='A', role='user', kind='user')) #self.put_object_to_group(PutObjectTo(child_object='b', group_name='A', kind='group')) #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='b', role='admin', kind='user')) #-self.create_group(gb) #-self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='B', role='admin', kind='user')) #param={'name':'Bskt', 'st_name':['name', 'level'], 'st_opt':['0', 'ranking'], 'st_place':[2], 'st_w':[1.0], 'st_ifbase':[True,False], 'role_propertys_add':[{'name':'@open', 'change':[],'visible': ['name','level']}]}, mescls=GroupStat, f='create_group') #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='referi')) #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='General parametrs', group_creator='<EMAIL>', role='user')) #self.put_object_to_group(PutObjectTo(child_object='<EMAIL>', group_name='Basketball', group_creator='<EMAIL>', role='user')) #T_f(self, param=param_add_stat, mescls=GroupStat, f='create_group') #T_f(self, param={'creator_mail':'<EMAIL>','name':'Basketball'}, mescls=GroupStat, f='update_group')