Skip to content

Commit bc75250

Browse files
vchavatapallijorwoods
authored andcommitted
New APIs: Update multiple connections in a single workbook/datasource (#1638)
Update multiple connections in a single workbook - Takes multiple connection, authType and credentials as input Update multiple connections in a single datasource - Takes multiple connection, authType and credentials as input --------- Co-authored-by: Jordan Woods <13803242+jorwoods@users.noreply.github.com>
1 parent b6880a3 commit bc75250

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

samples/update_connection_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def main():
5151
connection = connections[0]
5252
connection.username = args.datasource_username
5353
connection.password = args.datasource_password
54-
connection.auth_type = args.authentication_type
54+
connection.authentication_type = args.authentication_type
5555
connection.embed_password = True
5656

5757
updated_connection = update_function(resource, connection)

test/test_datasource.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,44 @@ def test_update_copy_fields(server) -> None:
157157
assert single_datasource._project_name == updated_datasource._project_name
158158

159159

160+
def test_update_connections(self) -> None:
161+
populate_xml, response_xml = read_xml_assets(POPULATE_CONNECTIONS_XML, UPDATE_CONNECTIONS_XML)
162+
163+
with requests_mock.Mocker() as m:
164+
165+
datasource_id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb"
166+
connection_luids = ["be786ae0-d2bf-4a4b-9b34-e2de8d2d4488", "a1b2c3d4-e5f6-7a8b-9c0d-123456789abc"]
167+
168+
datasource = TSC.DatasourceItem(datasource_id)
169+
datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb"
170+
datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794"
171+
self.server.version = "3.26"
172+
173+
url = f"{self.server.baseurl}/{datasource.id}/connections"
174+
m.get(
175+
"http://test/api/3.26/sites/dad65087-b08b-4603-af4e-2887b8aafc67/datasources/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb/connections",
176+
text=populate_xml,
177+
)
178+
m.put(
179+
"http://test/api/3.26/sites/dad65087-b08b-4603-af4e-2887b8aafc67/datasources/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb/connections",
180+
text=response_xml,
181+
)
182+
183+
print("BASEURL:", self.server.baseurl)
184+
print("Calling PUT on:", f"{self.server.baseurl}/{datasource.id}/connections")
185+
186+
connection_items = self.server.datasources.update_connections(
187+
datasource_item=datasource,
188+
connection_luids=connection_luids,
189+
authentication_type="auth-keypair",
190+
username="testuser",
191+
password="testpass",
192+
embed_password=True,
193+
)
194+
updated_ids = [conn.id for conn in connection_items]
195+
196+
self.assertEqual(updated_ids, connection_luids)
197+
160198
def test_update_connections(self) -> None:
161199
populate_xml, response_xml = read_xml_assets(POPULATE_CONNECTIONS_XML, UPDATE_CONNECTIONS_XML)
162200

test/test_workbook.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,38 @@ def test_publish_with_thumbnails_user_id(server: TSC.Server) -> None:
708708
assert re.search(b'thumbnailsUserId=\\"ee8c6e70-43b6-11e6-af4f-f7b0d8e20761\\"', request_body)
709709

710710

711+
def test_update_workbook_connections(self) -> None:
712+
populate_xml, response_xml = read_xml_assets(POPULATE_CONNECTIONS_XML, UPDATE_CONNECTIONS_XML)
713+
714+
with requests_mock.Mocker() as m:
715+
workbook_id = "1a2b3c4d-5e6f-7a8b-9c0d-112233445566"
716+
connection_luids = ["abc12345-def6-7890-gh12-ijklmnopqrst", "1234abcd-5678-efgh-ijkl-0987654321mn"]
717+
718+
workbook = TSC.WorkbookItem(workbook_id)
719+
workbook._id = workbook_id
720+
self.server.version = "3.26"
721+
url = f"{self.server.baseurl}/{workbook_id}/connections"
722+
m.get(
723+
"http://test/api/3.26/sites/dad65087-b08b-4603-af4e-2887b8aafc67/workbooks/1a2b3c4d-5e6f-7a8b-9c0d-112233445566/connections",
724+
text=populate_xml,
725+
)
726+
m.put(
727+
"http://test/api/3.26/sites/dad65087-b08b-4603-af4e-2887b8aafc67/workbooks/1a2b3c4d-5e6f-7a8b-9c0d-112233445566/connections",
728+
text=response_xml,
729+
)
730+
731+
connection_items = self.server.workbooks.update_connections(
732+
workbook_item=workbook,
733+
connection_luids=connection_luids,
734+
authentication_type="AD Service Principal",
735+
username="svc-client",
736+
password="secret-token",
737+
embed_password=True,
738+
)
739+
updated_ids = [conn.id for conn in connection_items]
740+
741+
self.assertEqual(updated_ids, connection_luids)
742+
711743
def test_update_workbook_connections(self) -> None:
712744
populate_xml, response_xml = read_xml_assets(POPULATE_CONNECTIONS_XML, UPDATE_CONNECTIONS_XML)
713745

0 commit comments

Comments
 (0)