Получение ошибки типа при создании цикла тестирования в JIRA в python - PullRequest
0 голосов
/ 21 февраля 2020

На моем компьютере установлена ​​локальная установка ядра Jira с установленными плагинами Zephyr и ZAPI.

Я пытаюсь создать новый цикл тестирования, используя приведенный ниже код, но получаю следующую ошибку

Может ли кто-нибудь любезно взглянуть на это и предложить, что должно быть сделано.

from urllib.request import Request, urlopen
from json import dumps, load
from base64 import b64encode

import requests

username = 'abc@xyz.com'
password = 'qwerty'
projectId = 10001
versionId = ''
testsToAdd = ["test-2", "test-2"]


newCycleValues = dumps({
    "clonedCycleId": "",
    "name": "TestCycle-1.1-1",
    "build": "",
    "environment": "",
    "description": "Created In ZAPI",
    "startDate": "",
    "endDate": "",
    "projectId": projectId,
    "versionId": versionId
})


baseURL = 'http://localhost:8080'
createCycleURL = baseURL + '/rest/zapi/latest/cycle'
addTestsToCycleURL = baseURL + '/rest/zapi/latest/execution/addTestsToCycle/'



headers = {"Authorization": "Basic" + b64encode(username + ":" + password), "Content-Type": "application/json"}


print ("Creating new cycle...")

req = Request(createCycleURL, data=newCycleValues, headers=headers)

js_res = urlopen(req)

objResponse = load(js_res)
newCycleId = objResponse['id']

print ("New Cycle Created!")

print ("Adding test(s) to newly created cycle... \n")

addTestValues = dumps({
    "issues": testsToAdd,
    "versionId": versionId,
    "cycleId": newCycleId,
    "projectId": projectId,
    "method": "1"
})

request = Request(addTestsToCycleURL, data=addTestValues, headers=headers)
httpResponse = urlopen(request).read()

print ("HTTP RESPONSE:\n" + httpResponse + "\n")
print ("Test addition completed! \nPlease check HTTP RESPONSE above for confirmation of addition or for failure conditions.")

Получение следующей ошибки, когда заголовок headers = {"Authorization": " Basic " + b64encode(username + ":" + password), "Content-Type": "application/json"}

C:\Users\1728\demo\Scripts\python.exe C:/Users/1728/PycharmProjects/demo/localinstallofjira/createTestCycle.py
Traceback (most recent call last):
  File "C:/Users/1728/PycharmProjects/demo/localinstallofjira/createTestCycle.py", line 41, in <module>
    headers = {"Authorization": "Basic" + b64encode(username + ":" + password), "Content-Type": "application/json"}
  File "C:\Users\1728\AppData\Local\Programs\Python\Python38\lib\base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'str'

Process finished with exit code 1

Получение следующей ошибки когда заголовок headers = {"Content-Type": "application/json"}

C:\Users\1728\demo\Scripts\python.exe C:/Users/1728/PycharmProjects/demo/localinstallofjira/createTestCycle.py
Traceback (most recent call last):
Creating new cycle...
  File "C:/Users/1728/PycharmProjects/demo/localinstallofjira/createTestCycle.py", line 51, in <module>
    js_res = urlopen(req)
  File "C:\Users\1728\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\1728\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 522, in open
    req = meth(req)
  File "C:\Users\1728\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 1248, in do_request_
    raise TypeError(msg)
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.

Process finished with exit code 1
...