Skip to content

Commit 07f5f06

Browse files
committed
[test] Added integration test for AtlanClient.from_token_guid()
1 parent 224e094 commit 07f5f06

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pyatlan/client/atlan.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,9 @@ def from_token_guid(cls, guid: str) -> AtlanClient:
390390
# Step 3: Use Argo client to retrieve API token's credentials
391391
# Both endpoints require authentication, hence using the Argo token
392392
token_secret = temp_argo_client.impersonate.get_client_secret(client_guid=guid)
393-
token_client_id = temp_argo_client.token.get_by_guid(guid=guid).client_id
393+
token_client_id = temp_argo_client.token.get_by_guid( # type: ignore[union-attr]
394+
guid=guid
395+
).client_id
394396

395397
# Step 4: Exchange API token credentials for access token
396398
token_credentials = {

tests/integration/test_client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,37 @@ def test_client_401_token_refresh(
16181618
assert results and results.count >= 1
16191619

16201620

1621+
def test_client_init_from_token_guid(
1622+
client: AtlanClient, token: ApiToken, argo_fake_token: ApiToken, monkeypatch
1623+
):
1624+
# In real-world scenarios, these values come from environment variables
1625+
# configured at the Argo template level. The SDK uses these values to
1626+
# create a temporary client, which allows us to find the `client_id` and `client_secret`
1627+
# for the provided API token GUID, later used to initialize a client with its actual access token (API key) <- AtlanClient.from_token_guid()
1628+
assert argo_fake_token and argo_fake_token.guid
1629+
argo_client_secret = client.impersonate.get_client_secret(
1630+
client_guid=argo_fake_token.guid
1631+
)
1632+
monkeypatch.setenv("CLIENT_ID", argo_fake_token.client_id)
1633+
monkeypatch.setenv("CLIENT_SECRET", argo_client_secret)
1634+
1635+
# Ensure it's a valid API token
1636+
assert token and token.username and token.guid
1637+
assert "service-account" in token.username
1638+
token_client = AtlanClient.from_token_guid(guid=token.guid)
1639+
1640+
# Should be able to perform all operations
1641+
# with this client as long as it has the necessary permissions
1642+
results = (
1643+
FluentSearch()
1644+
.where(CompoundQuery.active_assets())
1645+
.where(CompoundQuery.asset_type(AtlasGlossary))
1646+
.page_size(100)
1647+
.execute(client=token_client)
1648+
)
1649+
assert results and results.count >= 1
1650+
1651+
16211652
def test_process_assets_when_no_assets_found(client: AtlanClient):
16221653
def should_never_be_called(_: Asset):
16231654
pytest.fail("Should not be called")

0 commit comments

Comments
 (0)