Skip to content

Commit

Permalink
Fix sns event type casing
Browse files Browse the repository at this point in the history
Closes iopipe#250

Signed-off-by: Michael Lavers <kolanos@gmail.com>
  • Loading branch information
kolanos committed Jul 13, 2018
1 parent 684c3c1 commit 91ed662
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
6 changes: 3 additions & 3 deletions iopipe/contrib/eventinfo/event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ class SNS(EventType):
"Records[0].Sns.TopicArn",
"Records[0].Sns.Type",
]
required_keys = ["Records[0].eventVersion", "Records[0].eventSource"]
required_keys = ["Records[0].EventVersion", "Records[0].EventSource"]

def has_required_keys(self):
return (
super(SNS, self).has_required_keys()
and get_value(self.event, "Records[0].eventVersion") == "1.0"
and get_value(self.event, "Records[0].eventSource") == "aws:sns"
and get_value(self.event, "Records[0].EventVersion") == "1.0"
and get_value(self.event, "Records[0].EventSource") == "aws:sns"
)


Expand Down
5 changes: 5 additions & 0 deletions tests/contrib/eventinfo/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ def event_kinesis():
return _load_event("kinesis")


@pytest.fixture
def event_sns():
return _load_event("sns")


@pytest.fixture
def event_scheduled():
return _load_event("scheduled")
Expand Down
31 changes: 31 additions & 0 deletions tests/contrib/eventinfo/events/sns.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"Records": [
{
"EventVersion": "1.0",
"EventSubscriptionArn": "arn:aws:sns:EXAMPLE",
"EventSource": "aws:sns",
"Sns": {
"SignatureVersion": "1",
"Timestamp": "1970-01-01T00:00:00.000Z",
"Signature": "EXAMPLE",
"SigningCertUrl": "EXAMPLE",
"MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
"Message": "Hello from SNS!",
"MessageAttributes": {
"Test": {
"Type": "String",
"Value": "TestString"
},
"TestBinary": {
"Type": "Binary",
"Value": "TestBinary"
}
},
"Type": "Notification",
"UnsubscribeUrl": "EXAMPLE",
"TopicArn": "arn:aws:sns:EXAMPLE",
"Subject": "TestInvoke"
}
}
]
}
13 changes: 13 additions & 0 deletions tests/contrib/eventinfo/test_event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,16 @@ def test__event_types__serverless_lambda(event_serverless_lambda):
]
)
assert event_info["@iopipe/event-info.eventType.source"] == event.source


def test__event_types__sns(event_sns):
event = et.SNS(event_sns)
assert event.has_required_keys() is True

event_info = event.collect()
assert event_info != {}

expected_keys = ["@iopipe/event-info.eventType"] + [
"@iopipe/event-info.sns.%s" % key for key in event.keys
]
assert list(event_info.keys()).sort() == expected_keys.sort()

0 comments on commit 91ed662

Please sign in to comment.