@@ -71,80 +71,5 @@ def test_list_tags_for_resources_request_body_fields(self):
7171 self .assertEqual (second ["Key" ], "k2" )
7272 self .assertEqual (second ["Values" ], ["v3" ])
7373
74- @patch ("volcengine.tls.TLSService.TLSService._TLSService__request" )
75- def test_list_tags_for_resources_service_call_basic (self , mock_request ):
76- """测试基础场景下 TLSService.list_tags_for_resources 的调用"""
77- # 构造模拟 HTTP 响应
78- mock_response = Mock ()
79- mock_response .headers = {
80- "X-Tls-Requestid" : "test-request-id" ,
81- "Content-Type" : "application/json" ,
82- }
83- mock_response .text = '{"ResourceTags": [], "nextToken": ""}'
84- mock_request .return_value = mock_response
85-
86- request = ListTagsForResourcesRequest (
87- resource_type = "project" ,
88- resources_ids = ["project-123" ],
89- )
90-
91- response = self .tls_service .list_tags_for_resources (request )
92-
93- # 验证底层 __request 调用参数
94- mock_request .assert_called_once_with (
95- api = "/ListTagsForResources" ,
96- body = {
97- "ResourceType" : "project" ,
98- "ResourcesIds" : ["project-123" ],
99- },
100- )
101-
102- # 验证响应类型与字段解析
103- self .assertIsInstance (response , ListTagsForResourcesResponse )
104- self .assertIsInstance (response .get_resource_tags (), list )
105- self .assertIsInstance (response .get_next_token (), str )
106-
107- @patch ("volcengine.tls.TLSService.TLSService._TLSService__request" )
108- def test_list_tags_for_resources_with_tag_filters_and_pagination (self , mock_request ):
109- """测试携带 TagFilters 与分页参数时的调用与请求体结构"""
110- mock_response = Mock ()
111- mock_response .headers = {
112- "X-Tls-Requestid" : "test-request-id" ,
113- "Content-Type" : "application/json" ,
114- }
115- mock_response .text = '{"ResourceTags": [], "nextToken": "cursor-next"}'
116- mock_request .return_value = mock_response
117-
118- request = ListTagsForResourcesRequest (
119- resource_type = "topic" ,
120- resources_ids = ["topic-1" ],
121- tag_filters = [{"key" : "env" , "values" : ["test" ]}],
122- max_results = 10 ,
123- next_token = "cursor-1" ,
124- )
125-
126- body = request .get_api_input ()
127- response = self .tls_service .list_tags_for_resources (request )
128-
129- # 顶层字段
130- self .assertEqual (body ["ResourceType" ], "topic" )
131- self .assertEqual (body ["ResourcesIds" ], ["topic-1" ])
132- self .assertEqual (body ["MaxResults" ], 10 )
133- self .assertEqual (body ["NextToken" ], "cursor-1" )
134-
135- # TagFilters 结构
136- self .assertIn ("TagFilters" , body )
137- self .assertEqual (len (body ["TagFilters" ]), 1 )
138- self .assertEqual (body ["TagFilters" ][0 ]["Key" ], "env" )
139- self .assertEqual (body ["TagFilters" ][0 ]["Values" ], ["test" ])
140-
141- # __request 调用体中也应携带规范化后的 TagFilters
142- mock_request .assert_called_once_with (api = "/ListTagsForResources" , body = body )
143-
144- # 响应解析
145- self .assertIsInstance (response , ListTagsForResourcesResponse )
146- self .assertEqual (response .get_next_token (), "cursor-next" )
147-
148-
14974if __name__ == "__main__" : # pragma: no cover
15075 unittest .main ()
0 commit comments