Skip to content

Commit e8890d6

Browse files
jorwoodsjacalata
andauthored
fix: datasource description update and publish (#1682)
* fix: datasource description update and publish Publish and update datasource were missing adding in the description to the XML. This PR adds it in. Co-authored-by: raccoooonz * ci: trigger * chore: test publish contains description --------- Co-authored-by: Jordan Woods <[email protected]> Co-authored-by: Jac <[email protected]>
1 parent 0f706c6 commit e8890d6

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

tableauserverclient/server/request_factory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ def _generate_xml(self, datasource_item: DatasourceItem, connection_credentials=
184184
project_element = ET.SubElement(datasource_element, "project")
185185
project_element.attrib["id"] = datasource_item.project_id
186186

187+
if datasource_item.description is not None:
188+
datasource_element.attrib["description"] = datasource_item.description
189+
187190
if connection_credentials is not None and connections is not None:
188191
raise RuntimeError("You cannot set both `connections` and `connection_credentials`")
189192

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

199-
def update_req(self, datasource_item):
202+
def update_req(self, datasource_item: DatasourceItem) -> bytes:
200203
xml_request = ET.Element("tsRequest")
201204
datasource_element = ET.SubElement(xml_request, "datasource")
202205
if datasource_item.name:
@@ -219,6 +222,8 @@ def update_req(self, datasource_item):
219222
datasource_element.attrib["certificationNote"] = str(datasource_item.certification_note)
220223
if datasource_item.encrypt_extracts is not None:
221224
datasource_element.attrib["encryptExtracts"] = str(datasource_item.encrypt_extracts).lower()
225+
if datasource_item.description is not None:
226+
datasource_element.attrib["description"] = datasource_item.description
222227

223228
return ET.tostring(xml_request)
224229

test/test_datasource.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,49 @@ def test_get_datasource_all_fields(server) -> None:
853853
assert datasources[0].owner.site_role == "SiteAdministratorCreator"
854854

855855

856+
def test_update_description(server: TSC.Server) -> None:
857+
response_xml = UPDATE_XML.read_text()
858+
with requests_mock.mock() as m:
859+
m.put(server.datasources.baseurl + "/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb", text=response_xml)
860+
single_datasource = TSC.DatasourceItem("1d0304cd-3796-429f-b815-7258370b9b74", "Sample datasource")
861+
single_datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794"
862+
single_datasource._content_url = "Sampledatasource"
863+
single_datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb"
864+
single_datasource.certified = True
865+
single_datasource.certification_note = "Warning, here be dragons."
866+
single_datasource.description = "Sample description"
867+
_ = server.datasources.update(single_datasource)
868+
869+
history = m.request_history[0]
870+
body = fromstring(history.body)
871+
ds_elem = body.find(".//datasource")
872+
assert ds_elem is not None
873+
assert ds_elem.attrib["description"] == "Sample description"
874+
875+
876+
def test_publish_description(server: TSC.Server) -> None:
877+
response_xml = PUBLISH_XML.read_text()
878+
with requests_mock.mock() as m:
879+
m.post(server.datasources.baseurl, text=response_xml)
880+
single_datasource = TSC.DatasourceItem("1d0304cd-3796-429f-b815-7258370b9b74", "Sample datasource")
881+
single_datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794"
882+
single_datasource._content_url = "Sampledatasource"
883+
single_datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb"
884+
single_datasource.certified = True
885+
single_datasource.certification_note = "Warning, here be dragons."
886+
single_datasource.description = "Sample description"
887+
_ = server.datasources.publish(single_datasource, TEST_ASSET_DIR / "SampleDS.tds", server.PublishMode.CreateNew)
888+
889+
history = m.request_history[0]
890+
boundary = history.body[: history.body.index(b"\r\n")].strip()
891+
parts = history.body.split(boundary)
892+
request_payload = next(part for part in parts if b"request_payload" in part)
893+
xml_payload = request_payload.strip().split(b"\r\n")[-1]
894+
body = fromstring(xml_payload)
895+
ds_elem = body.find(".//datasource")
896+
assert ds_elem is not None
897+
assert ds_elem.attrib["description"] == "Sample description"
898+
856899
def test_get_datasource_no_owner(server: TSC.Server) -> None:
857900
with requests_mock.mock() as m:
858901
m.get(server.datasources.baseurl, text=GET_NO_OWNER.read_text())

0 commit comments

Comments
 (0)