def test_skte_t996_move_file(self): # 上传文件用于移动 filename = config.file_name # 移动源文件名称 file = '{}{}'.format(config.file_url, filename) # 源文件及其路径 target = config.ceph_path # 文件上传的目的地址,同时也是移动文件的源地址 send_file_m_req.upload_file(self.token, file, target) # 创建文件夹作为移动目的地址 folder = 'T996 movefolder' send_file_m_req.create_folder(self.token, target, folder) # 移动文件 move_source = '{}{}'.format(config.ceph_path, config.file_name) move_sources = [] move_sources.append(move_source) # 移动的源文件及其路径列表 move_target = '{}{}'.format(target, folder) # 文件移动的目标地址 send_file_m_req.move_file(self.token, move_sources, move_target) # 校验移动结果 filename_target = send_file_m_req.get_file_list( self.token, move_target) # 移动目的地址文件名列表 if filename not in filename_target: logger.log_error( 'file/folder {} move failed, target address do not find it'. format(filename)) assert False filename_source = send_file_m_req.get_file_list(self.token, target) # 移动源地址文件名列表 if filename in filename_source: logger.log_error( 'file/folder {} move failed, source address have not moved it away' .format(filename)) assert False # 删除文件夹 path_folder = [] path_folder.append('{}{}'.format(target, folder)) send_file_m_req.delete_files_and_folders(self.token, path_folder)
def check_files_folders_exist(conn_info=config.ssh_conn_info, input_path_list=None, isExistCheck=True): """ 检查文件和文件夹是否存在 :param ssh_conn_info {ip,port,user,passwrd}: :param input_path_list(绝对路径): :param isExistCheck(绝对路径): True(存在检查)/False(不存在检查) :return: False/True """ path_list = [] if input_path_list is None else input_path_list conn = SSHConnection(conn_info['host'], conn_info['port'], conn_info['user'], conn_info['passwd']) for path_item in path_list: command_foler_check = 'ls {}' isExist = conn.exec_command( command_foler_check.format(path_item)).decode('utf-8') if isExistCheck is True: if 'No such file or directory' in isExist: logger.log_error('Folder {} is not exist'.format(path_item)) conn.close() return False elif isExistCheck is False: if 'No such file or directory' not in isExist: logger.log_error('Folder {} is not exist'.format(path_item)) conn.close() return False conn.close() return True
def fetch_user_group_uuid_by_group_name(token, group_name): """ 查询指定用户组的uuid :param token: :param group_name: :return: """ user_group_list = get_user_group_list(token) if user_group_list: for group in user_group_list: if group['name'] == group_name: return group['uuid'] logger.log_error('Can not find user role uuid for {}'.format(group_name)) return False
def test_skte_t1023_t1030_share_and_cancel_files_in_bulk(self): target = config.ceph_path # 上传路径 filename1 = 'iris.csv' # 上传文件名称 file1 = '{}{}'.format(config.file_url, filename1) # 源文件及其路径 filePath1 = '{}{}'.format(target, filename1) # 上传后文件及其路径 filename2 = 'iris.txt' file2 = '{}{}'.format(config.file_url, filename2) filePath2 = '{}{}'.format(target, filename2) paths = [] paths.append(filePath1) paths.append(filePath2) # 上传文件用于共享/取消共享操作 send_file_m_req.upload_file(self.token, file1, target) send_file_m_req.upload_file(self.token, file2, target) # 共享文件给用户 uuid = get_uuid_from_token(self.token) # 文件所有者的uuid,同时也是文件共享者的uuid shareuser_token = send_user_m_req.get_token_simple( config.user_name_b, config.user_passwd_b) # 被共享用户的token sharer_uuid = get_uuid_from_token(shareuser_token) # 被共享用户的uuid share_uuid = send_file_m_req.share_files_batch(self.token, sharePaths=paths, owner_id=uuid, share_id=uuid, users=[sharer_uuid]) # 验证文件共享结果: 1)共享用户在“我的共享”文件夹下可看到共享文件 2)被共享用户在“接收的共享”文件夹下可看到被共享文件 my_share_file = send_file_m_req.get_shared_file_list( self.token, owner_id=uuid) # 共享用户查看"我的共享"文件夹,返回其下可查看到的文件列表 if filename1 and filename2 not in my_share_file: logger.log_error( 'user {} cannot find shared file {} and {}'.format( config.user_name_a, filename1, filename2)) assert False share_file_list = send_file_m_req.get_shared_file_list( shareuser_token, user_id=sharer_uuid) # 被共享用户查看"接收的共享",返回其下可查看到的文件列表 if filename1 and filename2 not in share_file_list: logger.log_error( 'user {} cannot find shared file {} and {}'.format( config.user_name_b, filename1, filename2)) assert False # 取消共享文件 send_file_m_req.cancel_shared_file(self.token, share_uuid) # 验证文件共享结果: 1)共享用户的“我的共享”文件夹下已移除共享文件 2)被共享用户已在“接收的共享”文件夹下移除被共享文件 my_share_file = send_file_m_req.get_shared_file_list( self.token, owner_id=uuid) # 共享用户查看"我的共享"文件夹,返回其下可查看到的文件列表 if filename1 and filename2 in my_share_file: logger.log_error( 'user {} should not find unshared file {} and {}'.format( config.user_name_a, filename1, filename2)) assert False share_file_list = send_file_m_req.get_shared_file_list( shareuser_token, user_id=sharer_uuid) # 被共享用户查看"接收的共享",返回其下可查看到的文件列表 if filename1 and filename2 in share_file_list: logger.log_error( 'user {} should not find unshared file {} and {}'.format( config.user_name_b, filename1, filename2)) assert False # 删除文件 send_file_m_req.delete_files_and_folders(self.token, paths)
def fetch_user_role_uuid_by_role_name(token, role_name): """ 查询指定角色的uuid :param token: :param role_name: :return: """ user_role_list = get_user_role_list(token) if user_role_list: for role in user_role_list: if role['name'] == role_name: return role['uuid'] logger.log_error('Can not find user role uuid for {}'.format(role_name)) return False else: return False
def check_pod_status(pod_ids, expected_status='Running', timeout=30): """ 根据pod id检查pod的状态 (此方法暂时不使用) :param pod_ids: str或list :param expected_status: :param timeout: 检查的次数,每隔一秒检查一次(kubectl命令需要时间,因此总时间大于timeout*1秒),如果所有pod达到期望状态,则提前返回 :return: bool """ if not isinstance(pod_ids, (list, str)): logger.log_error('The pod_id type is wrong, expect list or string, but got {}'.format(type(pod_ids))) return False if isinstance(pod_ids, str): pod_ids = list(pod_ids) match_status_pod_list = [] host = config.ssh_conn_info['host'] port = config.ssh_conn_info['port'] user = config.ssh_conn_info['user'] passwd = config.ssh_conn_info['passwd'] conn = SSHConnection(host, port, user, passwd) command = "kubectl get pod {} -n skydiscovery-app|awk '{print $3}'|grep -v STATUS" while timeout > 0: timeout = timeout - 1 for pod_id in pod_ids: pod_status = conn.exec_command(command.format(pod_id)) if pod_status == expected_status: logger.log_debug("Pod {}'s status is {}, = {}.".format(pod_id, pod_status, expected_status)) if pod_id not in match_status_pod_list: match_status_pod_list.append(pod_id) else: logger.log_debug("Pod {}'s status is {}, != {}.".format(pod_id, pod_status, expected_status)) if pod_id in match_status_pod_list: match_status_pod_list.remove(pod_id) if len(match_status_pod_list) == len(pod_ids): logger.log_debug('The pod(s) status match to the expectation.') conn.close() return True time.sleep(1) logger.log_error('The pod(s) status do not match to the expectation.') conn.close() return False
def test_skte_t1001_copy_file(self): # 上传文件用于拷贝 filename = config.file_name # 拷贝源文件名称 file = '{}{}'.format(config.file_url, filename) # 源文件及其路径 target = config.ceph_path # 文件上传的目的地址,同时也是拷贝文件的源地址 send_file_m_req.upload_file(self.token, file, target) # 创建拷贝目的地址文件夹 folder = 'T1001 copyfolder' send_file_m_req.create_folder(self.token, target, folder) # 拷贝文件 copy_source = '{}{}'.format(config.ceph_path, config.file_name) copy_sources = [] copy_sources.append(copy_source) # 拷贝的源文件及其路径列表 copy_target = '{}{}'.format(target, folder) # 文件拷贝的目标地址 send_file_m_req.copy_file(self.token, copy_sources, copy_target) # 校验拷贝结果 filename_target = send_file_m_req.get_file_list( self.token, copy_target) # 拷贝目的地址文件名列表 if filename not in filename_target: logger.log_error( 'file/folder {} copy failed, target address do not find it'. format(filename)) assert False filename_source = send_file_m_req.get_file_list(self.token, target) # 拷贝源地址文件名列表 if filename not in filename_source: logger.log_error( 'file/folder {} copy failed, source address do not find it'. format(filename)) assert False # 删除文件和文件夹 # paths = [] # paths.append('{}{}'.format(target, config.file_name)) # paths.append('{}{}'.format(target, folder)) # send_file_m_req.delete_files_and_folders(self.token, paths) # 批量删除文件和文件夹有bug,http://jira.iluvatar.ai:8080/browse/SDXTEST-468,文件和文件夹暂时分开删除 # 删除文件 path_file = [] path_file.append('{}{}'.format(target, config.file_name)) send_file_m_req.delete_files_and_folders(self.token, path_file) # 删除文件夹 path_folder = [] path_folder.append('{}{}'.format(target, folder)) send_file_m_req.delete_files_and_folders(self.token, path_folder)
def test_get_image_info_by_name(self): # 根据image name查询image信息 req = api_image_m.get_all_image_list_req(self.token) # 设置查询的image name req.param.update({'name': config.jupyter_image_name}) res = send_req.send_request(req) if len(res['data']) == 0: logger.log_error('Got empty result.') assert False # 模糊查询结果可能为多个,逐个检查名称 for i in res['data']: if config.jupyter_image_name not in i['name']: logger.log_error( 'Found unexpected image info: {}, no relationship with image "{}"' .format(i['name'], config.jupyter_image_name)) assert False
def test_skte_t1014_t1029_share_and_cancel_file(self): filename = config.file_name # 上传文件名称 file = '{}{}'.format(config.file_url, filename) # 源文件及其路径 target = config.ceph_path # 上传路径 filePath = '{}{}'.format(target, filename) # 上传后文件及其路径 # 上传文件用于共享/取消共享操作 send_file_m_req.upload_file(self.token, file, target) # 共享文件给全局 uuid = get_uuid_from_token(self.token) # 文件所有者的uuid,同时也是文件共享者的uuid share_uuid = send_file_m_req.share_file(self.token, owner_uuid=uuid, sharePath=filePath, isGlobal=True) # 验证文件共享结果: 1)共享用户在“我的共享”文件夹下可看到共享文件 2)被共享用户在“接收的共享”文件夹下可看到被共享文件 my_share_file = send_file_m_req.get_shared_file_list( self.token, owner_id=uuid) # 共享用户查看"我的共享"文件夹,返回其下可查看到的文件列表 if filename not in my_share_file: logger.log_error('user {} cannot find shared file {}'.format( config.user_name_a, filename)) assert False shareuser_token = send_user_m_req.get_token_simple( config.user_name_b, config.user_passwd_b) # 被共享用户的token sharer_uuid = get_uuid_from_token(shareuser_token) # 被共享用户的uuid share_file_list = send_file_m_req.get_shared_file_list( shareuser_token, user_id=sharer_uuid) # 被共享用户查看"接收的共享",返回其下可查看到的文件列表 if filename not in share_file_list: logger.log_error('user {} cannot find shared file {}'.format( config.user_name_b, filename)) assert False # 取消共享文件 send_file_m_req.cancel_shared_file(self.token, share_uuid) # 验证文件共享结果: 1)共享用户的“我的共享”文件夹下已移除共享文件 2)被共享用户已在“接收的共享”文件夹下移除被共享文件 my_share_file = send_file_m_req.get_shared_file_list( self.token, owner_id=uuid) # 共享用户查看"我的共享"文件夹,返回其下可查看到的文件列表 if filename in my_share_file: logger.log_error('user {} should not find unshared file {}'.format( config.user_name_a, filename)) assert False share_file_list = send_file_m_req.get_shared_file_list( shareuser_token, user_id=sharer_uuid) # 被共享用户查看"接收的共享",返回其下可查看到的文件列表 if filename in share_file_list: logger.log_error('user {} should not find unshared file {}'.format( config.user_name_b, filename)) assert False # 删除文件 paths = [] paths.append(filePath) send_file_m_req.delete_files_and_folders(self.token, paths)
def test_SKTE_T3609_model_version_import(self): # 创建模型 model_uuid = send_model_m_req.create_model(self.token, model_name='T3609') user_uuid = send_user_m_req.get_uuid_by_username( self.token, config.user_name_a) model_location = '{}:{}'.format(user_uuid, config.tf_model_location) # 添加模型版本 description = 'T3609 description' version_uuid = send_model_m_req.create_model_version( self.token, model_uuid, model_location, description)['uuid'] # 获取模型版本信息并检查 result = send_model_m_req.get_model_version_info( self.token, model_uuid, version_uuid) if result['name'].lower() != 'v1': logger.log_error( 'Model version number is wrong, it should be "v1" but actually it is {}' .format(result['name'])) assert False if result['description'].strip() != description: logger.log_error( 'Model version description is wrong, it should be {} but actually it is {}' .format(description, result['description'].strip())) assert False if result['modelPath'].strip() != model_location: logger.log_error( 'Model version modelPath is wrong, it should be {} but actually it is {}' .format(model_location, result['modelPath'].strip())) assert False # 删除模型版本 send_model_m_req.delete_model_version(self.token, model_uuid, version_uuid) # 删除模型 send_model_m_req.delete_model(self.token, model_uuid)
def test_get_all_image_list(self): # 获取所有image list req = api_image_m.get_all_image_list_req(self.token) # 最多显示100条 count = 100 req.param.update({'count': count}) res = send_req.send_request(req) try: total = res['total'] except KeyError: logger.log_error('Can not get "total" from response.') raise Exception('Key "total" can not be found!') if total > count: total = count # 检查list中image的个数与total相同 if len(res['data']) != total: logger.log_error( 'The count of image info is wrong, total is {}, but get {}'. format(total, len(res['data']))) assert False
def create_user(token, username='******', fullname='*****@*****.**', password='******', permissions=None, active=True, roles=None, groups=None, expires="2050-12-31T00:00:00.000Z"): """ 创建新用户 Args: token: 管理员用户token username: 新用户名称 fullname: 新用户全名 password: 新用户密码 permissions: 新用户权限列表,默认[] active: 是否激活,默认True roles: 拥有角色列表,默认[] groups: 所属组列表, 默认[] expires: 过期时间,默认[] Returns: uuid """ if not roles: role_uuid = fetch_user_role_uuid_by_role_name( token, role_name=config.user_role_name) roles = [role_uuid] req = api_user_m.create_user_req(token, username, fullname, password, permissions, active, roles, groups, expires) resp = send_req.send_request(req, result_code='201') uuid = resp.get('uuid', '') logger.log_info(f"uuid is: {uuid}.") if len(uuid) == 0: logger.log_error(f"uuid is error.") assert False return uuid
def test_skte_t1002_copy_folder(self): # 上传文件用于文件夹拷贝 filename = config.file_name # 上传源文件名称 file = '{}{}'.format(config.file_url, filename) # 源文件及其路径 source_folder = 'T1002' # 需拷贝的源文件夹名称 source_path = '{}{}'.format(config.ceph_path, source_folder) # 文件上传的目的地址,同时也是拷贝目标 send_file_m_req.upload_file(self.token, file, source_path) # 创建文件夹作为拷贝目的地址 folder = 'T1002 copyfolder' send_file_m_req.create_folder(self.token, config.ceph_path, folder) # 拷贝文件夹 copy_source = source_path copy_sources = [] copy_sources.append(copy_source) # 拷贝的源文件夹及其路径列表 copy_target = '{}{}'.format(config.ceph_path, folder) # 文件夹拷贝的目标地址 send_file_m_req.copy_file(self.token, copy_sources, copy_target) # 校验拷贝结果 foldername_target = send_file_m_req.get_file_list( self.token, copy_target) # 拷贝目的地址文件名列表 if source_folder not in foldername_target: logger.log_error( 'file/folder {} copy failed, target address do not find it'. format(source_folder)) assert False foldername_target = send_file_m_req.get_file_list( self.token, config.ceph_path) # 拷贝源地址文件名列表 if source_folder not in foldername_target: logger.log_error( 'file/folder {} copy failed, source address do not find it'. format(source_folder)) assert False # 删除文件夹 path_folder = [] path_folder.append(copy_source) path_folder.append(copy_target) send_file_m_req.delete_files_and_folders(self.token, path_folder)
def test_SKTE_T3622_modity_model_version(self): # 创建模型 model_uuid = send_model_m_req.create_model(self.token, model_name='T3622') user_uuid = send_user_m_req.get_uuid_by_username( self.token, config.user_name_a) model_location = '{}:{}'.format(user_uuid, config.tf_model_location) # 添加模型版本 description = 'T3622 description' version_uuid = send_model_m_req.create_model_version( self.token, model_uuid, model_location, description)['uuid'] # 修改模型版本 modelPath_mdf = '{}:{}'.format(user_uuid, config.spark_model_location) description_mdf = 'T3609 description modified' send_model_m_req.modity_model_version(self.token, model_uuid, version_uuid, modelPath_mdf, description_mdf) # 获取模型版本信息并检查 result = send_model_m_req.get_model_version_info( self.token, model_uuid, version_uuid) if result['description'].strip() != description: logger.log_error( 'Model version description is wrong, it should be {} but actually it is {}' .format(description_mdf, result['description'].strip())) assert False if result['modelPath'].strip() != model_location: logger.log_error( 'Model version modelPath is wrong, it should be {} but actually it is {}' .format(modelPath_mdf, result['modelPath'].strip())) assert False # 删除模型版本 send_model_m_req.delete_model_version(self.token, model_uuid, version_uuid) # 删除模型 send_model_m_req.delete_model(self.token, model_uuid)
def test_skte_t997_move_folder(self): # 上传文件用于文件夹移动 filename = config.file_name # 上传源文件名称 file = '{}{}'.format(config.file_url, filename) # 源文件及其路径 source_folder = 'T997' # 需移动的源文件夹名称 source_path = '{}{}'.format(config.ceph_path, source_folder) # 文件上传的目的地址,同时也是移动目标 send_file_m_req.upload_file(self.token, file, source_path) # 创建文件夹作为移动目的地址 folder = 'T997 movefolder' send_file_m_req.create_folder(self.token, config.ceph_path, folder) # 移动文件夹 move_source = source_path move_sources = [] move_sources.append(move_source) # 移动的源文件夹及其路径列表 move_target = '{}{}'.format(config.ceph_path, folder) # 文件夹移动的目标地址 send_file_m_req.move_file(self.token, move_sources, move_target) # 校验移动结果 foldername_target = send_file_m_req.get_file_list( self.token, move_target) # 移动目的地址文件名列表 if source_folder not in foldername_target: logger.log_error( 'file/folder {} move failed, target address do not find it'. format(source_folder)) assert False foldername_target = send_file_m_req.get_file_list( self.token, config.ceph_path) # 移动源地址文件名列表 if source_folder in foldername_target: logger.log_error( 'file/folder {} move failed, source address have not moved it away' .format(source_folder)) assert False # 删除文件夹 path_folder = [] path_folder.append(move_target) send_file_m_req.delete_files_and_folders(self.token, path_folder)
def test_SKTE_T3606_modify_model(self): # 创建模型 uuid = send_model_m_req.create_model(self.token, model_name='T3606') # 修改模型 model_name = 'T3606_modified' description = 'modified test' labels = ['lmodified'] model_type = 'mmodified' send_model_m_req.modify_model(token=self.token, uuid=uuid, model_name=model_name, description=description, labels=labels, model_type=model_type, share_type='PRIVATE') # 获取模型信息并检查修改结果 result = send_model_m_req.get_model_info(self.token, uuid) if result['name'] != model_name: logger.log_error( 'Model name is wrong, it should be {} but actually it is {}'. format(model_name, result['name'])) assert False if result['description'].strip() != description: logger.log_error( 'Model description is wrong, it should be {} but actually it is {}' .format(description, result['description'].strip())) assert False if result['labels'] != labels: logger.log_error( 'Model labels is wrong, it should be {} but actually it is {}'. format(labels, result['labels'])) assert False if result['modelType'] != model_type: logger.log_error( 'Model type is wrong, it should be {} but actually it is {}'. format(model_type, result['modelType'])) assert False # 删除模型 send_model_m_req.delete_model(self.token, uuid)
def test_SKTE_T1081_create_user_group(self): # 创建用户组并且删除. 同时实现了用例SKTE-T1085, SKTE-T1083, SKTE-T1080 # 获取user_role角色的uuid user_role_uuid = send_user_m_req.fetch_user_role_uuid_by_role_name( self.token, config.user_role_name) group_name = 'group_T1081' # 创建用户组 if user_role_uuid: group_uuid = send_user_m_req.create_user_group( self.token, group_name, [user_role_uuid]) else: # 找不到角色的uuid assert False # 修改用户组 new_group_name = group_name + '_new' # 获取admin_role角色的uuid admin_role_uuid = send_user_m_req.fetch_user_role_uuid_by_role_name( self.token, config.admin_role_name) new_role = [user_role_uuid, admin_role_uuid] send_user_m_req.modify_user_group(self.token, group_uuid, new_group_name, new_role) # 检查修改结果 user_group_details = send_user_m_req.get_user_group_detail( self.token, group_uuid) if user_group_details['name'] != new_group_name: logger.log_error( 'The group name is wrong, it should be {}, but it is {}'. format(new_group_name, user_group_details['name'])) assert False if user_group_details['roles'] != new_role: logger.log_error( 'The group role is wrong, it should be {}, but it is {}'. format(new_role, user_group_details['roles'])) assert False # 删除刚刚创建的用户组 send_user_m_req.delete_user_group(self.token, group_uuid) # 确认用户组已被删除 if send_user_m_req.fetch_user_group_uuid_by_group_name( self.token, group_name): logger.log_error( 'The user group should be deleted, but it is still existed.') assert False
def test_SKTE_T1020_extract_file(self): # Title: 解压文件 # Owner:qingzhen # PreCondition:创建测试目录T1020,上传zip文件到该目录成功 zip_file = '{}{}'.format(config.file_url, config.zip_file_name) target = config.ceph_path send_file_m_req.create_folder(self.token, target, 'T1020') zip_file_path = '{}T1020'.format(target) zip_file_path_full = '{}/{}'.format(zip_file_path, config.zip_file_name) send_file_m_req.upload_file(self.token, zip_file, zip_file_path) # 1. 解压zip文件成功 send_file_m_req.extract_file(self.token, zip_file_path_full, zip_file_path) # 2. 查看解压文件,目录结构如下 iris / iris1 (iris1.csv) + iris2 (iris2.csv + iris3.csv) folder_iris1_files = send_file_m_req.get_file_list( self.token, '{}/iris/iris1'.format(zip_file_path)) if 'iris1.csv' not in folder_iris1_files: logger.log_error( 'iris1.csv not include in folder T1020/iris/iris1, actually files under folder are {}' .format(folder_iris1_files)) assert False folder_iris2_files = send_file_m_req.get_file_list( self.token, '{}/iris/iris2'.format(zip_file_path)) # if 'iris2.csv' not in folder_iris2_files: logger.log_error( 'iris2.csv not include in folder T1020/iris/iris2, actually files under folder are {}' .format(folder_iris2_files)) assert False if 'iris3.csv' not in folder_iris2_files: logger.log_error( 'iris3.csv not include in folder T1020/iris/iris2, actually files under folder are {}' .format(folder_iris2_files)) assert False # Reset:删除zip文件及文件夹 send_file_m_req.delete_files_and_folders(self.token, paths=[target + 'T1020'])
def test_SKTE_T3623_delete_model_version_then_add_new_version(self): # Title: 删除模型版本后添加版本 # Owner: qingzhen # PreCondition:新建模型,添加模型版本v1和v2 model_uuid = send_model_m_req.create_model(self.token, model_name='T3623') time.sleep(1) user_uuid = send_user_m_req.get_uuid_by_username( self.token, config.user_name_a) time.sleep(1) model_location = '{}:{}'.format(user_uuid, config.tf_model_location) description = 'T3623 description' version_uuid_v1 = send_model_m_req.create_model_version( self.token, model_uuid, model_location, description)['uuid'] time.sleep(1) result = send_model_m_req.get_model_version_info( self.token, model_uuid, version_uuid_v1) if result['name'].lower() != 'v1': logger.log_error( 'Model version number is wrong, it should be "v1" but actually it is {}' .format(result['name'])) assert False version_uuid_v2 = send_model_m_req.create_model_version( self.token, model_uuid, model_location, description)['uuid'] time.sleep(1) result = send_model_m_req.get_model_version_info( self.token, model_uuid, version_uuid_v2) if result['name'].lower() != 'v2': logger.log_error( 'Model version number is wrong, it should be "v2" but actually it is {}' .format(result['name'])) assert False time.sleep(1) # 1.删除模型版本 v1 send_model_m_req.delete_model_version(self.token, model_uuid, version_uuid_v1) # 2. 删除版本 v1后检查模型版本 time.sleep(1) send_model_m_req.get_model_version_info(self.token, model_uuid, version_uuid_v1, resultcode='404') time.sleep(1) send_model_m_req.get_model_version_info(self.token, model_uuid, version_uuid_v2) if result['name'].lower() != 'v2': logger.log_error( 'Model version number is wrong, it should be "v2" but actually it is {}' .format(result['name'])) assert False # 3. 添加模型版本 v3 time.sleep(1) version_uuid_v3 = send_model_m_req.create_model_version( self.token, model_uuid, model_location, description)['uuid'] time.sleep(1) result = send_model_m_req.get_model_version_info( self.token, model_uuid, version_uuid_v3) if result['name'].lower() != 'v3': logger.log_error( 'Model version number is wrong, it should be "v3" but actually it is {}' .format(result['name'])) assert False # 4.删除模型版本 v3 send_model_m_req.delete_model_version(self.token, model_uuid, version_uuid_v3) time.sleep(1) send_model_m_req.get_model_version_info(self.token, model_uuid, version_uuid_v3, resultcode='404') time.sleep(1) # 5.添加模型版本 v4,并检查剩下模型版本v2,v4信息。 version_uuid_v4 = send_model_m_req.create_model_version( self.token, model_uuid, model_location, description)['uuid'] time.sleep(1) result = send_model_m_req.get_model_version_info( self.token, model_uuid, version_uuid_v4) if result['name'].lower() != 'v4': logger.log_error( 'Model version number is wrong, it should be "v4" but actually it is {}' .format(result['name'])) assert False time.sleep(1) result = send_model_m_req.get_model_version_info( self.token, model_uuid, version_uuid_v2) if result['name'].lower() != 'v2': logger.log_error( 'Model version number is wrong, it should be "v2" but actually it is {}' .format(result['name'])) assert False time.sleep(1) # Reset:删除模型 send_model_m_req.delete_model(self.token, model_uuid)
def send_request(request_data: ApiTemplate, result_code='200'): """ 将request_data的内容组成http请求并发送,检查result code并返回response body。 :param request_data: 接口请求内容,包括请求方法、请求URL、URL参数、请求头、请求体 :param result_code: 期望的response code :return: http response """ if len(request_data.url) == 0 or len(request_data.method) == 0: logger.log_error("request_data's url or/and method is not presented.") return False else: # 拼接HTTP请求 url = request_data.url+'?' if len(request_data.param) > 0 else request_data.url for i, j in request_data.param.items(): if url.endswith('?'): url = '{}{}={}'.format(url, i, j) else: url = '{}&{}={}'.format(url, i, j) method = request_data.method.upper() headers = request_data.headers data = request_data.body files = request_data.files # 发送请求 if method == 'POST': if len(request_data.files) == 0: result = requests.post(url=url, headers=headers, json=data) else: result = requests.post(url=url, headers=headers, data=data, files=files) elif method == 'GET': result = requests.get(url=url, headers=headers) elif method == 'DELETE': result = requests.delete(url=url, headers=headers) elif method == 'PATCH': result = requests.patch(url=url, headers=headers, json=data) elif method == 'OPTIONS': result = requests.options(url=url, headers=headers) elif method == 'HEAD': result = requests.head(url=url, headers=headers) else: logger.log_error("The HTTP method of {} in request_data is not supported!".format(request_data.url)) return False logger.log_debug("url: {}".format(url)) logger.log_debug("method: {}".format(method)) logger.log_debug("headers: {}".format(headers)) logger.log_debug("data: {}".format(data)) logger.log_debug(">>>>>>>> The HTTP request is sent.") # 部分请求返回结果不是json格式,如下载文件,返回为文件内容 if result.text.startswith("{"): # 部分请求如DELETE成功执行后result.content为空 if len(result.content) != 0: content = json.loads(str(result.content, 'utf-8')) else: content = '' else: content = result.text logger.log_debug("status code: {}".format(result.status_code)) logger.log_debug("headers: {}".format(result.headers)) logger.log_debug("body: {}".format(content)) logger.log_debug("<<<<<<<< Got HTTP response.") # 检查return code if str(result.status_code) != result_code: logger.log_error("The result code of response is {}, not the expected value: {}".format(result.status_code, result_code)) assert False return content