Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

Inserting dynamic Acceptance Criteria into Customfield via Python

i am quiet lost currently.

i want to load some data from my sqlite3 db and then create from this data some acceptance criteria and update the respective issue with these acc.

The issue i have is that i dont understand where my problem is regarding the "build" of the list element that contains the data for the acceptance criteria

i iterate over the data i did load from my DB to create a string variable.

for entry in accDict:
    strAcc = (
        strAcc
        + '{"name":'
        + entry["NAME"]
        + ',"checked": False,"Mandatory":'
        + entry["MANDATORY"]
        + ',"option": False,"id":'
        + str(cnt_id)
        + ',"rank": '
        + str(cnt_rank)
        + ",} "
    )
    cnt_id += 1
    cnt_rank += 1

strAcc = "[{" + strAcc + "}]"

next i want to insert this string and update the customfields for the respective issue.

    new_issue.update(fields={"customfield_11100": [strAcc]})

the code in strAcc looks as follows

[{
    {"name":Create Testcases,"checked": False,"Mandatory":True,"option": False,"id":1,"rank": 0,},
    {"name":Request Testdata,"checked": False,"Mandatory":True,"option": False,"id":2,"rank": 1,},
    {"name":Verify Testressources,"checked": False,"Mandatory":True,"option": False,"id":3,"rank": 2,},
}]

this means the complete insert looks as this

new_issue.update(fields={"customfield_11100":[{
    {"name":Create Testcases,"checked": False,"Mandatory":True,"option": False,"id":1,"rank": 0,},
    {"name":Request Testdata,"checked": False,"Mandatory":True,"option": False,"id":2,"rank": 1,},
    {"name":Verify Testressources,"checked": False,"Mandatory":True,"option": False,"id":3,"rank": 2,},
}]})

the error i receive is

response text = {"errorMessages":["Internal server error"],"errors":{}}

if i create the string by hand and place it as in the last code block it works perfectly...

question from:https://stackoverflow.com/questions/65643998/inserting-dynamic-acceptance-criteria-into-customfield-via-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you're missing quotes in the "name" attribute...

Furthermore I'd suggest you write actual python dicts, and not json strings, as they can be translated easily, plus improves readability:

strAcc = []
for entry in accDict:
    strAcc.append({
        "name": entry["NAME"],
        "checked": False,
        "mandatory": entry["MANDATORY"],
        "option": False,
        "id": str(cnt_id),
        "rank": str(cnt_rank)
     })
    cnt_id += 1
    cnt_rank += 1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...