Skip to content

Commit

Permalink
Standardize Amazon SES naming (#20367)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferruzzi authored Dec 18, 2021
1 parent ed604b6 commit cef498e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
18 changes: 17 additions & 1 deletion airflow/providers/amazon/aws/hooks/ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
# specific language governing permissions and limitations
# under the License.
"""This module contains AWS SES Hook"""
import warnings
from typing import Any, Dict, Iterable, List, Optional, Union

from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
from airflow.utils.email import build_mime_message


class SESHook(AwsBaseHook):
class SesHook(AwsBaseHook):
"""
Interact with Amazon Simple Email Service.
Expand Down Expand Up @@ -95,3 +96,18 @@ def send_email(
return ses_client.send_raw_email(
Source=mail_from, Destinations=recipients, RawMessage={'Data': message.as_string()}
)


class SESHook(SesHook):
"""
This hook is deprecated.
Please use :class:`airflow.providers.amazon.aws.hooks.ses.SesHook`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"This hook is deprecated. " "Please use :class:`airflow.providers.amazon.aws.hooks.ses.SesHook`.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(*args, **kwargs)
4 changes: 2 additions & 2 deletions airflow/providers/amazon/aws/utils/emailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from typing import List, Optional, Union

from airflow.providers.amazon.aws.hooks.ses import SESHook
from airflow.providers.amazon.aws.hooks.ses import SesHook


def send_email(
Expand All @@ -36,7 +36,7 @@ def send_email(
**kwargs,
) -> None:
"""Email backend for SES."""
hook = SESHook(aws_conn_id=conn_id)
hook = SesHook(aws_conn_id=conn_id)
hook.send_email(
mail_from=from_email,
to=to,
Expand Down
6 changes: 3 additions & 3 deletions tests/providers/amazon/aws/hooks/test_ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import pytest
from moto import mock_ses

from airflow.providers.amazon.aws.hooks.ses import SESHook
from airflow.providers.amazon.aws.hooks.ses import SesHook

boto3.setup_default_session()


@mock_ses
def test_get_conn():
hook = SESHook(aws_conn_id='aws_default')
hook = SesHook(aws_conn_id='aws_default')
assert hook.get_conn() is not None


Expand All @@ -42,7 +42,7 @@ def test_get_conn():
)
def test_send_email(to, cc, bcc):
# Given
hook = SESHook()
hook = SesHook()
ses_client = hook.get_conn()
mail_from = 'test_from@domain.com'

Expand Down
2 changes: 1 addition & 1 deletion tests/providers/amazon/aws/utils/test_emailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


class TestSendEmailSes(TestCase):
@mock.patch("airflow.providers.amazon.aws.utils.emailer.SESHook")
@mock.patch("airflow.providers.amazon.aws.utils.emailer.SesHook")
def test_send_ses_email(self, mock_hook):
send_email(
from_email="From Test <from@test.com>",
Expand Down

0 comments on commit cef498e

Please sign in to comment.