Skip to content

Commit df9b31b

Browse files
authored
Merge branch 'development' into jorwoods/users_csv_import
2 parents 905fbca + 9b84601 commit df9b31b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

tableauserverclient/server/request_factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ def batch_create(self, element: ET.Element, tags: set[str], content: content_typ
924924
if item.id is None:
925925
raise ValueError(f"Item {item} must have an ID to be tagged.")
926926
content_element.attrib["id"] = item.id
927+
content_element.attrib["contentType"] = item.__class__.__name__.replace("Item", "")
927928

928929
return ET.tostring(element)
929930

test/test_tagging.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from contextlib import ExitStack
22
import re
33
from collections.abc import Iterable
4+
from typing import Optional, Protocol
45
import uuid
56
from 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+
201207
def 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

217231
def test_tags_batch_delete(get_server) -> None:

0 commit comments

Comments
 (0)