Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "fix(parser): Add missing fields for SESEvent" #1190

Merged
merged 1 commit into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions aws_lambda_powertools/utilities/parser/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@
SesModel,
SesReceipt,
SesReceiptAction,
SesReceiptActionBase,
SesReceiptBounceAction,
SesReceiptS3Action,
SesReceiptVerdict,
SesReceiptWorkmailAction,
SesRecordModel,
)
from .sns import SnsModel, SnsNotificationModel, SnsRecordModel
Expand Down Expand Up @@ -88,10 +84,6 @@
"SesMailHeaders",
"SesReceipt",
"SesReceiptAction",
"SesReceiptActionBase",
"SesReceiptBounceAction",
"SesReceiptWorkmailAction",
"SesReceiptS3Action",
"SesReceiptVerdict",
"SnsModel",
"SnsNotificationModel",
Expand Down
34 changes: 3 additions & 31 deletions aws_lambda_powertools/utilities/parser/models/ses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import List, Optional, Union
from typing import List, Optional

from pydantic import BaseModel, Field
from pydantic.networks import EmailStr
Expand All @@ -12,49 +12,21 @@ class SesReceiptVerdict(BaseModel):
status: Literal["PASS", "FAIL", "GRAY", "PROCESSING_FAILED"]


class SesReceiptActionBase(BaseModel):
topicArn: Optional[str]


class SesReceiptAction(SesReceiptActionBase):
class SesReceiptAction(BaseModel):
type: Literal["Lambda"] # noqa A003,VNE003
invocationType: Literal["Event"]
functionArn: str


class SesReceiptS3Action(SesReceiptActionBase):
type: Literal["S3"] # noqa A003,VNE003
topicArn: str
bucketName: str
objectKey: str


class SesReceiptBounceAction(SesReceiptActionBase):
type: Literal["Bounce"] # noqa A003,VNE003
topicArn: str
smtpReplyCode: str
message: str
sender: str
statusCode: str


class SesReceiptWorkmailAction(SesReceiptActionBase):
type: Literal["WorkMail"] # noqa A003,VNE003
topicArn: str
organizationArn: str


class SesReceipt(BaseModel):
timestamp: datetime
processingTimeMillis: PositiveInt
recipients: List[EmailStr]
spamVerdict: SesReceiptVerdict
virusVerdict: SesReceiptVerdict
spfVerdict: SesReceiptVerdict
dkimVerdict: SesReceiptVerdict
dmarcVerdict: SesReceiptVerdict
dmarcPolicy: Optional[Literal["quarantine", "reject", "none"]]
action: Union[SesReceiptAction, SesReceiptS3Action, SesReceiptBounceAction, SesReceiptWorkmailAction]
action: SesReceiptAction


class SesMailHeaders(BaseModel):
Expand Down
114 changes: 0 additions & 114 deletions tests/events/sesEventS3.json

This file was deleted.

58 changes: 5 additions & 53 deletions tests/functional/parser/test_ses.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
from aws_lambda_powertools.utilities.parser import event_parser
from aws_lambda_powertools.utilities.parser.models import (
SesModel,
SesReceiptBounceAction,
SesReceiptWorkmailAction,
SesRecordModel,
)
from aws_lambda_powertools.utilities.parser.models import SesModel, SesRecordModel
from aws_lambda_powertools.utilities.typing import LambdaContext
from tests.functional.utils import load_event


@event_parser(model=SesModel)
def handle_ses(event: SesModel, _: LambdaContext) -> SesModel:
return event


def test_ses_trigger_lambda_event():
event_dict = load_event("sesEvent.json")
event = handle_ses(event_dict, LambdaContext())
def handle_ses(event: SesModel, _: LambdaContext):
expected_address = "[email protected]"
records = event.Records
record: SesRecordModel = records[0]
Expand All @@ -40,10 +29,6 @@ def test_ses_trigger_lambda_event():
assert common_headers.to == [expected_address]
assert common_headers.messageId == "<0123456789example.com>"
assert common_headers.subject == "Test Subject"
assert common_headers.cc is None
assert common_headers.bcc is None
assert common_headers.sender is None
assert common_headers.reply_to is None
receipt = record.ses.receipt
convert_time = int(round(receipt.timestamp.timestamp() * 1000))
assert convert_time == 0
Expand All @@ -53,45 +38,12 @@ def test_ses_trigger_lambda_event():
assert receipt.virusVerdict.status == "PASS"
assert receipt.spfVerdict.status == "PASS"
assert receipt.dmarcVerdict.status == "PASS"
assert receipt.dmarcVerdict.status == "PASS"
assert receipt.dmarcPolicy is None
action = receipt.action
assert action.type == "Lambda"
assert action.functionArn == "arn:aws:lambda:us-west-2:012345678912:function:Example"
assert action.invocationType == "Event"
assert action.topicArn is None


def test_ses_trigger_event_s3():
event_dict = load_event("sesEventS3.json")
event = handle_ses(event_dict, LambdaContext())
records = list(event.Records)
record = records[0]
receipt = record.ses.receipt
assert receipt.dmarcPolicy == "reject"
action = record.ses.receipt.action
assert action.type == "S3"
assert action.topicArn == "arn:aws:sns:us-east-1:012345678912:example-topic"
assert action.bucketName == "my-S3-bucket"
assert action.objectKey == "email"


def test_ses_trigger_event_bounce():
event_dict = {
"type": "Bounce",
"topicArn": "arn:aws:sns:us-east-1:123456789012:topic:my-topic",
"smtpReplyCode": "5.1.1",
"message": "message",
"sender": "sender",
"statusCode": "550",
}
SesReceiptBounceAction(**event_dict)


def test_ses_trigger_event_work_mail():
event_dict = {
"type": "WorkMail",
"topicArn": "arn:aws:sns:us-east-1:123456789012:topic:my-topic",
"organizationArn": "arn",
}
SesReceiptWorkmailAction(**event_dict)
def test_ses_trigger_event():
event_dict = load_event("sesEvent.json")
handle_ses(event_dict, LambdaContext())