Skip to content

Commit 0571bf8

Browse files
vchavatapalliclaude
authored andcommitted
Add tests for optional authentication_type and fix argparse defaults
- Remove unnecessary default=None from argparse arguments (implicit for optional args) - Add test_update_connections_without_auth_type for datasources - Add test_update_workbook_connections_without_auth_type for workbooks - Tests verify that auth_type is preserved from server response when not specified These tests ensure the optional authentication_type parameter works correctly and that existing authentication types are preserved when updating only credentials without changing auth type. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 2a6e274 commit 0571bf8

3 files changed

Lines changed: 77 additions & 3 deletions

File tree

samples/update_connections_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def main():
2222
# Resource-specific
2323
parser.add_argument("resource_type", choices=["workbook", "datasource"])
2424
parser.add_argument("resource_id")
25-
parser.add_argument("--datasource_username", default=None, help="Datasource username (optional)")
26-
parser.add_argument("--authentication_type", default=None, help="Authentication type (optional)")
27-
parser.add_argument("--datasource_password", default=None, help="Datasource password (optional)")
25+
parser.add_argument("--datasource_username", help="Datasource username (optional)")
26+
parser.add_argument("--authentication_type", help="Authentication type (optional)")
27+
parser.add_argument("--datasource_password", help="Datasource password (optional)")
2828
parser.add_argument(
2929
"--embed_password", default="true", choices=["true", "false"], help="Embed password (default: true)"
3030
)

test/test_datasource.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,44 @@ def test_update_connections(server) -> None:
277277
assert "auth-keypair" == connection_items[0].auth_type
278278

279279

280+
def test_update_connections_without_auth_type(server) -> None:
281+
"""Test that update_connections works when authentication_type is not provided."""
282+
populate_xml = POPULATE_CONNECTIONS_XML.read_text()
283+
response_xml = UPDATE_CONNECTIONS_NO_AUTH_XML.read_text()
284+
285+
with requests_mock.Mocker() as m:
286+
287+
datasource_id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb"
288+
connection_luids = ["be786ae0-d2bf-4a4b-9b34-e2de8d2d4488", "a1b2c3d4-e5f6-7a8b-9c0d-123456789abc"]
289+
290+
datasource = TSC.DatasourceItem(datasource_id)
291+
datasource._id = "9dbd2263-16b5-46e1-9c43-a76bb8ab65fb"
292+
datasource.owner_id = "dd2239f6-ddf1-4107-981a-4cf94e415794"
293+
server.version = "3.26"
294+
295+
m.get(
296+
"http://test/api/3.26/sites/dad65087-b08b-4603-af4e-2887b8aafc67/datasources/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb/connections",
297+
text=populate_xml,
298+
)
299+
m.put(
300+
"http://test/api/3.26/sites/dad65087-b08b-4603-af4e-2887b8aafc67/datasources/9dbd2263-16b5-46e1-9c43-a76bb8ab65fb/connections",
301+
text=response_xml,
302+
)
303+
304+
# Update connections without specifying authentication_type
305+
connection_items = server.datasources.update_connections(
306+
datasource_item=datasource,
307+
connection_luids=connection_luids,
308+
username="user1",
309+
embed_password=True,
310+
)
311+
updated_ids = [conn.id for conn in connection_items]
312+
313+
assert updated_ids == connection_luids
314+
# Verify that the auth type from the response is preserved (UsernamePassword)
315+
assert connection_items[0].auth_type == "UsernamePassword"
316+
317+
280318
def test_populate_permissions(server) -> None:
281319
response_xml = POPULATE_PERMISSIONS_XML.read_text()
282320
with requests_mock.mock() as m:

test/test_workbook.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,42 @@ def test_update_workbook_connections(server: TSC.Server) -> None:
10481048
assert "AD Service Principal" == connection_items[0].auth_type
10491049

10501050

1051+
def test_update_workbook_connections_without_auth_type(server: TSC.Server) -> None:
1052+
"""Test that update_connections works when authentication_type is not provided."""
1053+
populate_xml = POPULATE_CONNECTIONS_XML.read_text()
1054+
response_xml = UPDATE_CONNECTIONS_NO_AUTH_XML.read_text()
1055+
1056+
with requests_mock.Mocker() as m:
1057+
workbook_id = "1a2b3c4d-5e6f-7a8b-9c0d-112233445566"
1058+
connection_luids = ["abc12345-def6-7890-gh12-ijklmnopqrst", "1234abcd-5678-efgh-ijkl-0987654321mn"]
1059+
1060+
workbook = TSC.WorkbookItem(workbook_id)
1061+
workbook._id = workbook_id
1062+
server.version = "3.26"
1063+
url = f"{server.baseurl}/{workbook_id}/connections"
1064+
m.get(
1065+
"http://test/api/3.26/sites/dad65087-b08b-4603-af4e-2887b8aafc67/workbooks/1a2b3c4d-5e6f-7a8b-9c0d-112233445566/connections",
1066+
text=populate_xml,
1067+
)
1068+
m.put(
1069+
"http://test/api/3.26/sites/dad65087-b08b-4603-af4e-2887b8aafc67/workbooks/1a2b3c4d-5e6f-7a8b-9c0d-112233445566/connections",
1070+
text=response_xml,
1071+
)
1072+
1073+
# Update connections without specifying authentication_type
1074+
connection_items = server.workbooks.update_connections(
1075+
workbook_item=workbook,
1076+
connection_luids=connection_luids,
1077+
username="user1",
1078+
embed_password=True,
1079+
)
1080+
updated_ids = [conn.id for conn in connection_items]
1081+
1082+
assert updated_ids == connection_luids
1083+
# Verify that the auth type from the response is preserved (UsernamePassword)
1084+
assert connection_items[0].auth_type == "UsernamePassword"
1085+
1086+
10511087
def test_get_workbook_all_fields(server: TSC.Server) -> None:
10521088
server.version = "3.21"
10531089
baseurl = server.workbooks.baseurl

0 commit comments

Comments
 (0)