Skip to content

Commit 767cdee

Browse files
committed
[tests] Use token_client (retry=0) to avoid extra token generation
1 parent 020033d commit 767cdee

7 files changed

Lines changed: 53 additions & 38 deletions

File tree

tests/integration/aio/conftest.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from pyatlan.model.atlan_image import AtlanImage
1515
from pyatlan.model.enums import AtlanConnectorType, AtlanTagColor, CertificateStatus
1616
from pyatlan.model.typedef import AtlanTagDef
17+
from pyatlan.client.atlan import DEFAULT_RETRY
1718
from tests.integration.aio.test_connection import create_connection_async
1819
from tests.integration.aio.utils import delete_asset_async
1920
from tests.integration.client import TestId
@@ -36,6 +37,13 @@ async def client():
3637
client = AsyncAtlanClient()
3738
yield client
3839

40+
@pytest_asyncio.fixture(scope="module")
41+
async def token_client():
42+
"""Async Atlan client fixture for api token integration tests."""
43+
DEFAULT_RETRY.total = 0
44+
client = AsyncAtlanClient(retry=DEFAULT_RETRY)
45+
yield client
46+
3947

4048
@pytest_asyncio.fixture(scope="module")
4149
async def connection(client: AsyncAtlanClient) -> AsyncGenerator[Connection, None]:

tests/integration/aio/test_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,34 +77,34 @@ async def current_user(client: AsyncAtlanClient) -> UserMinimalResponse:
7777

7878

7979
@pytest_asyncio.fixture(scope="module")
80-
async def token(client: AsyncAtlanClient) -> AsyncGenerator[ApiToken, None]:
80+
async def token(token_client: AsyncAtlanClient) -> AsyncGenerator[ApiToken, None]:
8181
token = None
8282
try:
83-
token = await create_token_async(client, MODULE_NAME)
83+
token = await create_token_async(token_client, MODULE_NAME)
8484
yield token
8585
finally:
86-
await delete_token_async(client, token)
86+
await delete_token_async(token_client, token)
8787

8888

8989
@pytest_asyncio.fixture(scope="module")
90-
async def expired_token(client: AsyncAtlanClient) -> AsyncGenerator[ApiToken, None]:
90+
async def expired_token(token_client: AsyncAtlanClient) -> AsyncGenerator[ApiToken, None]:
9191
token = None
9292
try:
93-
token = await client.token.create(f"{MODULE_NAME}-expired", validity_seconds=1)
93+
token = await token_client.token.create(f"{MODULE_NAME}-expired", validity_seconds=1)
9494
time.sleep(5)
9595
yield token
9696
finally:
97-
await delete_token_async(client, token)
97+
await delete_token_async(token_client, token)
9898

9999

100100
@pytest_asyncio.fixture(scope="module")
101-
async def argo_fake_token(client: AsyncAtlanClient) -> AsyncGenerator[ApiToken, None]:
101+
async def argo_fake_token(token_client: AsyncAtlanClient) -> AsyncGenerator[ApiToken, None]:
102102
token = None
103103
try:
104-
token = await client.token.create(f"{MODULE_NAME}-fake-argo")
104+
token = await token_client.token.create(f"{MODULE_NAME}-fake-argo")
105105
yield token
106106
finally:
107-
await delete_token_async(client, token)
107+
await delete_token_async(token_client, token)
108108

109109

110110
@pytest_asyncio.fixture(scope="module")

tests/integration/aio/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@
1919
LOGGER = logging.getLogger(__name__)
2020

2121

22-
async def create_token_async(client: AsyncAtlanClient, name: str) -> ApiToken:
22+
async def create_token_async(token_client: AsyncAtlanClient, name: str) -> ApiToken:
2323
"""Create an API token asynchronously."""
24-
token = await client.token.create(name)
24+
token = await token_client.token.create(name)
2525
return token
2626

2727

2828
async def delete_token_async(
29-
client: AsyncAtlanClient, token: Optional[ApiToken] = None
29+
token_client: AsyncAtlanClient, token: Optional[ApiToken] = None
3030
):
3131
"""Delete an API token asynchronously."""
3232
# If there is a partial failure on the server side
3333
# and the token is still visible in the Atlan UI,
3434
# in that case, the create method may not return a token.
3535
# We should retrieve the list of all tokens and delete them here.
3636
if not token:
37-
tokens_response = await client.token.get()
37+
tokens_response = await token_client.token.get()
3838
tokens = tokens_response.records
3939
assert tokens
4040
delete_tokens = [
@@ -44,11 +44,11 @@ async def delete_token_async(
4444
]
4545
for token in delete_tokens:
4646
assert token and token.guid
47-
await client.token.purge(token.guid)
47+
await token_client.token.purge(token.guid)
4848
return
4949
# In case of no partial failure, directly delete the token
5050
if token.guid:
51-
await client.token.purge(token.guid)
51+
await token_client.token.purge(token.guid)
5252

5353

5454
async def delete_asset_async(

tests/integration/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pyatlan.client.atlan import AtlanClient
99
from pyatlan.model.enums import AtlanDeleteType
1010
from pyatlan.model.response import A
11+
from pyatlan.client.atlan import DEFAULT_RETRY
1112

1213
LOGGER = logging.getLogger(__name__)
1314

@@ -31,6 +32,12 @@ def client() -> Generator[AtlanClient, None, None]:
3132

3233
yield client
3334

35+
@pytest.fixture(scope="module")
36+
def token_client() -> Generator[AtlanClient, None, None]:
37+
DEFAULT_RETRY.total = 0
38+
client = AtlanClient(retry=DEFAULT_RETRY)
39+
yield client
40+
3441

3542
def delete_asset(
3643
client: AtlanClient,

tests/integration/purpose_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ def snowflake_column_qn(snowflake_conn):
4848

4949

5050
@pytest.fixture(scope="module")
51-
def token(client: AtlanClient) -> Generator[ApiToken, None, None]:
51+
def token(token_client: AtlanClient) -> Generator[ApiToken, None, None]:
5252
token = None
5353
try:
54-
token = client.token.create(API_TOKEN_NAME)
54+
token = token_client.token.create(API_TOKEN_NAME)
5555
assert token
5656
assert token.guid
5757
assert token.display_name
5858
# After creating the token, assign it to the
5959
# "Data Assets" persona to grant it query access
60-
persona = client.asset.find_personas_by_name(PERSONA_NAME)[0]
60+
persona = token_client.asset.find_personas_by_name(PERSONA_NAME)[0]
6161
assert persona.qualified_name
62-
client.token.update(
62+
token_client.token.update(
6363
guid=token.guid,
6464
display_name=token.display_name,
6565
personas={persona.qualified_name},
@@ -68,7 +68,7 @@ def token(client: AtlanClient) -> Generator[ApiToken, None, None]:
6868
# its associated personas -- will leave that to later...
6969
yield token
7070
finally:
71-
delete_token(client, token)
71+
delete_token(token_client, token)
7272

7373

7474
@pytest.fixture(scope="module")

tests/integration/requests_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
API_TOKEN_NAME = f"{MODULE_NAME}"
1111

1212

13-
def create_token(client: AtlanClient, name: str) -> ApiToken:
14-
t = client.token.create(name)
13+
def create_token(token_client: AtlanClient, name: str) -> ApiToken:
14+
t = token_client.token.create(name)
1515
return t
1616

1717

18-
def delete_token(client: AtlanClient, token: Optional[ApiToken] = None):
18+
def delete_token(token_client: AtlanClient, token: Optional[ApiToken] = None):
1919
# If there is a partial failure on the server side
2020
# and the token is still visible in the Atlan UI,
2121
# in that case, the create method may not return a token.
2222
# We should retrieve the list of all tokens and delete them here.
2323
if not token:
24-
tokens = client.token.get().records
24+
tokens = token_client.token.get().records
2525
assert tokens
2626
delete_tokens = [
2727
token
@@ -30,20 +30,20 @@ def delete_token(client: AtlanClient, token: Optional[ApiToken] = None):
3030
]
3131
for token in delete_tokens:
3232
assert token and token.guid
33-
client.token.purge(token.guid)
33+
token_client.token.purge(token.guid)
3434
return
3535
# In case of no partial failure, directly delete the token
36-
token.guid and client.token.purge(token.guid)
36+
token.guid and token_client.token.purge(token.guid)
3737

3838

3939
@pytest.fixture(scope="module")
40-
def token(client: AtlanClient) -> Generator[ApiToken, None, None]:
40+
def token(token_client: AtlanClient) -> Generator[ApiToken, None, None]:
4141
token = None
4242
try:
43-
token = create_token(client, API_TOKEN_NAME)
43+
token = create_token(token_client, API_TOKEN_NAME)
4444
yield token
4545
finally:
46-
delete_token(client, token)
46+
delete_token(token_client, token)
4747

4848

4949
def test_create_token(client: AtlanClient, token: ApiToken):

tests/integration/test_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,34 +66,34 @@
6666

6767

6868
@pytest.fixture(scope="module")
69-
def token(client: AtlanClient) -> Generator[ApiToken, None, None]:
69+
def token(token_client: AtlanClient) -> Generator[ApiToken, None, None]:
7070
token = None
7171
try:
72-
token = create_token(client, MODULE_NAME)
72+
token = create_token(token_client, MODULE_NAME)
7373
yield token
7474
finally:
75-
delete_token(client, token)
75+
delete_token(token_client, token)
7676

7777

7878
@pytest.fixture(scope="module")
79-
def expired_token(client: AtlanClient) -> Generator[ApiToken, None, None]:
79+
def expired_token(token_client: AtlanClient) -> Generator[ApiToken, None, None]:
8080
token = None
8181
try:
82-
token = client.token.create(f"{MODULE_NAME}-expired", validity_seconds=1)
82+
token = token_client.token.create(f"{MODULE_NAME}-expired", validity_seconds=1)
8383
time.sleep(5)
8484
yield token
8585
finally:
86-
delete_token(client, token)
86+
delete_token(token_client, token)
8787

8888

8989
@pytest.fixture(scope="module")
90-
def argo_fake_token(client: AtlanClient) -> Generator[ApiToken, None, None]:
90+
def argo_fake_token(token_client: AtlanClient) -> Generator[ApiToken, None, None]:
9191
token = None
9292
try:
93-
token = client.token.create(f"{MODULE_NAME}-fake-argo")
93+
token = token_client.token.create(f"{MODULE_NAME}-fake-argo")
9494
yield token
9595
finally:
96-
delete_token(client, token)
96+
delete_token(token_client, token)
9797

9898

9999
@pytest.fixture(scope="module")

0 commit comments

Comments
 (0)