"""Test deserialize_dynamo_db_streams_image udf entrypoint and helper fns.""" from typing import Any, Dict import pytest from pdp.utils.udf import deserialize_dynamo_db_streams_image as udf @pytest.fixture def dynamodb_streams_image() -> Dict[str, Dict[str, Any]]: """Fixture for dynamodb streams image.""" return { "created_at": { "bs": [], "l": [], "m": {}, "ns": [], "s": "2023-08-28T21:16:59.486313+00:00", "ss": [], "type": "S", }, "created_by": { "bs": [], "l": [], "m": {}, "ns": [], "s": "19d08c16-9ed3-4b38-89c2-9ea7c213267a", "ss": [], "type": "S", }, "identity_uuid": { "bs": [], "l": [], "m": {}, "ns": [], "s": "19d08c16-9ed3-4b38-89c2-9ea7c213267a", "ss": [], "type": "S", }, "roles": { "bs": [], "l": [ { "bs": [], "l": [], "m": { "role": { "bs": [], "l": [], "m": {}, "ns": [], "s": "dork", "ss": [], "type": "S", }, "types": { "bs": [], "l": [ { "bs": [], "l": [], "m": {}, "ns": [], "s": "book", "ss": [], "type": "S", } ], "m": {}, "ns": [], "ss": [], "type": "L", }, }, "ns": [], "ss": [], "type": "M", }, { "bs": [], "l": [], "m": { "role": { "bs": [], "l": [], "m": {}, "ns": [], "s": "dork_admin", "ss": [], "type": "S", }, "types": { "bs": [], "l": [ { "bs": [], "l": [], "m": {}, "ns": [], "s": "dictionary", "ss": [], "type": "S", } ], "m": {}, "ns": [], "ss": [], "type": "L", }, }, "ns": [], "ss": [], "type": "M", }, ], "m": {}, "ns": [], "ss": [], "type": "L", }, "tenant_type": { "bs": [], "l": [], "m": {}, "ns": [], "s": "account", "ss": [], "type": "S", }, "tenant_uuid": { "bs": [], "l": [], "m": {}, "ns": [], "s": "0268c332-8e7c-4c4e-9bb3-04532eb51c82", "ss": [], "type": "S", }, "updated_at": { "bs": [], "l": [], "m": {}, "ns": [], "s": "2023-08-28T21:17:24.734837+00:00", "ss": [], "type": "S", }, "updated_by": { "bs": [], "l": [], "m": {}, "ns": [], "s": "19d08c16-9ed3-4b38-89c2-9ea7c213267a", "ss": [], "type": "S", }, "version": { "bs": [], "l": [], "m": {}, "ns": [], "s": "2", "ss": [], "type": "S", }, } def test_udf_clean_dynamodb_streams_image( dynamodb_streams_image: Dict[str, Dict[str, Any]], ) -> None: """Test _clean_dynamodb_streams_image strips unnecessary keys.""" result = udf._clean_dynamodb_streams_image(dynamodb_streams_image) assert result == { "created_at": {"S": "2023-08-28T21:16:59.486313+00:00"}, "created_by": {"S": "19d08c16-9ed3-4b38-89c2-9ea7c213267a"}, "updated_at": {"S": "2023-08-28T21:17:24.734837+00:00"}, "updated_by": {"S": "19d08c16-9ed3-4b38-89c2-9ea7c213267a"}, "tenant_type": {"S": "account"}, "tenant_uuid": {"S": "0268c332-8e7c-4c4e-9bb3-04532eb51c82"}, "identity_uuid": {"S": "19d08c16-9ed3-4b38-89c2-9ea7c213267a"}, "version": {"S": "2"}, "roles": { "L": [ {"M": {"role": {"S": "dork"}, "types": {"L": [{"S": "book"}]}}}, { "M": { "role": {"S": "dork_admin"}, "types": {"L": [{"S": "dictionary"}]}, } }, ] }, } def test_deserialize_dynamo_item_udf( dynamodb_streams_image: Dict[str, Dict[str, Any]], ) -> None: """Test udf_entrypoint returns Python dict.""" result = udf.udf_entrypoint(dynamodb_streams_image) assert result == { "created_at": "2023-08-28T21:16:59.486313+00:00", "created_by": "19d08c16-9ed3-4b38-89c2-9ea7c213267a", "updated_at": "2023-08-28T21:17:24.734837+00:00", "updated_by": "19d08c16-9ed3-4b38-89c2-9ea7c213267a", "tenant_type": "account", "tenant_uuid": "0268c332-8e7c-4c4e-9bb3-04532eb51c82", "identity_uuid": "19d08c16-9ed3-4b38-89c2-9ea7c213267a", "version": "2", "roles": [ {"role": "dork", "types": ["book"]}, {"role": "dork_admin", "types": ["dictionary"]}, ], }