Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 6 additions & 1 deletion tableauserverclient/server/request_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def _generate_xml(self, datasource_item: DatasourceItem, connection_credentials=
project_element = ET.SubElement(datasource_element, "project")
project_element.attrib["id"] = datasource_item.project_id

if datasource_item.description is not None:
datasource_element.attrib["description"] = datasource_item.description

if connection_credentials is not None and connections is not None:
raise RuntimeError("You cannot set both `connections` and `connection_credentials`")

Expand All @@ -196,7 +199,7 @@ def _generate_xml(self, datasource_item: DatasourceItem, connection_credentials=
_add_connections_element(connections_element, connection)
return ET.tostring(xml_request)

def update_req(self, datasource_item):
def update_req(self, datasource_item: DatasourceItem) -> bytes:
xml_request = ET.Element("tsRequest")
datasource_element = ET.SubElement(xml_request, "datasource")
if datasource_item.name:
Expand All @@ -219,6 +222,8 @@ def update_req(self, datasource_item):
datasource_element.attrib["certificationNote"] = str(datasource_item.certification_note)
if datasource_item.encrypt_extracts is not None:
datasource_element.attrib["encryptExtracts"] = str(datasource_item.encrypt_extracts).lower()
if datasource_item.description is not None:
datasource_element.attrib["description"] = datasource_item.description

return ET.tostring(xml_request)

Expand Down
44 changes: 44 additions & 0 deletions test/test_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,47 @@ def test_get_datasource_all_fields(server) -> None:
assert datasources[0].owner.last_login == parse_datetime("2025-02-04T06:39:20Z")
assert datasources[0].owner.name == "[email protected]"
assert datasources[0].owner.site_role == "SiteAdministratorCreator"


def test_update_description(server: TSC.Server) -> None:
response_xml = UPDATE_XML.read_text()
with requests_mock.mock() as m:
m.put(server.datasources.baseurl + "/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb", text=response_xml)
single_datasource = TSC.DatasourceItem("1d0304cd-3796-429f-b815-7258370b9b74", "Sample datasource")
single_datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794"
single_datasource._content_url = "Sampledatasource"
single_datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb"
single_datasource.certified = True
single_datasource.certification_note = "Warning, here be dragons."
single_datasource.description = "Sample description"
_ = server.datasources.update(single_datasource)

history = m.request_history[0]
body = fromstring(history.body)
ds_elem = body.find(".//datasource")
assert ds_elem is not None
assert ds_elem.attrib["description"] == "Sample description"


def test_publish_description(server: TSC.Server) -> None:
response_xml = PUBLISH_XML.read_text()
with requests_mock.mock() as m:
m.post(server.datasources.baseurl, text=response_xml)
single_datasource = TSC.DatasourceItem("1d0304cd-3796-429f-b815-7258370b9b74", "Sample datasource")
single_datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794"
single_datasource._content_url = "Sampledatasource"
single_datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb"
single_datasource.certified = True
single_datasource.certification_note = "Warning, here be dragons."
single_datasource.description = "Sample description"
_ = server.datasources.publish(single_datasource, TEST_ASSET_DIR / "SampleDS.tds", server.PublishMode.CreateNew)

history = m.request_history[0]
boundary = history.body[: history.body.index(b"\r\n")].strip()
parts = history.body.split(boundary)
request_payload = next(part for part in parts if b"request_payload" in part)
xml_payload = request_payload.strip().split(b"\r\n")[-1]
body = fromstring(xml_payload)
ds_elem = body.find(".//datasource")
assert ds_elem is not None
assert ds_elem.attrib["description"] == "Sample description"
Loading