Skip to content

Commit

Permalink
feature: 提供 Agent 包管理后台接口 (closed TencentBlueKing#1683)
Browse files Browse the repository at this point in the history
  • Loading branch information
ping15 committed Nov 23, 2023
1 parent 22f942c commit 5b33b0f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions apps/node_man/tests/test_views/test_package_manage_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def test_list_with_filter_condition(self, *args, **kwargs):
self.assertEqual(result["data"]["total"], 1)
self.assertEqual(len(result["data"]["list"]), 1)

gse_package = GsePackages.objects.first()

# 筛选tags
result = self.client.get(path="/api/agent/package/", data={"tags": "tag1"})
self.assertEqual(len(result["data"]["list"]), 1)
Expand All @@ -70,29 +72,30 @@ def test_list_with_filter_condition(self, *args, **kwargs):

# 筛选os_cpu_arch
os, cpu_arch = "linux", "x86_64"
result = self.client.get(path="/api/agent/package/", data={"os_cpu_arch": f"{os}_{cpu_arch}"})
result = self.client.get(path="/api/agent/package/",
data={"os_cpu_arch": f"{gse_package.os}_{gse_package.cpu_arch}"})
self.assertEqual(len(result["data"]["list"]), 1)
self.assertEqual(result["data"]["list"][0]["os"], os)
self.assertEqual(result["data"]["list"][0]["cpu_arch"], cpu_arch)
result = self.client.get(path="/api/agent/package/", data={"os_cpu_arch": "windows_x86_64"})
self.assertEqual(len(result["data"]["list"]), 0)

# 筛选created_by
result = self.client.get(path="/api/agent/package/", data={"created_by": "admin"})
result = self.client.get(path="/api/agent/package/", data={"created_by": gse_package.created_by})
self.assertEqual(len(result["data"]["list"]), 1)
self.assertEqual(result["data"]["list"][0]["created_by"], "admin")
result = self.client.get(path="/api/agent/package/", data={"created_by": "system"})
self.assertEqual(len(result["data"]["list"]), 0)

# 筛选is_ready
result = self.client.get(path="/api/agent/package/", data={"is_ready": "true"})
result = self.client.get(path="/api/agent/package/", data={"is_ready": str(gse_package.is_ready)})
self.assertEqual(len(result["data"]["list"]), 1)
self.assertEqual(result["data"]["list"][0]["is_ready"], True)
result = self.client.get(path="/api/agent/package/", data={"is_ready": "false"})
self.assertEqual(len(result["data"]["list"]), 0)

# 筛选version
result = self.client.get(path="/api/agent/package/", data={"version": "1.0.1"})
result = self.client.get(path="/api/agent/package/", data={"version": gse_package.version})
self.assertEqual(len(result["data"]["list"]), 1)
self.assertEqual(result["data"]["list"][0]["version"], "1.0.1")
result = self.client.get(path="/api/agent/package/", data={"version": "1.0.2"})
Expand Down Expand Up @@ -133,17 +136,22 @@ def test_update(self, *args, **kwargs):
self.client.put(path=f"/api/agent/package/{first_gse_package.id}/", data={"is_ready": False})
self.assertEqual(GsePackages.objects.first().is_ready, False)

# 测试更新不存在的id是否服务器异常
self.client.put(path=f"/api/agent/package/10000/", data={"is_ready": False})

@patch("apps.node_man.permissions.package_manage.PackageManagePermission.has_permission", return_value=True)
def test_destroy(self, *args, **kwargs):
gse_packages = GsePackages.objects.all()
self.assertEqual(len(gse_packages), 1)
self.client.delete(path=f"/api/agent/package/{gse_packages.first().id}/")
self.assertEqual(len(GsePackages.objects.all()), 0)

# 测试删除存在的id是否服务器异常
self.client.delete(path=f"/api/agent/package/10000/")

@patch("apps.node_man.permissions.package_manage.PackageManagePermission.has_permission", return_value=True)
def test_quick_search_condition(self, *args, **kwargs):
result = self.client.get(path="/api/agent/package/quick_search_condition/")
print(f"result2={result}")
for condition in result["data"]:
if condition["id"] == "os_cpu_arch":
self.assertCountEqual(
Expand Down

0 comments on commit 5b33b0f

Please sign in to comment.