#NEWLINE# def create_role_test_data( orgs , branches ) : #NEWLINE# #INDENT# from lxml import etree #NEWLINE# import StringIO #NEWLINE# db = current . db #NEWLINE# s3db = current . s3db #NEWLINE# auth = current . auth #NEWLINE# request = current . request #NEWLINE# auth . override = True #NEWLINE# s3db . load_all_models ( ) #NEWLINE# test_dir = os . path . join ( current . request . folder , 'modules' , 'tests' , 'roles' , current . deployment_settings . base . template ) #NEWLINE# org_file = open ( os . path . join ( test_dir , 'org_organisation.xml' ) , 'rb' ) #NEWLINE# org_template_string = org_file . read ( ) #NEWLINE# data_file = open ( os . path . join ( test_dir , 'data.xml' ) , 'rb' ) #NEWLINE# data_template_string = data_file . read ( ) #NEWLINE# org_resource = s3db . resource ( 'org_organisation' ) #NEWLINE# org_branch_file = open ( os . path . join ( test_dir , 'org_organisation_branch.xml' ) , 'rb' ) #NEWLINE# org_branch_template_string = org_branch_file . read ( ) #NEWLINE# org_branch_resource = s3db . resource ( 'org_organisation_branch' ) #NEWLINE# user_file = open ( os . path . join ( test_dir , 'users_template.csv' ) , 'rb' ) #NEWLINE# user_template_string = user_file . read ( ) #NEWLINE# s3db . configure ( 'auth_user' , onaccept = ( lambda form : auth . s3_link_user ( form . vars ) ) ) #NEWLINE# s3db . add_components ( 'auth_user' , auth_membership = 'user_id' ) #NEWLINE# current . response . s3 . import_prep = auth . s3_import_prep #NEWLINE# user_resource = s3db . resource ( 'auth_user' ) #NEWLINE# hr_resource = s3db . resource ( 'pr_person' ) #NEWLINE# user_file = StringIO . StringIO ( ) #NEWLINE# user_stylesheet = os . path . join ( current . request . folder , 'static' , 'formats' , 's3csv' , 'auth' , 'user.xsl' ) #NEWLINE# hr_stylesheet = os . path . join ( current . request . folder , 'static' , 'formats' , 's3csv' , 'hrm' , 'person.xsl' ) #NEWLINE# for org in orgs : #NEWLINE# #INDENT# for branch in branches : #NEWLINE# #INDENT# copy_orgs = list ( orgs ) #NEWLINE# copy_orgs . remove ( org ) #NEWLINE# orgx1 = copy_orgs [ 0 ] #NEWLINE# orgx2 = copy_orgs [ 1 ] #NEWLINE# if branch : #NEWLINE# #INDENT# orgx = ( '%s-%s' % ( org , branch ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# orgx = org #NEWLINE# #UNINDENT# org_string = ( org_template_string % dict ( org = orgx ) ) #NEWLINE# xmltree = etree . ElementTree ( etree . fromstring ( org_string ) ) #NEWLINE# success = org_resource . import_xml ( xmltree ) #NEWLINE# otable = s3db . org_organisation #NEWLINE# org_id = db ( ( otable . name == orgx ) ) . select ( otable . id ) . first ( ) . id #NEWLINE# auth . user = Storage ( organisation_id = org_id ) #NEWLINE# data_string = ( data_template_string % dict ( org = orgx , orgx1 = orgx1 , orgx2 = org_template_string ) ) #NEWLINE# xmltree = etree . ElementTree ( etree . fromstring ( data_string ) ) #NEWLINE# success = org_resource . import_xml ( xmltree ) #NEWLINE# user_string = ( user_template_string % dict ( org = orgx , org_lower = orgx . lower ( ) ) ) #NEWLINE# user_file = StringIO . StringIO ( user_string ) #NEWLINE# success = user_resource . import_xml ( user_file , format = 'csv' , stylesheet = user_stylesheet ) #NEWLINE# user_file = StringIO . StringIO ( user_string ) #NEWLINE# hr_resource . import_xml ( user_file , format = 'csv' , stylesheet = hr_stylesheet ) #NEWLINE# if branch : #NEWLINE# #INDENT# org_branch_string = ( org_branch_template_string % dict ( org = org , branch = branch ) ) #NEWLINE# xmltree = etree . ElementTree ( etree . fromstring ( org_branch_string ) ) #NEWLINE# success = org_branch_resource . import_xml ( xmltree ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# test_user_file = open ( os . path . join ( test_dir , 'test_users.csv' ) , 'rb' ) #NEWLINE# success = user_resource . import_xml ( test_user_file , format = 'csv' , stylesheet = user_stylesheet ) #NEWLINE# test_user_file = open ( os . path . join ( test_dir , 'test_users.csv' ) , 'rb' ) #NEWLINE# hr_resource . import_xml ( test_user_file , format = 'csv' , stylesheet = hr_stylesheet ) #NEWLINE# db . commit ( ) #NEWLINE# auth . override = False