From 234e9afd3b97cc9907b923d1f8750880a70430a8 Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Thu, 1 Jun 2023 09:30:50 +0800 Subject: [PATCH] rest api testing --- test/restapi/api_case_test.go | 4 +++- test/restapi/api_module_test.go | 18 ++++++++++++++++++ test/restapi/api_suite_test.go | 18 ++++++++++++++++++ test/restapi/api_task_test.go | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/test/restapi/api_case_test.go b/test/restapi/api_case_test.go index a05dd04a..b60fc24a 100644 --- a/test/restapi/api_case_test.go +++ b/test/restapi/api_case_test.go @@ -47,7 +47,9 @@ func (s *CaseApiSuite) TestCaseListByModuleApi(t provider.T) { t.ID("7635") token := httpHelper.Login() - url := zentaoHelper.GenApiUrl(fmt.Sprintf("/products/%d/testcases?module=%d", config.ProductId, config.ModuleId), + moduleId := getModuleMinId() + + url := zentaoHelper.GenApiUrl(fmt.Sprintf("/products/%d/testcases?module=%d", config.ProductId, moduleId), nil, constTestHelper.ZentaoSiteUrl) bodyBytes, _ := httpHelper.Get(url, token) diff --git a/test/restapi/api_module_test.go b/test/restapi/api_module_test.go index 2d9a8ef5..4b0d969f 100644 --- a/test/restapi/api_module_test.go +++ b/test/restapi/api_module_test.go @@ -36,3 +36,21 @@ func (s *ModuleApiSuite) TestModuleListForCaseApi(t provider.T) { t.Require().Greater(firstModuleId, int64(0), "list modules failed") } + +func getModuleMinId() (id int64) { + token := httpHelper.Login() + + url := zentaoHelper.GenApiUrl(fmt.Sprintf("modules?type=case&id=%d", config.ProductId), nil, constTestHelper.ZentaoSiteUrl) + + bodyBytes, _ := httpHelper.Get(url, token) + + modules := gjson.Get(string(bodyBytes), "modules").Array() + for _, item := range modules { + itemId := item.Get("id").Int() + if id == 0 || (itemId > 0 && id > itemId) { + id = itemId + } + } + + return +} diff --git a/test/restapi/api_suite_test.go b/test/restapi/api_suite_test.go index 0676a17d..55ca0dc0 100644 --- a/test/restapi/api_suite_test.go +++ b/test/restapi/api_suite_test.go @@ -49,3 +49,21 @@ func (s *SuiteApiSuite) TestSuiteDetailApi(t provider.T) { t.Require().Greater(len(name), 0, "get testsuite failed") } + +func getSuiteMinId() (id int64) { + token := httpHelper.Login() + + url := zentaoHelper.GenApiUrl(fmt.Sprintf("products/%d/testsuites", config.ProductId), nil, constTestHelper.ZentaoSiteUrl) + + bodyBytes, _ := httpHelper.Get(url, token) + + suites := gjson.Get(string(bodyBytes), "testsuites").Array() + for _, suite := range suites { + suiteId := suite.Get("id").Int() + if id == 0 || (suiteId > 0 && id > suiteId) { + id = suiteId + } + } + + return +} diff --git a/test/restapi/api_task_test.go b/test/restapi/api_task_test.go index bd88aeda..c3b74966 100644 --- a/test/restapi/api_task_test.go +++ b/test/restapi/api_task_test.go @@ -64,3 +64,21 @@ func getLatestTaskId(token string) (id int) { return } + +func getTaskMinId() (id int64) { + token := httpHelper.Login() + + url := zentaoHelper.GenApiUrl(fmt.Sprintf("testtasks?product=%d", config.ProductId), nil, constTestHelper.ZentaoSiteUrl) + + bodyBytes, _ := httpHelper.Get(url, token) + + tasks := gjson.Get(string(bodyBytes), "testtasks").Array() + for _, task := range tasks { + taskId := task.Get("id").Int() + if id == 0 || (taskId > 0 && id > taskId) { + id = taskId + } + } + + return +} -- GitLab