使用Pyral api

时间:2019-07-16 09:36:19

标签: python rest pyral

我用过吡咯api

rally = Rally(server, apikey=api_key, workspace=workspace, project=project)

连接到集会 比,

  testfolders = rally.get('TestFolder', fetch=True, query=query_criteria) 

我需要将集会中定义的所有测试用例提取为:

TF*****
  -TC1
  -TC2
  -TC3

我需要从从返回的formattedID中获取所有测试用例 测试文件夹。

for tc in testfolders:
   print(tc.Name)
   print(tc.FormattedID)# this represents the TF***
   tc_link=tc._ref#url for TC's https://rally1.rallydev.com/slm/webservice 
query_criteria = 'TestSets = "%s"' % tp_name
testfolders = rally.get('TestFolder', fetch=True, query=query_criteria)

我尝试寻找不同的组合集来提取测试用例 tc._ref实际上是

https://rally1.rallydev.com/slm/webservice/v2.0/TestFolder/XXXXX/TestCases

当我尝试在浏览器中打开它时,它会给出整个测试用例列表。 我需要提取那些测试用例列表。 我尝试使用urllib访问以使用python访问数据,但是说未经授权的访问,我认为如果我在同一会话中,授权问题就不会成为问题,因为rally对象已经实例化了。 任何帮助,将不胜感激! 预先感谢

    rally = Rally(server, apikey=api_key, workspace=workspace, project=project)
    tp_name = "specific test case "
    query_criteria = 'FormattedID = "%s"' % tp_name
    testfolders = rally.get('TestFolder', fetch=True, query=query_criteria)
    for tc in testfolders:
         print(tc.Name)
         print(tc.FormattedID)   
         query_criteria = 'TestSets = "%s"' % tc._ref
         response = rally.get('TestCase', fetch=True, query=query_criteria)
         print(response)

422 Could not read: could not read all instances of class com.f4tech.slm.domain.TestCase for class TestCase

1 个答案:

答案 0 :(得分:0)

目前尚不清楚您要实现的目标,但是请看下面的代码。可能会解决您的问题:

query = 'FormattedID = %s'

test_folder_req = rally.get('TestFolder', fetch=True, projectScopeDown=True,
                                       query=query % folder_id) # folder_id == "TF111"
if test_folder_req.resultCount == 0:
    print('Rally returned nothing for folder: %s', folder_id)
    sys.exit(1)

test_folder = test_folder_req.next()

test_cases = test_folder.TestCases
print('Start working with %s' % folder_id)
print('Test Folder %s contains %s TestCases' % (folder_id, len(test_cases)))

for test_case in test_cases:
    print(test_case.FormattedID)
    print(test_case.Name)