(self, dynamodb_client, streams_client, stream_table)
| 575 | """Inserts, updates, deletes generating INSERT/MODIFY/REMOVE events.""" |
| 576 | |
| 577 | def test_insert_modify_remove_events(self, dynamodb_client, streams_client, stream_table): |
| 578 | table_name, stream_arn = stream_table |
| 579 | pk = f"mixed-{uuid.uuid4().hex[:8]}" |
| 580 | |
| 581 | # INSERT |
| 582 | dynamodb_client.put_item( |
| 583 | TableName=table_name, |
| 584 | Item={"pk": {"S": pk}, "val": {"N": "1"}}, |
| 585 | ) |
| 586 | # MODIFY |
| 587 | dynamodb_client.update_item( |
| 588 | TableName=table_name, |
| 589 | Key={"pk": {"S": pk}}, |
| 590 | UpdateExpression="SET val = :v", |
| 591 | ExpressionAttributeValues={":v": {"N": "2"}}, |
| 592 | ) |
| 593 | # REMOVE |
| 594 | dynamodb_client.delete_item( |
| 595 | TableName=table_name, |
| 596 | Key={"pk": {"S": pk}}, |
| 597 | ) |
| 598 | |
| 599 | # Poll until we have all 3 events for this pk. |
| 600 | deadline = time.monotonic() + 5.0 |
| 601 | our_records: list[dict] = [] |
| 602 | while time.monotonic() < deadline: |
| 603 | records = _drain_all_shards(streams_client, stream_arn, "TRIM_HORIZON") |
| 604 | our_records = [ |
| 605 | r for r in records |
| 606 | if r["dynamodb"]["Keys"]["pk"]["S"] == pk |
| 607 | ] |
| 608 | if len(our_records) >= 3: |
| 609 | break |
| 610 | time.sleep(_poll_interval()) |
| 611 | |
| 612 | events = [r["eventName"] for r in our_records] |
| 613 | assert events == ["INSERT", "MODIFY", "REMOVE"], ( |
| 614 | f"Expected [INSERT, MODIFY, REMOVE], got {events}" |
| 615 | ) |
| 616 | |
| 617 | # Verify images. |
| 618 | insert_rec = our_records[0] |
| 619 | assert "NewImage" in insert_rec["dynamodb"] |
| 620 | assert insert_rec["dynamodb"]["NewImage"]["val"]["N"] == "1" |
| 621 | |
| 622 | modify_rec = our_records[1] |
| 623 | assert "OldImage" in modify_rec["dynamodb"] |
| 624 | assert modify_rec["dynamodb"]["OldImage"]["val"]["N"] == "1" |
| 625 | assert "NewImage" in modify_rec["dynamodb"] |
| 626 | assert modify_rec["dynamodb"]["NewImage"]["val"]["N"] == "2" |
| 627 | |
| 628 | remove_rec = our_records[2] |
| 629 | assert "OldImage" in remove_rec["dynamodb"] |
| 630 | assert remove_rec["dynamodb"]["OldImage"]["val"]["N"] == "2" |
| 631 | class TestGetShardIterator: |
| 632 | """Edge cases for GetShardIterator.""" |
| 633 |
nothing calls this directly
no test coverage detected