【大爆炸】base_case_lib
# -*- coding: utf-8 -*- """ ------------------------------------------------- File Name: base_case_lib Description : 用例基库类 Author : jiaoyaxiong date: 2019/7/22 ------------------------------------------------- Change Activity: 2019/7/22: ------------------------------------------------- """ __author__ = 'jiaoyaxiong' import hcslog import conf import traceback import sys import AddSharesToExpressSyncRequest from xml.etree import ElementTree from aliyunsdkcore import client class common_lib(object,): def __init__(self,casemae): log_obj=hcslog.hcs_logger(casemae) self.logger=log_obj() self.txt_path=log_obj.txt_log_path self.cfg=conf.get_conf() cfg=conf.get_conf() clt_default = client.AcsClient(cfg["global"]["oss_ak_encrypt"], cfg["global"]["oss_sk_encrypt"], cfg["global"]["RegionId_Hangzhou"]) def do_AddSharesToExpressSyncRequest(self,ExpressSyncId=None, GatewayShares=None, req_client=clt_default): request = AddSharesToExpressSyncRequest.AddSharesToExpressSyncRequest() #当前函数的名称,通过sys 获取,其实logging 也可以 # %(funcName)s Function name # https://blog.csdn.net/haoxun07/article/details/104467589 function_name = sys._getframe().f_code.co_name if ExpressSyncId is not None: request.set_ExpressSyncId(ExpressSyncId) if GatewayShares is not None: request.set_GatewayShares(GatewayShares) result_dict = {} result_dict["Success"] = False result_dict["ReuqestId"] = "" result_dict["ErrorMassage"] = "" result_dict["Response"] = "" try: result = req_client.do_action(request) result_dict["Response"] = str(result) self.logger.info(result) root = ElementTree.fromstring(result) ele = root.findall("Success") result_dict["ReuqestId"] = root.find("RequestId").text if ele: self.logger.info("%s success" % str(function_name)) result_dict["Success"] = True # api 特有的 # result_dict["GatewayId"] = root.find("GatewayId").text result_dict["TaskId"] = root.find("TaskId").text else: self.logger.error("%s failed !" % str(function_name) ) result_dict["Success"] = False except Exception as e: self.logger.error("%s error. " % str(function_name)) self.logger.error(traceback.format_exc()) result_dict["Success"] = False result_dict["ErrorMassage"] = str(e) return result_dict return result_dict # 复习处理xml 和 json 类型数据