Skip to content

Commit 74739ef

Browse files
Abel Milashclaude
andcommitted
Add unit tests for async retrieve, list, list_pages, and batch _RecordList
- TestAsyncRecordRetrieve (11 tests): return type, all params forwarded, 404 → None, non-404 re-raised, ValueError re-raised, no DeprecationWarning, record.id and record.table set correctly - TestAsyncRecordList (15 tests): QueryResult return, multi-page collection, all query params forwarded, FilterExpression → str conversion, to_dataframe(), no DeprecationWarning - TestAsyncRecordListPages (12 tests): async generator type, QueryResult per page, page contents, all params forwarded, no DeprecationWarning - TestResolveRecordGet: 3 new tests covering expand, include_annotations, and combined forwarding to _build_get - TestResolveRecordList (11 tests): dispatch, all _RecordList fields forwarded to _build_list - Add _build_list AsyncMock to _make_batch_client() helper - Add _RecordList import to test file Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6c8ec45 commit 74739ef

2 files changed

Lines changed: 475 additions & 2 deletions

File tree

tests/unit/aio/data/test_async_batch_internal.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
_RecordCreate,
1515
_RecordDelete,
1616
_RecordGet,
17+
_RecordList,
1718
_RecordUpdate,
1819
_RecordUpsert,
1920
_TableAddColumns,
@@ -81,6 +82,9 @@ def _make_batch_client():
8182
method="POST", url="https://x/accounts/UpsertMultiple", body="{}", headers=None, content_id=None
8283
)
8384
)
85+
od._build_list = AsyncMock(
86+
return_value=MagicMock(method="GET", url="https://x/accounts", body=None, headers=None, content_id=None)
87+
)
8488
od._build_sql = AsyncMock(
8589
return_value=MagicMock(method="GET", url="https://x/accounts?sql=...", body=None, headers=None, content_id=None)
8690
)
@@ -270,6 +274,132 @@ async def test_single_get_request(self):
270274
assert len(result) == 1
271275
od._build_get.assert_called_once_with("account", "guid-1", select=["name"], expand=None, include_annotations=None)
272276

277+
async def test_passes_expand_to_build_get(self):
278+
"""expand= is forwarded from _RecordGet to _build_get."""
279+
client, od = _make_batch_client()
280+
op = _RecordGet(table="account", record_id="guid-1", expand=["primarycontactid"])
281+
await client._resolve_record_get(op)
282+
od._build_get.assert_called_once_with(
283+
"account", "guid-1", select=None, expand=["primarycontactid"], include_annotations=None
284+
)
285+
286+
async def test_passes_include_annotations_to_build_get(self):
287+
"""include_annotations= is forwarded from _RecordGet to _build_get."""
288+
client, od = _make_batch_client()
289+
annotation = "OData.Community.Display.V1.FormattedValue"
290+
op = _RecordGet(table="account", record_id="guid-1", include_annotations=annotation)
291+
await client._resolve_record_get(op)
292+
od._build_get.assert_called_once_with(
293+
"account", "guid-1", select=None, expand=None, include_annotations=annotation
294+
)
295+
296+
async def test_passes_all_params_to_build_get(self):
297+
"""All _RecordGet fields are forwarded together to _build_get."""
298+
client, od = _make_batch_client()
299+
annotation = "OData.Community.Display.V1.FormattedValue"
300+
op = _RecordGet(
301+
table="account",
302+
record_id="guid-1",
303+
select=["name"],
304+
expand=["primarycontactid"],
305+
include_annotations=annotation,
306+
)
307+
result = await client._resolve_record_get(op)
308+
assert len(result) == 1
309+
od._build_get.assert_called_once_with(
310+
"account", "guid-1", select=["name"], expand=["primarycontactid"], include_annotations=annotation
311+
)
312+
313+
314+
# ---------------------------------------------------------------------------
315+
# _resolve_record_list()
316+
# ---------------------------------------------------------------------------
317+
318+
319+
class TestResolveRecordList:
320+
"""Tests for _resolve_record_list() intent-to-request translation."""
321+
322+
async def test_produces_one_request(self):
323+
"""A _RecordList op produces exactly one _build_list request."""
324+
client, od = _make_batch_client()
325+
op = _RecordList(table="account")
326+
result = await client._resolve_record_list(op)
327+
assert len(result) == 1
328+
od._build_list.assert_called_once()
329+
330+
async def test_passes_table_to_build_list(self):
331+
"""The table name is forwarded to _build_list as first positional arg."""
332+
client, od = _make_batch_client()
333+
op = _RecordList(table="contact")
334+
await client._resolve_record_list(op)
335+
call_args = od._build_list.call_args
336+
assert call_args[0][0] == "contact"
337+
338+
async def test_passes_filter(self):
339+
"""filter= is forwarded from _RecordList to _build_list."""
340+
client, od = _make_batch_client()
341+
op = _RecordList(table="account", filter="statecode eq 0")
342+
await client._resolve_record_list(op)
343+
assert od._build_list.call_args[1]["filter"] == "statecode eq 0"
344+
345+
async def test_passes_select(self):
346+
"""select= is forwarded from _RecordList to _build_list."""
347+
client, od = _make_batch_client()
348+
op = _RecordList(table="account", select=["name", "revenue"])
349+
await client._resolve_record_list(op)
350+
assert od._build_list.call_args[1]["select"] == ["name", "revenue"]
351+
352+
async def test_passes_top(self):
353+
"""top= is forwarded from _RecordList to _build_list."""
354+
client, od = _make_batch_client()
355+
op = _RecordList(table="account", top=50)
356+
await client._resolve_record_list(op)
357+
assert od._build_list.call_args[1]["top"] == 50
358+
359+
async def test_passes_orderby(self):
360+
"""orderby= is forwarded from _RecordList to _build_list."""
361+
client, od = _make_batch_client()
362+
op = _RecordList(table="account", orderby=["name asc"])
363+
await client._resolve_record_list(op)
364+
assert od._build_list.call_args[1]["orderby"] == ["name asc"]
365+
366+
async def test_passes_expand(self):
367+
"""expand= is forwarded from _RecordList to _build_list."""
368+
client, od = _make_batch_client()
369+
op = _RecordList(table="account", expand=["primarycontactid"])
370+
await client._resolve_record_list(op)
371+
assert od._build_list.call_args[1]["expand"] == ["primarycontactid"]
372+
373+
async def test_passes_page_size(self):
374+
"""page_size= is forwarded from _RecordList to _build_list."""
375+
client, od = _make_batch_client()
376+
op = _RecordList(table="account", page_size=200)
377+
await client._resolve_record_list(op)
378+
assert od._build_list.call_args[1]["page_size"] == 200
379+
380+
async def test_passes_count(self):
381+
"""count=True is forwarded from _RecordList to _build_list."""
382+
client, od = _make_batch_client()
383+
op = _RecordList(table="account", count=True)
384+
await client._resolve_record_list(op)
385+
assert od._build_list.call_args[1]["count"] is True
386+
387+
async def test_passes_include_annotations(self):
388+
"""include_annotations= is forwarded from _RecordList to _build_list."""
389+
client, od = _make_batch_client()
390+
annotation = "OData.Community.Display.V1.FormattedValue"
391+
op = _RecordList(table="account", include_annotations=annotation)
392+
await client._resolve_record_list(op)
393+
assert od._build_list.call_args[1]["include_annotations"] == annotation
394+
395+
async def test_resolve_item_dispatch(self):
396+
"""_resolve_item dispatches _RecordList correctly."""
397+
client, od = _make_batch_client()
398+
op = _RecordList(table="account", filter="statecode eq 0")
399+
result = await client._resolve_item(op)
400+
assert len(result) == 1
401+
od._build_list.assert_called_once()
402+
273403

274404
# ---------------------------------------------------------------------------
275405
# _resolve_record_upsert()

0 commit comments

Comments
 (0)