Skip to content

Commit

Permalink
DynamoDB: Add software test for decoding list of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Motl authored and amotl committed Aug 28, 2024
1 parent 25eb728 commit 3e32304
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions tests/transform/test_dynamodb_full.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from commons_codec.model import SQLOperation
from commons_codec.transform.dynamodb import DynamoDBFullLoadTranslator

RECORD = {
RECORD_ALL_TYPES = {
"id": {"S": "5F9E-Fsadd41C-4C92-A8C1-70BF3FFB9266"},
"data": {"M": {"temperature": {"N": "42.42"}, "humidity": {"N": "84.84"}}},
"meta": {"M": {"timestamp": {"S": "2024-07-12T01:17:42"}, "device": {"S": "foo"}}},
Expand All @@ -16,6 +16,22 @@
},
}

RECORD_UTM = {
"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_sql_ddl():
assert (
Expand All @@ -24,8 +40,8 @@ def test_sql_ddl():
)


def test_to_sql():
assert DynamoDBFullLoadTranslator(table_name="foo").to_sql(RECORD) == SQLOperation(
def test_to_sql_all_types():
assert DynamoDBFullLoadTranslator(table_name="foo").to_sql(RECORD_ALL_TYPES) == SQLOperation(
statement='INSERT INTO "foo" (data) VALUES (:record);',
parameters={
"record": {
Expand All @@ -39,3 +55,22 @@ def test_to_sql():
}
},
)


def test_to_sql_list_of_objects():
assert DynamoDBFullLoadTranslator(table_name="foo").to_sql(RECORD_UTM) == SQLOperation(
statement='INSERT INTO "foo" (data) VALUES (:record);',
parameters={
"record": {
"utmTags": [
{
"date": "2024-08-28T20:05:42.603Z",
"utm_adgroup": ["", ""],
"utm_campaign": "34374686341",
"utm_medium": "foobar",
"utm_source": "google",
}
]
}
},
)

0 comments on commit 3e32304

Please sign in to comment.