-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DynamoDB: Add software test for decoding list of objects
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from cratedb_toolkit.io.dynamodb.copy import DynamoDBFullLoad | ||
|
||
RECORD_UTM = { | ||
"Id": {"N": "101"}, | ||
"utmTags": { | ||
"L": [ | ||
{ | ||
"M": { | ||
"date": {"S": "2024-08-28T20:05:42.603Z"}, | ||
"utm_adgroup": {"L": [{"S": ""}, {"S": ""}]}, | ||
"utm_campaign": {"S": "34374686341"}, | ||
"utm_medium": {"S": "foobar"}, | ||
"utm_source": {"S": "google"}, | ||
} | ||
} | ||
] | ||
}, | ||
} | ||
|
||
|
||
def test_dynamodb_copy_list_of_objects(caplog, cratedb, dynamodb, dynamodb_test_manager): | ||
""" | ||
CLI test: Invoke `ctk load table` for DynamoDB. | ||
""" | ||
|
||
# Define source and target URLs. | ||
cratedb_url = f"{cratedb.get_connection_url()}/testdrive/demo" | ||
dynamodb_url = f"{dynamodb.get_connection_url()}/demo?region=us-east-1" | ||
|
||
# Populate source database with data. | ||
dynamodb_test_manager.load_records(table_name="demo", records=[RECORD_UTM]) | ||
|
||
# Run transfer command. | ||
table_loader = DynamoDBFullLoad(dynamodb_url=dynamodb_url, cratedb_url=cratedb_url) | ||
table_loader.start() | ||
|
||
# Verify data in target database. | ||
assert cratedb.database.table_exists("testdrive.demo") is True | ||
assert cratedb.database.refresh_table("testdrive.demo") is True | ||
assert cratedb.database.count_records("testdrive.demo") == 1 | ||
|
||
results = cratedb.database.run_sql("SELECT * FROM testdrive.demo;", records=True) # noqa: S608 | ||
assert results[0]["data"] == { | ||
"Id": 101.0, | ||
"utmTags": [ | ||
{ | ||
"date": "2024-08-28T20:05:42.603Z", | ||
"utm_adgroup": ["", ""], | ||
"utm_campaign": "34374686341", | ||
"utm_medium": "foobar", | ||
"utm_source": "google", | ||
} | ||
], | ||
} |