def add_real_data(db): for group in ['admin', 'staff', 'users']: if not db.usergroup_db.has_key(group): ug = UserGroup(group) db.usergroup_db.add_usergroup(ug) group_admin = db.usergroup_db['admin'] group_staff = db.usergroup_db['staff'] group_users = db.usergroup_db['users'] for (user_id, group_id, name, email) in [ ('admin', 'admin', "Administrative User", "*****@*****.**"), ('jimc', 'users', "Jim Carroll", "*****@*****.**"), ]: if not db.user_db.has_key(user_id): user = User(user_id) user.set_password(user_id) user.contact_name = name user.add_email(email) user.add_to_group(db.usergroup_db[group_id]) db.user_db.add_user(user) admin = db.user_db['admin'] admin.add_to_group(group_staff) admin.add_to_group(group_users) jimc = db.user_db['jimc'] jimc.add_to_group(group_staff) # set database owners db.user_db.set_owner(admin) db.user_db.set_owning_group(group_admin) db.user_db.set_group_perms(['read']) db.user_db.set_other_perms(['read']) db.usergroup_db.set_owner(admin) db.usergroup_db.set_owning_group(group_admin) db.usergroup_db.set_group_perms(['read']) db.usergroup_db.set_other_perms(['read']) db.group_db.set_owner(admin) db.group_db.set_owning_group(group_admin) db.group_db.add_owning_group([group_staff, group_users]) db.group_db.set_group_perms(['read','write']) db.group_db.set_other_perms(['read']) # create initial groups import qon.group_db qon.group_db.create_initial_groups()
def create_test_users(db, how_many, print_progress=False, sequential=False): """ Create a bunch of test users with userid tu______ and add them to the database howmany = how many users to attempt to create sequential = True to number the userids in sequence; otherwise, random userids are used """ # don't bother doing it if we already have enough users # if len(db.user_db) >= how_many: # return progress_interval = calculate_progress_interval(how_many) for x in range(1, how_many+1): if print_progress and (x % progress_interval == 0): print "Creating user %s of %s" % (x, how_many) if sequential: userid = "tu%s" % x if db.user_db.has_key(userid): continue else: user = User("tu%s" % x) else: user = User() while db.user_db.has_key(user.get_user_id()): user.generate_user_id("tu") user.set_password("password") user.contact_name = "%s Smith" % user.get_user_id() user.add_email("*****@*****.**" % user.get_user_id()) # add user to the 'users' UserGroup user.add_to_group(db.usergroup_db['users']) # add user to the database db.user_db.add_user(user) get_transaction().commit()