python - 如何使用 Python API (pyral) 在 Rally 中更新测试用例的步骤

标签 python rally pyral

多亏了 Rally API 的在线文档,我知道如何 create test stepsupdate a defect/test case .

一个类似的问题已经被问到并回答了关于使用...

但是,我没有成功使用 python API (pyral) 更新测试步骤。

我试过下面的代码:

TCid = "TC1392"
testcase=rally.get('TestCase', query='FormattedID = %s' % TCid, instance=True)
print "Updating steps for Test Case %s" % testcase.FormattedID
#Test Steps
try:
    for i in range(3):
        input="Step Input for Step: "+str(i)
        expected_result="Expected Result for Step: "+str(i)

        testcasestep_fields = {
            "TestCase"          : testcase.ref,
            "StepIndex"         : i,
            "Input"             : input,
            "ExpectedResult"    : expected_result
        }

        testcasestep = rally.update('TestCaseStep', testcasestep_fields)
    print "Steps of TestCase %s updated\n" % testcase.FormattedID
except RallyRESTAPIError, details:
    sys.stderr.write('ERROR: %s \n\n' % details)

但这会返回以下错误:必须指定标识字段(Object 或 FormattedID)。该错误由 pyral/restapi.py 的第 991 行引发。

如何让它发挥作用?

最佳答案

我找到的解决方案是采用另一种方法并循环执行这些步骤,因此能够检索每个步骤的 oid。

[2015 年 5 月 14 日更新]:更好的方法是执行 3 个步骤:

  1. 更新现有测试步骤(如果有的话)
  2. 创建新的测试步骤(如果需要)
  3. 删除额外的测试步骤(如果需要)

程序应首先确定每个操作的步骤数。


结果是这样的:

TCid = "TC1394"
#Generate random number of steps
def generate_Steps():
    list_Steps=[]
    import random
    n_steps=random.randrange(1,15)
    for i in range(n_steps):
        Step={'StepIndex':i+1}
        Step['Input']="Step Input for step %d" % (i+1)
        Step['ExpectedResult']="Expected Result for step %d" % (i+1)
        list_Steps.append(Step)
    print "Using random list of %d Test Steps" % (n_steps)
    return list_Steps

#Update steps
def update_TestSteps(TCid, Steps):
    try:
        #Get number of existing steps
        testcase=rally.get('TestCase', query='FormattedID = %s' % TCid, instance=True)
        print "Updating steps for Test Case %s" % testcase.FormattedID
        list_steps=sorted(testcase.Steps, key=lambda step: step.StepIndex)
        #Calculate what to do on the steps (how many to update, create, or delete)
        nb_steps = { 'Rally':len(testcase.Steps), 'HTML':len(Steps) } 
        nb_steps['toUpdate'] = min(nb_steps['Rally'], nb_steps['HTML'])
        nb_steps['toCreate'] = nb_steps['HTML'] - nb_steps['toUpdate']
        nb_steps['toDelete'] = nb_steps['Rally'] - nb_steps['toUpdate']

        #Update content of existing steps with steps from test case
        for StepIndex in range(nb_steps['toUpdate']):
            step=list_steps[StepIndex]
            teststep_fields = Steps[StepIndex]
            (teststep_fields['TestCase'], teststep_fields['ObjectID']) = (testcase.ref, step.oid)
            teststep = rally.update('TestCaseStep', teststep_fields)
        #Create new test steps when required
        for StepIndex in range(nb_steps['toCreate']):
            teststep_fields = Steps[StepIndex+nb_steps['toUpdate']]
            teststep_fields['TestCase'] = testcase.ref
            teststep = rally.put('TestCaseStep', teststep_fields)
        #Delete extra test steps
        for StepIndex in range(nb_steps['toDelete']):
            step=list_steps[StepIndex+nb_steps['toUpdate']]
            rally.delete('TestCaseStep', step.oid)

        #Print message for end of test step update
        message="Updated test steps for TestCase %s" % testcase.FormattedID
        message+=" (steps created: {toCreate}, updated: {toUpdate}, deleted: {toDelete})".format(**nb_steps)
        print message

    except RallyRESTAPIError, details:
        sys.stderr.write('Rally Error during update of Test Step:  %s \n\n' % details)

#Update random list of Steps
update_TestSteps(TCid, generate_Steps())

关于python - 如何使用 Python API (pyral) 在 Rally 中更新测试用例的步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30091375/

相关文章:

python - 尝试创建 Rally 测试用例时出现错误 "RallyRESTAPIError: 422 Not authorized to perform action: Invalid key"

python - 通过 Pyral 向 Rally 添加任务

python - 无法从网页的不同深度抓取相似的链接

python - 带权重的 Xarray 滚动平均值

python - 使用twistd部署Flask

javascript - 显示最后一个记录值,不是所有值都循环

python - 使用Pyral向Rally神器添加图片

python - 如何创建一个循环模块,为每个 SQL 行结果一次创建一个窗口?

javascript - 反弹回顾是最低的投资组合项目索引字段?

java - 使用 Rally API 访问自定义页面(示例 : Plan->Backlog)