Skip to content

Commit 674f973

Browse files
committed
add tests
1 parent c7602ef commit 674f973

File tree

2 files changed

+138
-3
lines changed

2 files changed

+138
-3
lines changed

aws_lambda_powertools/utilities/parser/models/iot_registry_events.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class IoTCoreThingEvent(IoTCoreRegistryEventsBase):
2323
thingName: str
2424
versionNumber: int
2525
thingTypeName: Optional[str]
26-
billingGroupName: Optional[str]
27-
2826
attributes: Dict[str, Any]
2927

3028

@@ -36,7 +34,7 @@ class IoTCoreThingTypeEvent(IoTCoreRegistryEventsBase):
3634
isDeprecated: bool
3735
deprecationDate: Optional[str]
3836
searchableAttributes: List[str]
39-
propagatingAttributes: Dict[str, str]
37+
propagatingAttributes: List[Dict[str, str]]
4038
description: str
4139

4240

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
from aws_lambda_powertools.utilities.parser import parse
2+
from aws_lambda_powertools.utilities.parser.models.iot_registry_events import (
3+
IoTCoreAddOrDeleteFromThingGroupEvent,
4+
IoTCoreAddOrRemoveFromThingGroupEvent,
5+
IoTCoreThingEvent,
6+
IoTCoreThingGroupEvent,
7+
IoTCoreThingTypeAssociationEvent,
8+
IoTCoreThingTypeEvent,
9+
)
10+
11+
12+
def test_IoTCoreThingEvent_serialization():
13+
event = {
14+
"eventType": "THING_EVENT",
15+
"eventId": "f5ae9b94-8b8e-4d8e-8c8f-b3266dd89853",
16+
"timestamp": 1234567890123,
17+
"operation": "CREATED",
18+
"accountId": "123456789012",
19+
"thingId": "b604f69c-aa9a-4d4a-829e-c480e958a0b5",
20+
"thingName": "MyThing",
21+
"versionNumber": 1,
22+
"thingTypeName": None,
23+
"attributes": {"attribute3": "value3", "attribute1": "value1", "attribute2": "value2"},
24+
}
25+
parsed_event = parse(event, IoTCoreThingEvent)
26+
assert parsed_event is not None
27+
28+
29+
def test_IoTCoreThingTypeEvent_serialization():
30+
event = {
31+
"eventType": "THING_TYPE_EVENT",
32+
"eventId": "8827376c-4b05-49a3-9b3b-733729df7ed5",
33+
"timestamp": 1234567890123,
34+
"operation": "CREATED",
35+
"accountId": "123456789012",
36+
"thingTypeId": "c530ae83-32aa-4592-94d3-da29879d1aac",
37+
"thingTypeName": "MyThingType",
38+
"isDeprecated": False,
39+
"deprecationDate": None,
40+
"searchableAttributes": ["attribute1", "attribute2", "attribute3"],
41+
"propagatingAttributes": [
42+
{"userPropertyKey": "key", "thingAttribute": "model"},
43+
{"userPropertyKey": "key", "connectionAttribute": "iot:ClientId"},
44+
],
45+
"description": "My thing type",
46+
}
47+
result = parse(event, IoTCoreThingTypeEvent)
48+
assert result is not None
49+
50+
51+
def test_IoTCoreThingTypeAssociationEvent_serialization():
52+
event = {
53+
"eventId": "87f8e095-531c-47b3-aab5-5171364d138d",
54+
"eventType": "THING_TYPE_ASSOCIATION_EVENT",
55+
"operation": "ADDED",
56+
"thingId": "b604f69c-aa9a-4d4a-829e-c480e958a0b5",
57+
"thingName": "myThing",
58+
"thingTypeName": "MyThingType",
59+
"timestamp": 1234567890123,
60+
}
61+
result = parse(event, IoTCoreThingTypeAssociationEvent)
62+
assert result is not None
63+
64+
65+
def test_IoTCoreThingGroupEvent_serialization():
66+
event = {
67+
"eventType": "THING_GROUP_EVENT",
68+
"eventId": "8b9ea8626aeaa1e42100f3f32b975899",
69+
"timestamp": 1603995417409,
70+
"operation": "UPDATED",
71+
"accountId": "571EXAMPLE833",
72+
"thingGroupId": "8757eec8-bb37-4cca-a6fa-403b003d139f",
73+
"thingGroupName": "Tg_level5",
74+
"versionNumber": 3,
75+
"parentGroupName": "Tg_level4",
76+
"parentGroupId": "5fce366a-7875-4c0e-870b-79d8d1dce119",
77+
"description": "New description for Tg_level5",
78+
"rootToParentThingGroups": [
79+
{
80+
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/TgTopLevel",
81+
"groupId": "36aa0482-f80d-4e13-9bff-1c0a75c055f6",
82+
},
83+
{
84+
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/Tg_level1",
85+
"groupId": "bc1643e1-5a85-4eac-b45a-92509cbe2a77",
86+
},
87+
{
88+
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/Tg_level2",
89+
"groupId": "0476f3d2-9beb-48bb-ae2c-ea8bd6458158",
90+
},
91+
{
92+
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/Tg_level3",
93+
"groupId": "1d9d4ffe-a6b0-48d6-9de6-2e54d1eae78f",
94+
},
95+
{
96+
"groupArn": "arn:aws:iot:us-west-2:571EXAMPLE833:thinggroup/Tg_level4",
97+
"groupId": "5fce366a-7875-4c0e-870b-79d8d1dce119",
98+
},
99+
],
100+
"attributes": {"attribute1": "value1", "attribute3": "value3", "attribute2": "value2"},
101+
"dynamicGroupMappingId": None,
102+
}
103+
result = parse(event, IoTCoreThingGroupEvent)
104+
assert result is not None
105+
106+
107+
def test_IoTCoreAddOrRemoveFromThingGroupEvent_serialization():
108+
event = {
109+
"eventType": "THING_GROUP_MEMBERSHIP_EVENT",
110+
"eventId": "d684bd5f-6f6e-48e1-950c-766ac7f02fd1",
111+
"timestamp": 1234567890123,
112+
"operation": "ADDED",
113+
"accountId": "123456789012",
114+
"groupArn": "arn:aws:iot:ap-northeast-2:123456789012:thinggroup/MyChildThingGroup",
115+
"groupId": "06838589-373f-4312-b1f2-53f2192291c4",
116+
"thingArn": "arn:aws:iot:ap-northeast-2:123456789012:thing/MyThing",
117+
"thingId": "b604f69c-aa9a-4d4a-829e-c480e958a0b5",
118+
"membershipId": "8505ebf8-4d32-4286-80e9-c23a4a16bbd8",
119+
}
120+
result = parse(event, IoTCoreAddOrRemoveFromThingGroupEvent)
121+
assert result is not None
122+
123+
124+
def test_IoTCoreAddOrDeleteFromThingGroupEvent_serialization():
125+
event = {
126+
"eventType": "THING_GROUP_HIERARCHY_EVENT",
127+
"eventId": "264192c7-b573-46ef-ab7b-489fcd47da41",
128+
"timestamp": 1234567890123,
129+
"operation": "ADDED",
130+
"accountId": "123456789012",
131+
"thingGroupId": "8f82a106-6b1d-4331-8984-a84db5f6f8cb",
132+
"thingGroupName": "MyRootThingGroup",
133+
"childGroupId": "06838589-373f-4312-b1f2-53f2192291c4",
134+
"childGroupName": "MyChildThingGroup",
135+
}
136+
result = parse(event, IoTCoreAddOrDeleteFromThingGroupEvent)
137+
assert result is not None

0 commit comments

Comments
 (0)