我需要删除我在集会中的几个测试用例。 Rally网站说,解决这个问题的唯一方法是与Rally API进行通信并编写一个小的批量删除脚本。
E.g。我需要从TC100 - TC150中删除。
任何人都可以帮我这个吗?我正在使用java。
感谢。
答案 0 :(得分:0)
每Rally Rest toolkit for Java个文档有一个Delete方法。
下面是一个代码示例,它通过标记名称查询测试用例,然后批量删除这些测试用例。您的查询条件会有所不同,但如果您选择按标记标识测试用例,请注意Tags.Name contains "tag1"
会返回可能应用了多个标记的测试用例,而不仅仅是那些单个" tag1&# 34。
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.response.QueryResponse;
import com.rallydev.rest.request.DeleteRequest;
import com.rallydev.rest.response.DeleteResponse;
import com.rallydev.rest.util.Fetch;
import com.rallydev.rest.util.QueryFilter;
import java.net.URI;
public class GetTestCasesByTagAndBulkDelete {
public static void main(String[] args) throws Exception {
String host = "https://rally1.rallydev.com";
String apiKey = "_abc123"; //use your api key
String applicationName = "Find TestCases by Tag and bulk delete";
String workspaceRef = "/workspace/12345";
RallyRestApi restApi = null;
try {
restApi = new RallyRestApi(new URI(host),apiKey);
restApi.setApplicationName(applicationName);
QueryRequest request = new QueryRequest("TestCase");
request.setWorkspace(workspaceRef);
request.setFetch(new Fetch(new String[] {"Name", "FormattedID", "Tags"}));
request.setLimit(1000);
request.setScopedDown(false);
request.setScopedUp(false);
request.setQueryFilter(new QueryFilter("Tags.Name", "contains", "\"tag1\""));
QueryResponse response = restApi.query(request);
System.out.println("Successful: " + response.wasSuccessful());
System.out.println("Results Size: " + response.getResults().size());
for (int i=0; i<response.getResults().size();i++){
JsonObject tcJsonObject = response.getResults().get(i).getAsJsonObject();
System.out.println("Name: " + tcJsonObject.get("Name") + " FormattedID: " + tcJsonObject.get("FormattedID"));
int numberOfTags = tcJsonObject.getAsJsonObject("Tags").get("Count").getAsInt();
QueryRequest tagRequest = new QueryRequest(tcJsonObject.getAsJsonObject("Tags"));
tagRequest.setFetch(new Fetch("Name","FormattedID"));
//load the collection
JsonArray tags = restApi.query(tagRequest).getResults();
for (int j=0;j<numberOfTags;j++){
System.out.println("Tag Name: " + tags.get(j).getAsJsonObject().get("Name"));
}
System.out.println("deleting " + tcJsonObject.get("FormattedID")) ;
DeleteRequest deleteRequest = new DeleteRequest(tcJsonObject.get("_ref").getAsString());
DeleteResponse deleteResponse = restApi.delete(deleteRequest);
}
} finally {
if (restApi != null) {
restApi.close();
}
}
}
}