示例#1
0
def api_response_result_data(resp_dict):
    """
    @author: june.chen
    @resp_dict: 待比对的字典集和
    @return: data空值校验 True/False
    @summary: 返回的data是否为空
    """
    Logger.info("检查返回的data是否为空")
    if resp_dict.has_key(Config.ApiConfig().ResponseStruct.ErrorCodeKey):
        if resp_dict[Config.ApiConfig().ResponseStruct.ErrorCodeKey] != 0:
            Logger.info("API接口数据返回的错误码errorCode不等于0")
            return False
    else:
        Logger.info("API接口数据中不存在错误码")
        return False

    if resp_dict.has_key(Config.ApiConfig().ResponseStruct.DataKey):
        data = Config.ApiConfig().ResponseStruct.DataKey
        if resp_dict[data] == [] or resp_dict[data] == '' or resp_dict[
                data] == {} or resp_dict[data] == None:
            Logger.info("API接口数据中data为空")
            return False
        else:
            Logger.info("API接口数据中data不为空")
            return True
    else:
        Logger.info("API接口数据没有查询数据返回")
        return False
示例#2
0
def api_request_result(params_dict, host = ""):
    """
    @author: eason.sun
    @param_dict: API请求的数据(字典类型)
    @host: API请求的URL
    @return: 返回处理后的POST请求结果
    @summary: 获取API响应结果后,将数据进行格式化
    """    
    if not len(host):
        host = Config.ApiConfig().URL
    # 获取POST请求返回的结果
    post_response = post_request_result(params_dict, host)
    # 将部分null值的返回值设置为空字符串
    post_response = post_response.read().replace("null", '""')
    # false替换为False,true替换为True
    post_response = post_response.replace("false", "False").replace("true", "True")
    # 以字典集返回结果
    dict_post = eval(post_response)
    # API定义所有返回结果都保存在data键中
    post_data = dict_post["data"]
    if type(post_data) == dict: # 返回data的类型为dict,则结果为单条记录
        result_escape(post_data)
    elif type(post_data) == list: # 返回data的类型为list,则结果为多条记录
        post_data = [result_escape(post_item) for post_item in post_data]
    return dict_post
示例#3
0
def api_response_result_null(resp_dict):
    """
    @author: eason.sun
    @resp_dict: 待比对的字典集和
    @return: 对API返回的数据进行空值校验 True/False
    @summary: 比较字典内容是否为空,以下为接口返回数据:version/action/errCode/allRows/data
    """
    if not resp_dict.has_key(Config.ApiConfig().ResponseStruct.VersionKey):
        return False
    Logger.info("API接口数据中有版本信息")
    if not resp_dict.has_key(Config.ApiConfig().ResponseStruct.ActionKey):
        return False
    Logger.info("API接口数据中有Action信息")
    if not resp_dict.has_key(Config.ApiConfig().ResponseStruct.ErrorCodeKey):
        return False
    Logger.info("API接口数据中有错误码信息")
    if not resp_dict.has_key(Config.ApiConfig().ResponseStruct.AllRowsKey):
        return False
    Logger.info("API接口数据中有行数信息")
    if not resp_dict.has_key(Config.ApiConfig().ResponseStruct.DataKey):
        return False
    Logger.info("API接口数据中有数据信息")
    return True
示例#4
0
def api_result_basic_info_cmp(src_dict, dst_dict):
    """
    @author: june.chen
    @resp_dict: 源字典集合
    @dst_dict: 目的字典集合
    @return: True/False
    @summary: 数据基础数据比较:version/action/errorCode/allRows
    """
    Logger.info("检查基础内容")
    if src_dict[Config.ApiConfig().ResponseStruct.VersionKey] != dst_dict[
            Config.ApiConfig().ResponseStruct.VersionKey]:
        Logger.info("版本号比对失败")
        Logger.info(src_dict[Config.ApiConfig().ResponseStruct.VersionKey])
        Logger.info(dst_dict[Config.ApiConfig().ResponseStruct.VersionKey])
        return False
    if src_dict[Config.ApiConfig().ResponseStruct.ActionKey] != dst_dict[
            Config.ApiConfig().ResponseStruct.ActionKey]:
        Logger.info("action方法比对失败")
        Logger.info(src_dict[Config.ApiConfig().ResponseStruct.ActionKey])
        Logger.info(dst_dict[Config.ApiConfig().ResponseStruct.ActionKey])
        return False
    if src_dict[Config.ApiConfig().ResponseStruct.ErrorCodeKey] != dst_dict[
            Config.ApiConfig().ResponseStruct.ErrorCodeKey]:
        Logger.info("错误码比对失败")
        Logger.info(src_dict[Config.ApiConfig().ResponseStruct.ErrorCodeKey])
        Logger.info(dst_dict[Config.ApiConfig().ResponseStruct.ErrorCodeKey])
        return False
    if src_dict[Config.ApiConfig().ResponseStruct.AllRowsKey] != dst_dict[
            Config.ApiConfig().ResponseStruct.AllRowsKey]:
        Logger.info("行数比对失败")
        Logger.info(src_dict[Config.ApiConfig().ResponseStruct.AllRowsKey])
        Logger.info(dst_dict[Config.ApiConfig().ResponseStruct.AllRowsKey])
        return False
    return True