Rally API:如何移动测试文件夹

时间:2012-11-18 04:39:00

标签: ruby rally

我使用了以下答案中概述的脚本:

Rally APIs: How to copy Test Folder and member Test Cases

并且它很方便,但我真正想做的是整个测试文件夹移动到另一个项目中。通过Rally用户界面几乎不可能实现这一点。根据Rally支持,在UI中执行此操作的唯一方法是:

  • 从当前的测试文件夹取消测试用例
  • 在信息中心设置自定义网格应用
  • 使用自定义网格批量修改来更新测试用例的项目
  • 最后使用自定义网格批量修改来更新测试文件夹 - 现在您已进入测试用例的目标项目

即使上面的过程很笨重,现在也比以前在自定义网格中批量编辑出现之前更容易。在你必须逐个编辑每个测试用例之前,这是非常手动和缓慢的。

但是,我们需要移动几千个测试用例,而Custom Grid对我们来说有一个致命的缺陷。它只会显示查询中的前200条记录。因此,我们必须以逐步的方式手动更改网格查询,以完成我们需要的移动。这比逐个编辑测试用例要好得多。有没有办法使用脚本将测试用例从一个项目移动到另一个项目?请告诉我有。

1 个答案:

答案 0 :(得分:0)

以下脚本将执行此任务 - 它将所有测试用例从FormattedID标识的源测试文件夹移动到目标测试文件夹,也由FormattedID标识。源测试文件夹和目标测试文件夹可以位于不同的项目中(尽管它们必须位于同一工作区内)。与问题中引用的复制脚本一样,目标测试文件夹必须存在,即如果未找到目标,脚本将不会为您创建测试文件夹。

对于那些需要安装和配置Ruby REST Toolkit的人,链接在这里:

Developer Portal: Rally REST API for Ruby

Github

# Copyright 2002-2012 Rally Software Development Corp. All Rights Reserved.

require 'rally_api'

$my_base_url       = "https://rally1.rallydev.com/slm"
$my_username       = "user@company.com"
$my_password       = "password"
$my_workspace      = "My Workspace"
$my_project        = "My Project"
$wsapi_version     = "1.39"

# Test Folders
$source_test_folder_formatted_id = "TF8"
$target_test_folder_formatted_id = "TF11"

#==================== Make a connection to Rally ====================
config                  = {:base_url => $my_base_url}
config[:username]       = $my_username
config[:password]       = $my_password
config[:workspace]      = $my_workspace
config[:project]        = $my_project
config[:version]        = $wsapi_version

@rally = RallyAPI::RallyRestJson.new(config)

begin

  # Lookup source Test Folder
  source_test_folder_query = RallyAPI::RallyQuery.new()
  source_test_folder_query.type = :testfolder
  source_test_folder_query.fetch = true
  source_test_folder_query.query_string = "(FormattedID = \"" + $source_test_folder_formatted_id + "\")"

  source_test_folder_result = @rally.find(source_test_folder_query)

  # Lookup Target Test Folder
  target_test_folder_query = RallyAPI::RallyQuery.new()
  target_test_folder_query.type = :testfolder
  target_test_folder_query.fetch = true
  target_test_folder_query.query_string = "(FormattedID = \"" + $target_test_folder_formatted_id + "\")"

  target_test_folder_result = @rally.find(target_test_folder_query)

  if source_test_folder_result.total_result_count == 0
    puts "Source Test Folder: " + $source_test_folder_formatted_id + "not found. Exiting."
    exit
  end

  if target_test_folder_result.total_result_count == 0
    puts "Target Test Folder: " + $target_test_folder_formatted_id + "not found. Target must exist before moving."
    exit
  end

  source_test_folder = source_test_folder_result.first()
  target_test_folder = target_test_folder_result.first()

  # Populate full object for both Source and Target Test Folders
  full_source_test_folder = source_test_folder.read
  full_target_test_folder = target_test_folder.read

  # Grab collection of Source Test Cases
  source_test_cases = source_test_folder["TestCases"]

  # Loop through Source Test Cases and Move to Target
  source_test_cases.each do |source_test_case|
    begin

      test_case_to_update = source_test_case.read
      source_test_case_formatted_id = test_case_to_update["FormattedID"]

      target_project = full_target_test_folder["Project"]
      target_project_full_object = target_project.read
      target_project_name = target_project_full_object["Name"]

      source_project = full_source_test_folder["Project"]
      source_project_full_object = source_project.read
      source_project_name = source_project_full_object["Name"]

      puts "Source Project Name: #{source_project_name}"
      puts "Target Project Name: #{target_project_name}"

      # Test if the source project and target project are the same
      source_target_proj_match = source_project_name.eql?(target_project_name)

      # If the target Test Folder is in a different Project, we have to do some homework first:
      # "un-Test Folder" the project
      # Assign the Test Case to the Target Project
      # Assign the Test Case to the Target Test Folder
      if !source_target_proj_match then
        fields = {}
        fields["TestFolder"] = ""
        test_case_updated = @rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID
        puts "Test Case #{source_test_case_formatted_id} successfully dissociated from: #{$source_test_folder_formatted_id}"

        # Get full object on Target Project and assign Test Case to Target Project
        fields = {}
        fields["Project"] = target_project_full_object
        test_case_updated = @rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID
        puts "Test Case #{source_test_case_formatted_id} successfully assigned to Project: #{target_project_name}"
      end

      # Change the Test Folder attribute on the Test Case
      fields = {}
      fields["TestFolder"] = target_test_folder
      test_case_updated = @rally.update(:testcase, test_case_to_update.ObjectID, fields) #by ObjectID
      puts "Test Case #{source_test_case_formatted_id} successfully moved to #{$target_test_folder_formatted_id}"
    rescue => ex
      puts "Test Case #{source_test_case_formatted_id} not updated due to error"
      puts ex
    end
  end
end