def pytest_configure(config): # check for skipping setup on xdist master process if not config.pluginmanager.getplugin("dsession"): suffix = str(uuid.uuid4().int) env, db = dr_usertool_setup() # User credentials user_username = "******".format( suffix) user_api_token = "lkjkljnm988989jkr5645tv_{}".format(suffix) user_permissions = get_permissions( "tests/fixtures/user_permissions.json", user_api_token) # Add user DataRobotUserDatabase.add_user( db, env, user_username, invite_code="autogen", app_user_manager=False, permissions=user_permissions, api_token=user_api_token, activated=True, unix_user="******", ) os.environ["DATAROBOT_API_TOKEN"] = user_api_token os.environ["DATAROBOT_ENDPOINT"] = ENDPOINT_URL config.user_username = user_username
def print_user_info(): # username, _ = generate_user() username = '******' env, db = dr_usertool_setup() user = DataRobotUserDatabase.get_user(db, username) check = DataRobotUserDatabase.check_user(db, env, username) print('USER') for k, v in user.items(): print('{}: {!r}'.format(k, v)) print('CHECK') for k, v in check.items(): print('{}: {!r}'.format(k, v))
def set_permisisons(): permissions = { "EXPERIMENTAL_API_ACCESS": True, "ENABLE_DOWNLOAD_DATASET": True, "ENABLE_DATA_MANAGEMENT": True, "ENABLE_CREATE_SNAPSHOT_DATASOURCE": True, 'DATAROBOT_PRIME': True, 'PREDICTIONS_ADMIN': True, 'ADMIN_API_ACCESS': True, 'CAN_MANAGE_OWN_PERMISSIONS': True } env, db = dr_usertool_setup() username, _ = generate_user() # username = '******' DataRobotUserDatabase.set_permissions(db, username, permissions)
def setup(): env, db = dr_usertool_setup() user_username, user_api_token = generate_user() user_permissions = get_permissions('_user_permissions', user_api_token) # # Add user DataRobotUserDatabase.add_user( db, env, user_username, invite_code='autogen', app_user_manager=False, permissions=user_permissions, api_token=user_api_token, activated=True, unix_user='******' ) DataRobotUserDatabase.add_organization(db, user_username, 2) DataRobotUserDatabase.add_user_to_organization(db, user_username, user_username) user = DataRobotUserDatabase.get_user(db, user_username) print(user) create_prediction_instance_for_user(user) print('export DATAROBOT_API_TOKEN={}'.format(user_api_token))
def dr_usertool_setup(): mongo_host = get_mongo_host() return DataRobotUserDatabase.setup('adhoc', '', mongo_host=mongo_host)
def reset_password(password): # username, api_token = generate_user() username = '******' env, db = dr_usertool_setup() DataRobotUserDatabase.add_user(db, env, username, 'autogen',reset_password=True, password=password)
def pytest_unconfigure(config): if not config.pluginmanager.getplugin("dsession"): warnings.simplefilter("ignore") _, db = dr_usertool_setup() DataRobotUserDatabase.delete_user(db, config.user_username) warnings.simplefilter("error")
def dr_usertool_setup(): mongo_host = os.environ.get("MONGO_HOST", os.environ.get("HOST", "127.0.0.1")).strip() return DataRobotUserDatabase.setup("adhoc", "", mongo_host=mongo_host)