Ejemplo n.º 1
0
def execute_dubbo_interface(*args):
    '''
       执行DUBBO接口列表,可以有多个接口。
       :param args: dubbo接口列表,最后一个arg可以是IGNORE_ALL IGNORE_FAIL_ERROR等忽略信息
       :return: 执行后的接口对象或者接口对象列表
       '''
    interfaceIdList = args
    # 如果获取参数等导致错误,不继续执行登录返回错误原因。

    # 处理 interfaceIdList 判断是否结果影响后续执行
    # IGNORE_ALL IGNORE_FAIL_ERROR
    interfaceIdList, whetherSetResultWhenFAIL, whetherSetResultWhenERROR, whetherSetResultWhenEXCEPTION = processWhetherIGNORE(interfaceIdList)
    # 处理结束 interfaceIdList #########

    startInterfaceId = context.interfaceId
    interfaceTobeExecutedList = []
    for i in range(0, len(interfaceIdList)):
        endInterfaceId = interfaceIdList[i].strip()
        if endInterfaceId == "":
            continue
        if isLoop(context.calledInterfaceRecurDict, startInterfaceId, endInterfaceId):
            tobeReplacedError = "接口[%s]被循环调用形成死循环,请检查用例。" % endInterfaceId
            set_result("ERROR", tobeReplacedError)
            break
        else:
            if startInterfaceId not in context.calledInterfaceRecurDict.keys():
                context.calledInterfaceRecurDict[startInterfaceId] = []
            context.calledInterfaceRecurDict[startInterfaceId].append(endInterfaceId)

        import allmodels.DubboInterface
        interfaceTobeExecuted = allmodels.DubboInterface.DubboInterface()
        interfaceTobeExecuted.interfaceId = endInterfaceId
        interfaceTobeExecuted.version = context.version  # 加入版本属性。
        retBool = interfaceTobeExecuted.generateByInterfaceId()
        if retBool == False:
            tobeReplacedError = "接口[%s]没有找到,请确认是否存在或者已删除。" % endInterfaceId
            set_result("ERROR", tobeReplacedError)
            break

        executeAndTransferContext(interfaceTobeExecuted, context)
        interfaceTobeExecutedList.append(interfaceTobeExecuted)
        log("执行接口[%s],执行结果:%s" % (interfaceTobeExecuted.interfaceId, interfaceTobeExecuted.testResult))

        if interfaceTobeExecuted.testResult == "FAIL":
            if whetherSetResultWhenFAIL:
                set_result(interfaceTobeExecuted.testResult, "执行接口%s结果FAIL,断言结果:%s" % (interfaceTobeExecuted.interfaceId, interfaceTobeExecuted.assertResult))

        if interfaceTobeExecuted.testResult == "ERROR":
            if whetherSetResultWhenERROR:
                set_result(interfaceTobeExecuted.testResult, "执行接口%s出现错误,错误原因:%s" % (interfaceTobeExecuted.interfaceId, interfaceTobeExecuted.assertResult))

        if interfaceTobeExecuted.testResult == "EXCEPTION":
            if whetherSetResultWhenEXCEPTION:
                set_result(interfaceTobeExecuted.testResult,"执行接口%s出现异常,异常原因:%s" % (interfaceTobeExecuted.interfaceId,interfaceTobeExecuted.assertResult))

    return interfaceTobeExecutedList[0] if len(interfaceTobeExecutedList) == 1 else interfaceTobeExecutedList
Ejemplo n.º 2
0
def execute_testcase(*args):
    '''
       执行HTTP业务流列表,可以有多个业务流。
       :param args: http业务流列表,最后一个arg可以是IGNORE_ALL IGNORE_FAIL_ERROR等忽略信息
       :return: 执行后的业务流对象或者业务流对象列表
       '''
    TestCaseIdList = args

    # 处理 TestCaseIdList 判断是否结果影响后续执行
    # IGNORE_ALL IGNORE_FAIL_ERROR
    TestCaseIdList, whetherSetResultWhenFAIL, whetherSetResultWhenERROR, whetherSetResultWhenEXCEPTION = processWhetherIGNORE(TestCaseIdList)

    # 处理结束 TestCaseIdList #########

    startTestCaseId = context.caseId
    testCaseTobeExecuteList = []
    for i in range(0, len(TestCaseIdList)):
        endTestCaseId = TestCaseIdList[i].strip()
        if endTestCaseId == "":
            continue
        if isLoop(context.calledInterfaceRecurDict, startTestCaseId, endTestCaseId):
            tobeReplacedError = "用例[%s]被循环调用形成死循环,请检查用例。" % endTestCaseId
            set_result("ERROR", tobeReplacedError)
            break
        else:
            if startTestCaseId not in context.calledInterfaceRecurDict.keys():
                context.calledInterfaceRecurDict[startTestCaseId] = []
            context.calledInterfaceRecurDict[startTestCaseId].append(endTestCaseId)

        import allmodels.HttpTestcase
        testCaseTobeExecute = allmodels.HttpTestcase.HttpTestcase()
        testCaseTobeExecute.caseId = endTestCaseId
        testCaseTobeExecute.version = context.version
        testCaseTobeExecute.generateByCaseId()

        executeAndTransferContext(testCaseTobeExecute,context)
        log("执行业务流[%s],执行结果:%s" % (testCaseTobeExecute.caseId, testCaseTobeExecute.testResult))
        testCaseTobeExecuteList.append(testCaseTobeExecute)

        if testCaseTobeExecute.testResult == "FAIL":
            if whetherSetResultWhenFAIL:
                set_result(testCaseTobeExecute.testResult, "执行业务流%s结果FAIL,断言结果:%s" % (testCaseTobeExecute.caseId, testCaseTobeExecute.assertResult))

        if testCaseTobeExecute.testResult == "ERROR":
            if whetherSetResultWhenERROR:
                set_result(testCaseTobeExecute.testResult, "执行业务流%s出现错误,错误原因:%s" % (testCaseTobeExecute.caseId, testCaseTobeExecute.assertResult))

        if testCaseTobeExecute.testResult == "EXCEPTION":
            if whetherSetResultWhenEXCEPTION:
                set_result(testCaseTobeExecute.testResult,"执行业务流%s出现异常,异常原因:%s" % (testCaseTobeExecute.caseId,testCaseTobeExecute.assertResult))

    return testCaseTobeExecuteList[0] if len(testCaseTobeExecuteList) == 1 else testCaseTobeExecuteList