add email
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
import boto3
|
||||
import jsonlines
|
||||
import pytest
|
||||
|
||||
PYTEST_TABLE_NAME = 'pytest'
|
||||
PYTEST_TABLE_NAME = f'pytest_{uuid4()}'
|
||||
DYNAMODB_ENDPOINT_URL = 'http://localhost:8000'
|
||||
PK = 'id'
|
||||
SK = 'sk'
|
||||
|
||||
BIN
layercake/tests/samples/test.pdf
Normal file
BIN
layercake/tests/samples/test.pdf
Normal file
Binary file not shown.
48
layercake/tests/test_email.py
Normal file
48
layercake/tests/test_email.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import boto3
|
||||
import pytest
|
||||
from layercake.dateutils import now
|
||||
from layercake.email_ import Message
|
||||
from moto import mock_aws
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def aws_credentials():
|
||||
"""Mocked AWS Credentials for moto."""
|
||||
os.environ['AWS_ACCESS_KEY_ID'] = 'testing'
|
||||
os.environ['AWS_SECRET_ACCESS_KEY'] = 'testing'
|
||||
os.environ['AWS_SECURITY_TOKEN'] = 'testing'
|
||||
os.environ['AWS_SESSION_TOKEN'] = 'testing'
|
||||
os.environ['AWS_DEFAULT_REGION'] = 'sa-east-1'
|
||||
|
||||
|
||||
def test_send_email(aws_credentials):
|
||||
from_ = 'pytest@eduseg.com.br'
|
||||
|
||||
with mock_aws():
|
||||
ses = boto3.client('ses', region_name='sa-east-1')
|
||||
ses.verify_email_identity(EmailAddress=from_)
|
||||
to = ('Sérgio', 'sergio@somosbeta.com.br')
|
||||
msg = Message(
|
||||
to=to,
|
||||
from_=('Beta Educação', from_),
|
||||
subject='áéíóúnõ',
|
||||
reply_to=('', 'osergiosiqueira@gmail.com'),
|
||||
content='<b>Lorem ipsum dolor sit amet, consectetur adipiscing elit</b>',
|
||||
)
|
||||
msg.add_header('X-Feedback', f'uid=123; oid=123; date={now().isoformat()}')
|
||||
msg.add_alternative(
|
||||
"""
|
||||
<h2>áéíóúnõ</h2>
|
||||
html
|
||||
"""
|
||||
)
|
||||
msg.attach(Path('tests/samples/test.pdf'), 'relatório.pdf')
|
||||
|
||||
assert ses.send_raw_email(
|
||||
Source=from_,
|
||||
Destinations=[to[1]],
|
||||
RawMessage={'Data': msg.as_bytes()},
|
||||
)
|
||||
Reference in New Issue
Block a user