def __init__(self, api_key): configuration = jcapiv2.Configuration() configuration.api_key['x-api-key'] = api_key self.graph_api = jcapiv2.GraphApi(jcapiv2.ApiClient(configuration)) self.groups_api = jcapiv2.GroupsApi(jcapiv2.ApiClient(configuration)) self.user_groups_api = jcapiv2.UserGroupsApi( jcapiv2.ApiClient(configuration)) self.system_groups_api = jcapiv2.SystemGroupsApi( jcapiv2.ApiClient(configuration)) self.bulk_job_requests_api = jcapiv2.BulkJobRequestsApi( jcapiv2.ApiClient(configuration))
def setup_class(cls): '''Check that there are no existing users, and no groups named 'fake-group-123' in JC test account ''' apiv1_configuration = jcapiv1.Configuration() apiv1_configuration.api_key['x-api-key'] = API_KEY systemusers_api = SystemusersApi( jcapiv1.ApiClient(configuration=apiv1_configuration)) current_users = systemusers_api.systemusers_list( content_type='application/json', accept='application/json') assert current_users.total_count == 0 apiv2_configuration = jcapiv2.Configuration() apiv2_configuration.api_key['x-api-key'] = API_KEY user_groups_api = UserGroupsApi( jcapiv2.ApiClient(configuration=apiv2_configuration)) current_groups = user_groups_api.groups_user_list( content_type='application/json', accept='application/json') assert not any(group.name == GROUP_NAME for group in current_groups)
return f.read().strip() except FileNotFoundError: print("'%s' file not found" % filename) api_key = get_file_contents(secrets) CONTENT_TYPE = "application/json" ACCEPT = "application/json" # APIv1 configuration configuration = jcapiv1.Configuration() configuration.api_key['x-api-key'] = api_key # APIv2 CONFIGURATION CONFIGURATION = jcapiv2.Configuration() CONFIGURATION.api_key['x-api-key'] = api_key API_INSTANCE = jcapiv2.UserGroupsApi(jcapiv2.ApiClient(CONFIGURATION)) def get_groups_list(): """Retrieve all user groups.""" try: i = 0 groups_list = API_INSTANCE.groups_user_list(CONTENT_TYPE, ACCEPT) group_names = [g.name for g in groups_list] group_ids = [g.id for g in groups_list] group_dict = dict(zip(group_ids, group_names)) for id in group_dict.keys(): print(id, '->', group_dict[id])