|
14 | 14 | _RecordCreate, |
15 | 15 | _RecordDelete, |
16 | 16 | _RecordGet, |
| 17 | + _RecordList, |
17 | 18 | _RecordUpdate, |
18 | 19 | _RecordUpsert, |
19 | 20 | _TableAddColumns, |
@@ -81,6 +82,9 @@ def _make_batch_client(): |
81 | 82 | method="POST", url="https://x/accounts/UpsertMultiple", body="{}", headers=None, content_id=None |
82 | 83 | ) |
83 | 84 | ) |
| 85 | + od._build_list = AsyncMock( |
| 86 | + return_value=MagicMock(method="GET", url="https://x/accounts", body=None, headers=None, content_id=None) |
| 87 | + ) |
84 | 88 | od._build_sql = AsyncMock( |
85 | 89 | return_value=MagicMock(method="GET", url="https://x/accounts?sql=...", body=None, headers=None, content_id=None) |
86 | 90 | ) |
@@ -270,6 +274,132 @@ async def test_single_get_request(self): |
270 | 274 | assert len(result) == 1 |
271 | 275 | od._build_get.assert_called_once_with("account", "guid-1", select=["name"], expand=None, include_annotations=None) |
272 | 276 |
|
| 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 | + |
273 | 403 |
|
274 | 404 | # --------------------------------------------------------------------------- |
275 | 405 | # _resolve_record_upsert() |
|
0 commit comments