Skip to content

Commit 46f363f

Browse files
vchavatapallijacalata
authored andcommitted
Added response parsing
1 parent 58c3a25 commit 46f363f

File tree

7 files changed

+24
-18
lines changed

7 files changed

+24
-18
lines changed

samples/update_connections_auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def main():
4848
embed_password = args.embed_password.lower() == "true"
4949

5050
# Call unified update_connections method
51-
updated_ids = endpoint.update_connections(
51+
connection_items = endpoint.update_connections(
5252
resource,
5353
connection_luids=connection_luids,
5454
authentication_type=args.authentication_type,
@@ -57,7 +57,7 @@ def main():
5757
embed_password=embed_password,
5858
)
5959

60-
print(f"Updated connections on {args.resource_type} {args.resource_id}: {updated_ids}")
60+
print(f"Updated connections on {args.resource_type} {args.resource_id}: {connection_items}")
6161

6262

6363
if __name__ == "__main__":

tableauserverclient/server/endpoint/datasources_endpoint.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,12 @@ def update_connections(
422422
password=password,
423423
embed_password=embed_password,
424424
)
425-
response = self.put_request(url, request_body)
425+
server_response = self.put_request(url, request_body)
426+
connection_items = list(ConnectionItem.from_response(server_response.content, self.parent_srv.namespace))
427+
updated_ids = [conn.id for conn in connection_items]
426428

427-
logger.info(f"Updated connections for datasource {datasource_item.id}: {', '.join(connection_luids)}")
428-
return connection_luids
429+
logger.info(f"Updated connections for datasource {datasource_item.id}: {', '.join(updated_ids)}")
430+
return connection_items
429431

430432
@api(version="2.8")
431433
def refresh(self, datasource_item: Union[DatasourceItem, str], incremental: bool = False) -> JobItem:

tableauserverclient/server/endpoint/workbooks_endpoint.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,12 @@ def update_connections(
379379
)
380380

381381
# Send request
382-
response = self.put_request(url, request_body)
382+
server_response = self.put_request(url, request_body)
383+
connection_items = list(ConnectionItem.from_response(server_response.content, self.parent_srv.namespace))
384+
updated_ids = [conn.id for conn in connection_items]
383385

384-
logger.info(f"Updated connections for workbook {workbook_item.id}: {', '.join(connection_luids)}")
385-
return connection_luids
386+
logger.info(f"Updated connections for workbook {workbook_item.id}: {', '.join(updated_ids)}")
387+
return connection_items
386388

387389
# Download workbook contents with option of passing in filepath
388390
@api(version="2.0")
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<tsResponse xmlns="http://tableau.com/api"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.26.xsd">
4+
xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_25.xsd">
55
<connections>
66
<connection id="be786ae0-d2bf-4a4b-9b34-e2de8d2d4488"
77
type="sqlserver"
88
serverAddress="updated-server"
99
serverPort="1433"
1010
userName="user1"
1111
embedPassword="true"
12-
authentication="auth-keypair" />
12+
authenticationType="auth-keypair" />
1313
<connection id="a1b2c3d4-e5f6-7a8b-9c0d-123456789abc"
1414
type="sqlserver"
1515
serverAddress="updated-server"
1616
serverPort="1433"
1717
userName="user1"
1818
embedPassword="true"
19-
authentication="auth-keypair" />
19+
authenticationType="auth-keypair" />
2020
</connections>
2121
</tsResponse>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<tsResponse xmlns="http://tableau.com/api"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.26.xsd">
4+
xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_25.xsd">
55
<connections>
66
<connection id="abc12345-def6-7890-gh12-ijklmnopqrst"
77
type="sqlserver"
88
serverAddress="updated-db-host"
99
serverPort="1433"
1010
userName="svc-client"
1111
embedPassword="true"
12-
authentication="AD Service Principal" />
12+
authenticationType="AD Service Principal" />
1313
<connection id="1234abcd-5678-efgh-ijkl-0987654321mn"
1414
type="sqlserver"
1515
serverAddress="updated-db-host"
1616
serverPort="1433"
1717
userName="svc-client"
1818
embedPassword="true"
19-
authentication="AD Service Principal" />
19+
authenticationType="AD Service Principal" />
2020
</connections>
2121
</tsResponse>

test/test_datasource.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,17 @@ def test_update_connections(self) -> None:
183183
print("BASEURL:", self.server.baseurl)
184184
print("Calling PUT on:", f"{self.server.baseurl}/{datasource.id}/connections")
185185

186-
updated_luids = self.server.datasources.update_connections(
186+
connection_items = self.server.datasources.update_connections(
187187
datasource_item=datasource,
188188
connection_luids=connection_luids,
189189
authentication_type="auth-keypair",
190190
username="testuser",
191191
password="testpass",
192192
embed_password=True,
193193
)
194+
updated_ids = [conn.id for conn in connection_items]
194195

195-
self.assertEqual(updated_luids, connection_luids)
196+
self.assertEqual(updated_ids, connection_luids)
196197

197198
def test_populate_permissions(self) -> None:
198199
with open(asset(POPULATE_PERMISSIONS_XML), "rb") as f:

test/test_workbook.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,16 +728,17 @@ def test_update_workbook_connections(self) -> None:
728728
text=response_xml,
729729
)
730730

731-
updated_luids = self.server.workbooks.update_connections(
731+
connection_items = self.server.workbooks.update_connections(
732732
workbook_item=workbook,
733733
connection_luids=connection_luids,
734734
authentication_type="AD Service Principal",
735735
username="svc-client",
736736
password="secret-token",
737737
embed_password=True,
738738
)
739+
updated_ids = [conn.id for conn in connection_items]
739740

740-
self.assertEqual(updated_luids, connection_luids)
741+
self.assertEqual(updated_ids, connection_luids)
741742

742743
def test_get_workbook_all_fields(self) -> None:
743744
self.server.version = "3.21"

0 commit comments

Comments
 (0)