diff --git a/apps/mock_data/views_mkd/job.py b/apps/mock_data/views_mkd/job.py index 1bf6b9806..8ee62b7dd 100644 --- a/apps/mock_data/views_mkd/job.py +++ b/apps/mock_data/views_mkd/job.py @@ -39,7 +39,7 @@ ], "retention": 1, } -# 因为MockClient中接口数据定义死了,如需调用使用深拷贝后update原数据 +# 因为MockClient中接口数据定义死了,如需调用使用,深拷贝后update原数据 JOB_REINSTALL_REQUEST_PARAMS = { "job_type": constants.JobType.REINSTALL_AGENT, "hosts": [ diff --git a/apps/node_man/tests/test_views/test_job_views.py b/apps/node_man/tests/test_views/test_job_views.py index 62783f3c8..0aa90bfaa 100644 --- a/apps/node_man/tests/test_views/test_job_views.py +++ b/apps/node_man/tests/test_views/test_job_views.py @@ -17,7 +17,7 @@ from apps.mock_data.common_unit import host from apps.mock_data.views_mkd import job from apps.node_man import constants -from apps.node_man.models import Host +from apps.node_man.models import Host, IdentityData from apps.node_man.tests.utils import MockClient, Subscription from apps.utils.unittest.testcase import CustomAPITestCase, MockSuperUserMixin @@ -107,13 +107,18 @@ def setUp(self) -> None: }, bk_host_id=14110, ) + identify_data = copy.deepcopy(host.IDENTITY_MODEL_DATA) + identify_data["bk_host_id"] = 14110 + IdentityData.objects.create(**identify_data) return super().setUp() - @patch("apps.node_man.periodic_tasks.sync_cmdb_host.client_v2", MockClient) @patch("apps.node_man.handlers.job.JobHandler.create_subscription", Subscription.create_subscription) + @patch("apps.node_man.periodic_tasks.sync_cmdb_host.client_v2", MockClient) def test_install(self): data = copy.deepcopy(job.JOB_REINSTALL_REQUEST_PARAMS) data["hosts"][0]["inner_ip"] = "2.1.2.52" + response = self.client.post(path="/api/job/install/", data=data) # 成功创建安装任务 self.assertEqual(response["result"], True) + self.assertEqual(type(response["data"]["job_id"]), int)