python 用于从TestRail和Jira检索信息的Python脚本。需要在jira_testrail_cfg.py中定义凭据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 用于从TestRail和Jira检索信息的Python脚本。需要在jira_testrail_cfg.py中定义凭据相关的知识,希望对你有一定的参考价值。
import requests
import json
import pprint
from jira_testrail_cfg import *
test_rail_url_root = 'https://testrail.devfactory.com/index.php?/api/v2/'
test_rail_get_case = 'get_case/'
jira_url_root = 'https://jira.devfactory.com/rest/api/latest'
jira_issue_path = '/issue/'
jira_proj = 'VIEWSCID'
# HTTP Request Headers
headers = {'content-type': 'application/json'}
def get_testrail_status(tr_case_id):
tr_js = requests.get(
test_rail_url_root + test_rail_get_case + tr_case_id,
auth=(test_rail_usr, test_rail_pwd), headers=headers).json()
case_id = str(tr_js['id'])
case_title = tr_js['title']
result = ''
if tr_js['custom_tc_status'] == 3:
result = ('Approved for Automation')
if tr_js['custom_tc_status'] == 5:
result = ('Automated')
if tr_js['custom_tc_status'] == 7:
result = ('Automation in progress')
if tr_js['custom_tc_status'] == 9:
result = ('Approved for Testing')
return result
def get_jira(tr_case_id):
pp = pprint.PrettyPrinter(indent=2)
jira_url = 'https://jira.devfactory.com/rest/api/2/search?fields=key,summary,status' + \
'&jql=project=%s AND type = "Integration Test" AND summary ~ "C%s"' % (jira_proj, tr_case_id)
result = requests.get(jira_url, auth=(jira_usr, jira_pwd)).json()
tr_status = get_testrail_status(tr_case_id)
tr_status_fmt = '%-10s # %-25s @ '
if len(result['issues']) > 0:
print(tr_status_fmt % ( tr_case_id, tr_status) +
'%-20s -> %s' % (result['issues'][0]['key'], result['issues'][0]['fields']['status']['name']))
else:
print(tr_status_fmt % ( tr_case_id, tr_status))
return
def str_var_empty(var):
if len(var) == 0:
return True
else:
return False
def check_cfg():
try:
if str_var_empty(test_rail_usr) or \
str_var_empty(test_rail_pwd) or \
str_var_empty(jira_usr) or \
str_var_empty(jira_pwd):
raise NameError()
except NameError:
print('Missing credential. '+
'Please make sure following var properly defined in jira_testrail_cfg.py: \n' +
'test_rail_usr, test_rail_pwd, jira_usr, jira_pwd')
return False
return True
def main():
if not check_cfg():
return
print('Input cases:')
tcase = ''
tr_cases = []
while(True):
tcase = input()
if len(tcase) == 0:
break
if tcase.isdigit():
tr_cases.append(tcase)
else:
print('Input in incorrect format: %s' % tcase)
return False
print('Processing started...')
for case_id in tr_cases:
get_jira(case_id)
return
if __name__ == '__main__':
main()
以上是关于python 用于从TestRail和Jira检索信息的Python脚本。需要在jira_testrail_cfg.py中定义凭据的主要内容,如果未能解决你的问题,请参考以下文章
在TestRail中更新TestCafe脚本执行状态(已通过/未通过)
如何将 Selenium Testng (java) 与 Testrail 测试用例集成
注释/获取/映射 Testrail 测试用例 ID 到本地 Java TestNG 测试(Jenkins Test Rail Integration)
用于错误跟踪和客户支持的 Jira?
使用 SED 命令检索 JSON 对象键值
利用ElasticSearch和Redis检索和存储十亿信息