Skip to content

Commit 2497033

Browse files
committed
Improved test and fixed a small bug in create request
1 parent 3b96e45 commit 2497033

3 files changed

Lines changed: 157 additions & 28 deletions

File tree

pyatlan/client/common/oauth_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ def prepare_request(
202202
"""
203203
request = OAuthClientRequest(
204204
display_name=display_name,
205-
description=description,
205+
description=description or "",
206206
role=role,
207-
persona_qualified_names=persona_qualified_names,
207+
persona_qualified_names=persona_qualified_names or [],
208208
) # type: ignore[call-arg]
209209
return CREATE_OAUTH_CLIENT.format_path_with_params(), request
210210

tests/integration/aio/test_oauth_client.py

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# Copyright 2026 Atlan Pte. Ltd.
33
"""Async integration tests for OAuth client CRUD operations."""
44

5+
import asyncio
56
import time
6-
from typing import AsyncGenerator, Optional
7+
from typing import AsyncGenerator, List, Optional
78

89
import pytest
910
import pytest_asyncio
@@ -22,6 +23,10 @@
2223
OAUTH_CLIENT_ROLE = "Admin" # Role description
2324
DATA_ASSETS_PERSONA_NAME = "Data Assets" # Pre-existing persona
2425

26+
# Pagination test constants
27+
PAGINATION_CLIENT_COUNT = 5
28+
PAGINATION_CLIENT_NAME_PREFIX = f"{MODULE_NAME}_pagination_client"
29+
2530

2631
async def delete_oauth_client_async(client: AsyncAtlanClient, client_id: str) -> None:
2732
"""Helper to delete an OAuth client."""
@@ -40,6 +45,41 @@ async def persona_qualified_name(client: AsyncAtlanClient) -> str:
4045
return persona_qn
4146

4247

48+
@pytest_asyncio.fixture(scope="module")
49+
async def pagination_oauth_clients(
50+
client: AsyncAtlanClient,
51+
) -> AsyncGenerator[List[OAuthClientCreateResponse], None]:
52+
"""
53+
Fixture to create multiple OAuth clients for pagination testing.
54+
Creates 5 OAuth clients and yields their responses.
55+
Cleans up by deleting all created OAuth clients after tests.
56+
"""
57+
created_clients: List[OAuthClientCreateResponse] = []
58+
59+
# Create 5 OAuth clients for pagination testing
60+
for i in range(PAGINATION_CLIENT_COUNT):
61+
response = await client.oauth_client.create(
62+
name=f"{PAGINATION_CLIENT_NAME_PREFIX}_{i}",
63+
role=OAUTH_CLIENT_ROLE,
64+
description=f"Pagination test OAuth client {i}",
65+
)
66+
assert response is not None
67+
assert response.client_id is not None
68+
created_clients.append(response)
69+
# Small delay to ensure distinct createdAt timestamps for sorting
70+
await asyncio.sleep(0.5)
71+
72+
yield created_clients
73+
74+
# Cleanup: delete all created OAuth clients
75+
for oauth_client in created_clients:
76+
if oauth_client.client_id:
77+
try:
78+
await delete_oauth_client_async(client, oauth_client.client_id)
79+
except Exception:
80+
pass # Ignore cleanup errors
81+
82+
4383
@pytest_asyncio.fixture(scope="module")
4484
async def oauth_client_response(
4585
client: AsyncAtlanClient,
@@ -128,25 +168,50 @@ async def test_oauth_client_get_by_id(
128168
@pytest.mark.order(after="test_oauth_client_get_by_id")
129169
async def test_oauth_client_get_with_pagination(
130170
client: AsyncAtlanClient,
131-
oauth_client_response: OAuthClientCreateResponse,
132-
persona_qualified_name: str,
171+
pagination_oauth_clients: List[OAuthClientCreateResponse],
133172
):
134-
"""Test retrieving OAuth clients with pagination and async iteration."""
135-
assert oauth_client_response.client_id is not None
173+
"""Test retrieving OAuth clients with pagination and async iteration.
174+
175+
This test creates 5 OAuth clients and uses limit=1 to ensure
176+
the pagination logic is properly exercised across multiple API calls.
177+
"""
178+
# Verify we have the expected number of test clients
179+
assert len(pagination_oauth_clients) == PAGINATION_CLIENT_COUNT
180+
181+
# Get the client IDs we created for verification
182+
created_client_ids = {c.client_id for c in pagination_oauth_clients}
136183

137-
response = await client.oauth_client.get(limit=10, offset=0, sort="-createdAt")
184+
# Use limit=1 to force multiple API calls for pagination
185+
response = await client.oauth_client.get(limit=1, offset=0, sort="createdAt")
138186
assert response is not None
139187
assert response.total_record is not None
140-
assert response.total_record >= 1
188+
# Should have at least our 5 created clients
189+
assert response.total_record >= PAGINATION_CLIENT_COUNT
190+
191+
# Store the initial total record count
192+
initial_total = response.total_record
141193

142194
# Test async iteration over the paginated response
143-
found = False
195+
# This should make multiple API calls (one per page with limit=1)
196+
found_client_ids: set = set()
197+
total_iterated = 0
198+
144199
async for oauth_client in response:
145-
if oauth_client.client_id == oauth_client_response.client_id:
146-
found = True
147-
_assert_oauth_client(oauth_client, persona_qn=persona_qualified_name)
148-
break
149-
assert found, f"OAuth client {oauth_client_response.client_id} not found"
200+
total_iterated += 1
201+
if oauth_client.client_id in created_client_ids:
202+
found_client_ids.add(oauth_client.client_id)
203+
204+
# Verify we iterated through all records
205+
assert total_iterated == initial_total, (
206+
f"Expected to iterate through {initial_total} records, "
207+
f"but only iterated through {total_iterated}"
208+
)
209+
210+
# Verify we found all our created clients
211+
assert found_client_ids == created_client_ids, (
212+
f"Expected to find all {PAGINATION_CLIENT_COUNT} created clients. "
213+
f"Found: {len(found_client_ids)}, Missing: {created_client_ids - found_client_ids}"
214+
)
150215

151216

152217
@pytest.mark.order(after="test_oauth_client_get_with_pagination")

tests/integration/test_oauth_client.py

Lines changed: 77 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""Integration tests for OAuth client CRUD operations."""
44

55
import time
6-
from typing import Generator, Optional
6+
from typing import Generator, List, Optional
77

88
import pytest
99

@@ -21,6 +21,10 @@
2121
OAUTH_CLIENT_ROLE = "Admin" # Role description
2222
DATA_ASSETS_PERSONA_NAME = "Data Assets" # Pre-existing persona
2323

24+
# Pagination test constants
25+
PAGINATION_CLIENT_COUNT = 5
26+
PAGINATION_CLIENT_NAME_PREFIX = f"{MODULE_NAME}_pagination_client"
27+
2428

2529
def delete_oauth_client(client: AtlanClient, client_id: str) -> None:
2630
"""Helper to delete an OAuth client."""
@@ -39,6 +43,41 @@ def persona_qualified_name(client: AtlanClient) -> str:
3943
return persona_qn
4044

4145

46+
@pytest.fixture(scope="module")
47+
def pagination_oauth_clients(
48+
client: AtlanClient,
49+
) -> Generator[List[OAuthClientCreateResponse], None, None]:
50+
"""
51+
Fixture to create multiple OAuth clients for pagination testing.
52+
Creates 5 OAuth clients and yields their responses.
53+
Cleans up by deleting all created OAuth clients after tests.
54+
"""
55+
created_clients: List[OAuthClientCreateResponse] = []
56+
57+
# Create 5 OAuth clients for pagination testing
58+
for i in range(PAGINATION_CLIENT_COUNT):
59+
response = client.oauth_client.create(
60+
name=f"{PAGINATION_CLIENT_NAME_PREFIX}_{i}",
61+
role=OAUTH_CLIENT_ROLE,
62+
description=f"Pagination test OAuth client {i}",
63+
)
64+
assert response is not None
65+
assert response.client_id is not None
66+
created_clients.append(response)
67+
# Small delay to ensure distinct createdAt timestamps for sorting
68+
time.sleep(0.5)
69+
70+
yield created_clients
71+
72+
# Cleanup: delete all created OAuth clients
73+
for oauth_client in created_clients:
74+
if oauth_client.client_id:
75+
try:
76+
delete_oauth_client(client, oauth_client.client_id)
77+
except Exception:
78+
pass # Ignore cleanup errors
79+
80+
4281
@pytest.fixture(scope="module")
4382
def oauth_client_response(
4483
client: AtlanClient,
@@ -127,25 +166,50 @@ def test_oauth_client_get_by_id(
127166
@pytest.mark.order(after="test_oauth_client_get_by_id")
128167
def test_oauth_client_get_with_pagination(
129168
client: AtlanClient,
130-
oauth_client_response: OAuthClientCreateResponse,
131-
persona_qualified_name: str,
169+
pagination_oauth_clients: List[OAuthClientCreateResponse],
132170
):
133-
"""Test retrieving OAuth clients with pagination and iteration."""
134-
assert oauth_client_response.client_id is not None
171+
"""Test retrieving OAuth clients with pagination and iteration.
172+
173+
This test creates 5 OAuth clients and uses limit=1 to ensure
174+
the pagination logic is properly exercised across multiple API calls.
175+
"""
176+
# Verify we have the expected number of test clients
177+
assert len(pagination_oauth_clients) == PAGINATION_CLIENT_COUNT
178+
179+
# Get the client IDs we created for verification
180+
created_client_ids = {c.client_id for c in pagination_oauth_clients}
135181

136-
response = client.oauth_client.get(limit=10, offset=0, sort="createdAt")
182+
# Use limit=1 to force multiple API calls for pagination
183+
response = client.oauth_client.get(limit=1, offset=0, sort="createdAt")
137184
assert response is not None
138185
assert response.total_record is not None
139-
assert response.total_record >= 1
186+
# Should have at least our 5 created clients
187+
assert response.total_record >= PAGINATION_CLIENT_COUNT
188+
189+
# Store the initial total record count
190+
initial_total = response.total_record
140191

141192
# Test iterating over the paginated response
142-
found = False
193+
# This should make multiple API calls (one per page with limit=1)
194+
found_client_ids: set = set()
195+
total_iterated = 0
196+
143197
for oauth_client in response:
144-
if oauth_client.client_id == oauth_client_response.client_id:
145-
found = True
146-
_assert_oauth_client(oauth_client, persona_qn=persona_qualified_name)
147-
break
148-
assert found, f"OAuth client {oauth_client_response.client_id} not found"
198+
total_iterated += 1
199+
if oauth_client.client_id in created_client_ids:
200+
found_client_ids.add(oauth_client.client_id)
201+
202+
# Verify we iterated through all records
203+
assert total_iterated == initial_total, (
204+
f"Expected to iterate through {initial_total} records, "
205+
f"but only iterated through {total_iterated}"
206+
)
207+
208+
# Verify we found all our created clients
209+
assert found_client_ids == created_client_ids, (
210+
f"Expected to find all {PAGINATION_CLIENT_COUNT} created clients. "
211+
f"Found: {len(found_client_ids)}, Missing: {created_client_ids - found_client_ids}"
212+
)
149213

150214

151215
@pytest.mark.order(after="test_oauth_client_get_with_pagination")

0 commit comments

Comments
 (0)