使用python在Rally中创建新缺陷时出现错误

时间:2019-01-02 05:01:27

标签: python rally

以下是我的代码,使用python向集会中添加新缺陷:

import sys import time from pyral import Rally, rallyWorkset
server = "rally1.rallydev.com" 
user = "*****" 
password = "****" 
apikey = "****" 
workspace = "****" 
project = "****"
rally = Rally(server, user=user, password=password,apikey=apikey, workspace=workspace, project=project)

project_req = rally.get('Project', fetch=True, query='Name = "%s"' % (project))
project = project_req.next()

priority = "3.Normal" 
severity = "Major Problem" 
name = "prabhakar.sharma@***.com"
#defectID = 'INC0547865'
description = "A Test Rally User Story created using python API now, start working on it as fast as you all could !!" 
user = rally.getUserInfo(username=name).pop(0)
#rally.setProject(proj) 
print("%s %s "% (project.oid , user.ref)) 
defect_data = { "Project" : project.ref,
                "SubmittedBy" : user.ref,
                "Name" : name,
                "Severity" : severity, 
                "Priority" : priority,
               "State" : "Open", 
                "ScheduleState" : "Defined",
                "Owner": user.ref,
                "Description" : description 
                }


defect = rally.create('Defect', defect_data) print("Defect created, ObjectID: %s  FormattedID: %s" % (defect.oid, defect.FormattedID))

跟踪:

  

回溯(最近一次通话最后一次):文件“ pythonrally.py”,第186行,   在       缺陷= rally.create('缺陷',缺陷数据)文件“ C:\ Users \ PRABHAKAR.SHARMA \ AppData \ Local \ Programs \ Python \ Python37 \ pyral \ restapi.py”,   输入的第1024行       引发RallyRESTAPIError(问题)pyral.restapi.RallyRESTAPIError:422验证错误:Defect.PRJ#不应为空

2 个答案:

答案 0 :(得分:0)

更改:

  1. 必须使用“ username = name”(其中“ name”是登录ID)代替“ username = user”。
  2. “何时”字段不是缺陷的一部分(注释如下)。
  3. “ PRJ#”字段不是“缺陷”的一部分(注释如下)。
  4. 项目引用必须指定为“ proj.ref”而不是“ project.ref”。

    $ diff code.orig code.new
    10c10
    < user = rally.getUserInfo(username=user).pop(0)
    ---
    > user = rally.getUserInfo(username=name).pop(0)
    12,14c12,14
    < defect_data = { "When" : when,
    <                 "PRJ#" : project.oid,
    <                 "Project" : project.ref,
    ---
    > defect_data = { #"When" : when,
    >                 #"PRJ#" : proj.oid,
    >                 "Project" : proj.ref,
    

以上更改对我有用。

答案 1 :(得分:0)

所以,我在下面一行更改了:

defect = rally.create('Defect', defect_data) print("Defect created, ObjectID: %s  FormattedID: %s" % (defect.oid, defect.FormattedID))

defect = rally.create('UserStory', defect_data) print("Defect created, ObjectID: %s  FormattedID: %s" % (defect.oid, defect.FormattedID))

,然后是什么错误告诉我我可以正常工作了。 另外,我从“ defect_data”中删除了一些字段,如下所示:

defect_data = { "Project" : project.ref,
                #"SubmittedBy" : user.ref,
                "Name" : name,
                #"Severity" : severity, 
                "Priority" : priority,
                #"State" : "Open", 
                "ScheduleState" : "Defined",
                "Owner": user.ref,
                "Description" : description 
                }

最终密码:

project_req = rally.get('Project', fetch=True, query='Name = "%s"' % (project))
project = project_req.next()
priority = "Normal"
severity = "Major Problem"
name = "prabhakar.sharma@dish.com"
#when = "2018.12.26 - 2019.01.01"
#defectNum = 'INC0547865'
description = "Just one more test Rally User Story created using python API now, start working on it as fast as you all could !!"
user = rally.getUserInfo(username=user).pop(0)
#rally.setProject(proj)
print("%s %s "% (project.ref , user.ref))
defect_data = { "Project" : project.ref,
                #"SubmittedBy" : user.ref,
                "Name" : name,
                #"Severity" : severity, 
                "Priority" : priority,
                #"State" : "Open", 
                "ScheduleState" : "Defined",
                "Owner": user.ref,
                "Description" : description 
                }
try:
    print("am here %s "% defect_data)
    defect = rally.create('UserStory', defect_data)
except Exception as e:
    sys.stderr.write('ERROR: %s \n' % Exception)
    print(e)
    sys.exit(1)

希望这可以为面临任何此类问题的人提供服务!!欢呼声