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()