|
36 | 36 | AssetCollectionResponse, |
37 | 37 | AssetEventResponse, |
38 | 38 | AssetResponse, |
| 39 | + AssetStateStoreCollectionResponse, |
| 40 | + AssetStateStoreResponse, |
39 | 41 | BackfillCollectionResponse, |
40 | 42 | BackfillPostBody, |
41 | 43 | BackfillResponse, |
@@ -321,7 +323,11 @@ class TestAssetsOperations: |
321 | 323 | queued_events=[asset_queued_event_response], |
322 | 324 | total_entries=1, |
323 | 325 | ) |
324 | | - |
| 326 | + asset_state_store_response = AssetStateStoreResponse( |
| 327 | + key="my_key", |
| 328 | + value={"my_val": 0}, # type: ignore[arg-type] |
| 329 | + updated_at=datetime.datetime(2025, 1, 1, 0, 0, 0), |
| 330 | + ) |
325 | 331 | dag_run_response = DAGRunResponse( |
326 | 332 | dag_display_name=dag_id, |
327 | 333 | dag_run_id=dag_id, |
@@ -513,6 +519,73 @@ def handle_request(request: httpx.Request) -> httpx.Response: |
513 | 519 | response = client.assets.delete_queued_event(dag_id=self.dag_id, asset_id=self.asset_id) |
514 | 520 | assert response == self.asset_id |
515 | 521 |
|
| 522 | + def test_list_state_store(self): |
| 523 | + collection_response = AssetStateStoreCollectionResponse( |
| 524 | + asset_state_store=[self.asset_state_store_response], |
| 525 | + total_entries=1, |
| 526 | + ) |
| 527 | + |
| 528 | + def handle_request(request: httpx.Request) -> httpx.Response: |
| 529 | + assert request.url.path == f"/api/v2/assets/{self.asset_id}/state-store" |
| 530 | + return httpx.Response(200, json=json.loads(collection_response.model_dump_json())) |
| 531 | + |
| 532 | + client = make_api_client(transport=httpx.MockTransport(handle_request)) |
| 533 | + response = client.assets.list_state_store(self.asset_id) |
| 534 | + assert response == collection_response |
| 535 | + |
| 536 | + def test_get_state_store(self): |
| 537 | + key = self.asset_state_store_response.key |
| 538 | + |
| 539 | + def handle_request(request: httpx.Request) -> httpx.Response: |
| 540 | + assert request.url.path == f"/api/v2/assets/{self.asset_id}/state-store/{key}" |
| 541 | + return httpx.Response(200, json=json.loads(self.asset_state_store_response.model_dump_json())) |
| 542 | + |
| 543 | + client = make_api_client(transport=httpx.MockTransport(handle_request)) |
| 544 | + response = client.assets.get_state_store(self.asset_id, key) |
| 545 | + assert response == self.asset_state_store_response |
| 546 | + |
| 547 | + @pytest.mark.parametrize( |
| 548 | + ("value", "expected"), |
| 549 | + [ |
| 550 | + ('{"index": 0}', {"index": 0}), |
| 551 | + ("hello", "hello"), |
| 552 | + ], |
| 553 | + ) |
| 554 | + def test_set_state_store(self, value, expected): |
| 555 | + key = self.asset_state_store_response.key |
| 556 | + |
| 557 | + def handle_request(request: httpx.Request) -> httpx.Response: |
| 558 | + assert request.method == "PUT" |
| 559 | + assert request.url.path == f"/api/v2/assets/{self.asset_id}/state-store/{key}" |
| 560 | + assert json.loads(request.content) == {"value": expected} |
| 561 | + return httpx.Response(204) |
| 562 | + |
| 563 | + client = make_api_client(transport=httpx.MockTransport(handle_request)) |
| 564 | + response = client.assets.set_state_store(self.asset_id, key, value) |
| 565 | + assert response == key |
| 566 | + |
| 567 | + def test_delete_state_store(self): |
| 568 | + key = self.asset_state_store_response.key |
| 569 | + |
| 570 | + def handle_request(request: httpx.Request) -> httpx.Response: |
| 571 | + assert request.method == "DELETE" |
| 572 | + assert request.url.path == f"/api/v2/assets/{self.asset_id}/state-store/{key}" |
| 573 | + return httpx.Response(204) |
| 574 | + |
| 575 | + client = make_api_client(transport=httpx.MockTransport(handle_request)) |
| 576 | + response = client.assets.delete_state_store(self.asset_id, key) |
| 577 | + assert response == key |
| 578 | + |
| 579 | + def test_clear_state_store(self): |
| 580 | + def handle_request(request: httpx.Request) -> httpx.Response: |
| 581 | + assert request.method == "DELETE" |
| 582 | + assert request.url.path == f"/api/v2/assets/{self.asset_id}/state-store" |
| 583 | + return httpx.Response(204) |
| 584 | + |
| 585 | + client = make_api_client(transport=httpx.MockTransport(handle_request)) |
| 586 | + response = client.assets.clear_state_store(self.asset_id) |
| 587 | + assert response == self.asset_id |
| 588 | + |
516 | 589 |
|
517 | 590 | class TestBackfillOperations: |
518 | 591 | backfill_id: NonNegativeInt = 1 |
|
0 commit comments