11from  contextlib  import  ExitStack 
22import  re 
33from  collections .abc  import  Iterable 
4+ from  typing  import  Optional , Protocol 
45import  uuid 
56from  xml .etree  import  ElementTree  as  ET 
67
@@ -198,9 +199,14 @@ def test_update_tags(get_server, endpoint_type, item, tags) -> None:
198199        endpoint .update_tags (item )
199200
200201
202+ class  HasID (Protocol ):
203+     @property  
204+     def  id (self ) ->  Optional [str ]: ...
205+ 
206+ 
201207def  test_tags_batch_add (get_server ) ->  None :
202208    server  =  get_server 
203-     content  =  [make_workbook (), make_view (), make_datasource (), make_table (), make_database ()]
209+     content :  list [ HasID ]  =  [make_workbook (), make_view (), make_datasource (), make_table (), make_database ()]
204210    tags  =  ["a" , "b" ]
205211    add_tags_xml  =  batch_add_tags_xml_response_factory (tags , content )
206212    with  requests_mock .mock () as  m :
@@ -210,8 +216,16 @@ def test_tags_batch_add(get_server) -> None:
210216            text = add_tags_xml ,
211217        )
212218        tag_result  =  server .tags .batch_add (tags , content )
219+         history  =  m .request_history 
213220
214221    assert  set (tag_result ) ==  set (tags )
222+     assert  len (history ) ==  1 
223+     body  =  ET .fromstring (history [0 ].body )
224+     id_types  =  {c .id : c .__class__ .__name__ .replace ("Item" , "" ) for  c  in  content }
225+     for  tag  in  body .findall (".//content" ):
226+         content_type  =  tag .attrib .get ("contentType" , "" )
227+         content_id  =  tag .attrib .get ("id" , "" )
228+         assert  content_type  ==  id_types .get (content_id , "" ), f"Content type mismatch for { content_id }  
215229
216230
217231def  test_tags_batch_delete (get_server ) ->  None :
0 commit comments