def test_create_new_user(): ac = AccessControlAPI() username = '******' password = '******' role_ids = None team_ids = [1022] authentication_provider_id = 1 first_name = 'test' last_name = 'test' email = '*****@*****.**' phone_number = None cell_phone_number = None job_title = None other = None country = None active = 'true' expiration_date = '2023-04-28' allowed_ip_list = None locale_id = 1 is_successful = ac.create_new_user(username=username, password=password, role_ids=role_ids, team_ids=team_ids, authentication_provider_id=authentication_provider_id, first_name=first_name, last_name=last_name, email=email, phone_number=phone_number, cell_phone_number=cell_phone_number, job_title=job_title, other=other, country=country, active=active, expiration_date=expiration_date, allowed_ip_list=allowed_ip_list, locale_id=locale_id) assert is_successful is True
def add_users_from_csv_file(users): """ All locale: ['en-US', 'fr-FR', 'ja-JP', 'ko-KR', 'pt-BR', 'ru-RU', 'zh-CN', 'zh-TW', 'es-ES'] Args: users: Returns: """ ac = AccessControlAPI() all_users = ac.get_all_users() all_user_name = [user.username for user in all_users] all_user_email = [user.email for user in all_users] all_locale_code = [item.code for item in ac.get_all_system_locales()] all_roles = ac.get_all_roles() all_teams = ac.get_all_teams() for index, user in enumerate(users): row_number = index + 2 username = user.get("Username") if username in all_user_name: print( "Row No.{}, Username: {} already taken, will ignore this line". format(row_number, username)) continue email = user.get("Email") if email in all_user_email: print("Row No.{}, Email: {} already taken, will ignore this line". format(row_number, email)) continue try: locale_id = all_locale_code.index(user.get("LocaleCode")) + 1 except ValueError: print("Wrong Locale Code in row No.{}, will use en-US".format( row_number)) locale_id = 1 role_ids = [] for role_name in user.get("Roles").split(";"): for item in all_roles: if item.name == role_name: role_ids.append(item.id) team_ids = [] for team_name in user.get("Teams").split(";"): for item in all_teams: if item.full_name == team_name: team_ids.append(item.id) ac.create_new_user( username=user.get("Username"), password=user.get("Password"), role_ids=role_ids, team_ids=team_ids, authentication_provider_id=1, first_name=user.get("FirstName"), last_name=user.get("LastName"), email=user.get("Email"), phone_number=user.get("Phone"), cell_phone_number=user.get("MobilePhone"), job_title=user.get("JobTitle"), other=user.get("Other"), country=user.get("Country"), active=user.get("ActiveUser").lower(), expiration_date=user.get("ExpirationDate"), allowed_ip_list=[], locale_id=locale_id, )