Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tableauserverclient/server/request_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ def batch_create(self, element: ET.Element, tags: set[str], content: content_typ
if item.id is None:
raise ValueError(f"Item {item} must have an ID to be tagged.")
content_element.attrib["id"] = item.id
content_element.attrib["contentType"] = item.__class__.__name__.replace("Item", "")

return ET.tostring(element)

Expand Down
16 changes: 15 additions & 1 deletion test/test_tagging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from contextlib import ExitStack
import re
from collections.abc import Iterable
from typing import Optional, Protocol
import uuid
from xml.etree import ElementTree as ET

Expand Down Expand Up @@ -198,9 +199,14 @@ def test_update_tags(get_server, endpoint_type, item, tags) -> None:
endpoint.update_tags(item)


class HasID(Protocol):
@property
def id(self) -> Optional[str]: ...


def test_tags_batch_add(get_server) -> None:
server = get_server
content = [make_workbook(), make_view(), make_datasource(), make_table(), make_database()]
content: list[HasID] = [make_workbook(), make_view(), make_datasource(), make_table(), make_database()]
tags = ["a", "b"]
add_tags_xml = batch_add_tags_xml_response_factory(tags, content)
with requests_mock.mock() as m:
Expand All @@ -210,8 +216,16 @@ def test_tags_batch_add(get_server) -> None:
text=add_tags_xml,
)
tag_result = server.tags.batch_add(tags, content)
history = m.request_history

assert set(tag_result) == set(tags)
assert len(history) == 1
body = ET.fromstring(history[0].body)
id_types = {c.id: c.__class__.__name__.replace("Item", "") for c in content}
for tag in body.findall(".//content"):
content_type = tag.attrib.get("contentType", "")
content_id = tag.attrib.get("id", "")
assert content_type == id_types.get(content_id, ""), f"Content type mismatch for {content_id}"


def test_tags_batch_delete(get_server) -> None:
Expand Down
Loading