diff --git a/apps/node_man/tests/test_views/test_package_manage_views.py b/apps/node_man/tests/test_views/test_package_manage_views.py index 292c67023..611a161e8 100644 --- a/apps/node_man/tests/test_views/test_package_manage_views.py +++ b/apps/node_man/tests/test_views/test_package_manage_views.py @@ -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) @@ -70,7 +72,8 @@ 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) @@ -78,21 +81,21 @@ def test_list_with_filter_condition(self, *args, **kwargs): 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"}) @@ -133,6 +136,9 @@ 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() @@ -140,10 +146,12 @@ def test_destroy(self, *args, **kwargs): 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(