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

feat: add v3 bypass filters #983

Merged
merged 3 commits into from
Apr 9, 2021
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
3 changes: 3 additions & 0 deletions sendgrid/helpers/mail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from .bcc_email import Bcc
from .bcc_settings import BccSettings
from .bcc_settings_email import BccSettingsEmail
from .bypass_bounce_management import BypassBounceManagement
from .bypass_list_management import BypassListManagement
from .bypass_spam_management import BypassSpamManagement
from .bypass_unsubscribe_management import BypassUnsubscribeManagement
from .category import Category
from .cc_email import Cc
from .click_tracking import ClickTracking
Expand Down
48 changes: 48 additions & 0 deletions sendgrid/helpers/mail/bypass_bounce_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class BypassBounceManagement(object):
"""Setting for Bypass Bounce Management


Allows you to bypass the bounce list to ensure that the email is delivered to recipients.
Spam report and unsubscribe lists will still be checked; addresses on these other lists
will not receive the message. This filter cannot be combined with the bypass_list_management filter.
"""

def __init__(self, enable=None):
"""Create a BypassBounceManagement.

:param enable: Whether emails should bypass bounce management.
:type enable: boolean, optional
"""
self._enable = None

if enable is not None:
self.enable = enable

@property
def enable(self):
"""Indicates if this setting is enabled.

:rtype: boolean
"""
return self._enable

@enable.setter
def enable(self, value):
"""Indicates if this setting is enabled.

:param value: Indicates if this setting is enabled.
:type value: boolean
"""
self._enable = value

def get(self):
"""
Get a JSON-ready representation of this BypassBounceManagement.

:returns: This BypassBounceManagement, ready for use in a request body.
:rtype: dict
"""
bypass_bounce_management = {}
if self.enable is not None:
bypass_bounce_management["enable"] = self.enable
return bypass_bounce_management
47 changes: 47 additions & 0 deletions sendgrid/helpers/mail/bypass_spam_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class BypassSpamManagement(object):
"""Setting for Bypass Spam Management

Allows you to bypass the spam report list to ensure that the email is delivered to recipients.
Bounce and unsubscribe lists will still be checked; addresses on these other lists will not
receive the message. This filter cannot be combined with the bypass_list_management filter.
"""

def __init__(self, enable=None):
"""Create a BypassSpamManagement.

:param enable: Whether emails should bypass spam management.
:type enable: boolean, optional
"""
self._enable = None

if enable is not None:
self.enable = enable

@property
def enable(self):
"""Indicates if this setting is enabled.

:rtype: boolean
"""
return self._enable

@enable.setter
def enable(self, value):
"""Indicates if this setting is enabled.

:param value: Indicates if this setting is enabled.
:type value: boolean
"""
self._enable = value

def get(self):
"""
Get a JSON-ready representation of this BypassSpamManagement.

:returns: This BypassSpamManagement, ready for use in a request body.
:rtype: dict
"""
bypass_spam_management = {}
if self.enable is not None:
bypass_spam_management["enable"] = self.enable
return bypass_spam_management
49 changes: 49 additions & 0 deletions sendgrid/helpers/mail/bypass_unsubscribe_management.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class BypassUnsubscribeManagement(object):
"""Setting for Bypass Unsubscribe Management


Allows you to bypass the global unsubscribe list to ensure that the email is delivered to recipients.
Bounce and spam report lists will still be checked; addresses on these other lists will not receive
the message. This filter applies only to global unsubscribes and will not bypass group unsubscribes.
This filter cannot be combined with the bypass_list_management filter.
"""

def __init__(self, enable=None):
"""Create a BypassUnsubscribeManagement.

:param enable: Whether emails should bypass unsubscribe management.
:type enable: boolean, optional
"""
self._enable = None

if enable is not None:
self.enable = enable

@property
def enable(self):
"""Indicates if this setting is enabled.

:rtype: boolean
"""
return self._enable

@enable.setter
def enable(self, value):
"""Indicates if this setting is enabled.

:param value: Indicates if this setting is enabled.
:type value: boolean
"""
self._enable = value

def get(self):
"""
Get a JSON-ready representation of this BypassUnsubscribeManagement.

:returns: This BypassUnsubscribeManagement, ready for use in a request body.
:rtype: dict
"""
bypass_unsubscribe_management = {}
if self.enable is not None:
bypass_unsubscribe_management["enable"] = self.enable
return bypass_unsubscribe_management
87 changes: 87 additions & 0 deletions sendgrid/helpers/mail/mail_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ class MailSettings(object):

def __init__(self,
bcc_settings=None,
bypass_bounce_management=None,
bypass_list_management=None,
bypass_spam_management=None,
bypass_unsubscribe_management=None,
footer_settings=None,
sandbox_mode=None,
spam_check=None):
"""Create a MailSettings object

:param bcc_settings: The BCC Settings of this MailSettings
:type bcc_settings: BCCSettings, optional
:param bypass_bounce_management: Whether this MailSettings bypasses bounce management.
Should not be combined with bypass_list_management.
:type bypass_list_management: BypassBounceManagement, optional
:param bypass_list_management: Whether this MailSettings bypasses list
management
:type bypass_list_management: BypassListManagement, optional
:param bypass_spam_management: Whether this MailSettings bypasses spam management.
Should not be combined with bypass_list_management.
:type bypass_list_management: BypassSpamManagement, optional
:param bypass_unsubscribe_management: Whether this MailSettings bypasses unsubscribe management.
Should not be combined with bypass_list_management.
:type bypass_list_management: BypassUnsubscribeManagement, optional
:param footer_settings: The default footer specified by this
MailSettings
:type footer_settings: FooterSettings, optional
Expand All @@ -24,17 +36,29 @@ def __init__(self,
:type spam_check: SpamCheck, optional
"""
self._bcc_settings = None
self._bypass_bounce_management = None
self._bypass_list_management = None
self._bypass_spam_management = None
self._bypass_unsubscribe_management = None
self._footer_settings = None
self._sandbox_mode = None
self._spam_check = None

if bcc_settings is not None:
self.bcc_settings = bcc_settings

if bypass_bounce_management is not None:
self.bypass_bounce_management = bypass_bounce_management

if bypass_list_management is not None:
self.bypass_list_management = bypass_list_management

if bypass_spam_management is not None:
self.bypass_spam_management = bypass_spam_management

if bypass_unsubscribe_management is not None:
self.bypass_unsubscribe_management = bypass_unsubscribe_management

if footer_settings is not None:
self.footer_settings = footer_settings

Expand All @@ -61,6 +85,23 @@ def bcc_settings(self, value):
"""
self._bcc_settings = value

@property
def bypass_bounce_management(self):
"""Whether this MailSettings bypasses bounce management.

:rtype: BypassBounceManagement
"""
return self._bypass_bounce_management

@bypass_bounce_management.setter
def bypass_bounce_management(self, value):
"""Whether this MailSettings bypasses bounce management.

:param value: Whether this MailSettings bypasses bounce management.
:type value: BypassBounceManagement
"""
self._bypass_bounce_management = value

@property
def bypass_list_management(self):
"""Whether this MailSettings bypasses list management.
Expand All @@ -78,6 +119,40 @@ def bypass_list_management(self, value):
"""
self._bypass_list_management = value

@property
def bypass_spam_management(self):
"""Whether this MailSettings bypasses spam management.

:rtype: BypassSpamManagement
"""
return self._bypass_spam_management

@bypass_spam_management.setter
def bypass_spam_management(self, value):
"""Whether this MailSettings bypasses spam management.

:param value: Whether this MailSettings bypasses spam management.
:type value: BypassSpamManagement
"""
self._bypass_spam_management = value

@property
def bypass_unsubscribe_management(self):
"""Whether this MailSettings bypasses unsubscribe management.

:rtype: BypassUnsubscribeManagement
"""
return self._bypass_unsubscribe_management

@bypass_unsubscribe_management.setter
def bypass_unsubscribe_management(self, value):
"""Whether this MailSettings bypasses unsubscribe management.

:param value: Whether this MailSettings bypasses unsubscribe management.
:type value: BypassUnsubscribeManagement
"""
self._bypass_unsubscribe_management = value

@property
def footer_settings(self):
"""The default footer specified by this MailSettings.
Expand Down Expand Up @@ -141,10 +216,22 @@ def get(self):
if self.bcc_settings is not None:
mail_settings["bcc"] = self.bcc_settings.get()

if self.bypass_bounce_management is not None:
mail_settings[
"bypass_bounce_management"] = self.bypass_bounce_management.get()

if self.bypass_list_management is not None:
mail_settings[
"bypass_list_management"] = self.bypass_list_management.get()

if self.bypass_spam_management is not None:
mail_settings[
"bypass_spam_management"] = self.bypass_spam_management.get()

if self.bypass_unsubscribe_management is not None:
mail_settings[
"bypass_unsubscribe_management"] = self.bypass_unsubscribe_management.get()

if self.footer_settings is not None:
mail_settings["footer"] = self.footer_settings.get()

Expand Down
54 changes: 53 additions & 1 deletion test/test_mail_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,8 @@ def test_kitchen_sink(self):
FileContent, FileType, Disposition, ContentId, TemplateId,
Section, ReplyTo, Category, BatchId, Asm, GroupId, GroupsToDisplay,
IpPoolName, MailSettings, BccSettings, BccSettingsEmail,
BypassListManagement, FooterSettings, FooterText,
BypassBounceManagement, BypassListManagement, BypassSpamManagement,
BypassUnsubscribeManagement, FooterSettings, FooterText,
FooterHtml, SandBoxMode, SpamCheck, SpamThreshold, SpamUrl,
TrackingSettings, ClickTracking, SubscriptionTracking,
SubscriptionText, SubscriptionHtml, SubscriptionSubstitutionTag,
Expand Down Expand Up @@ -1116,7 +1117,10 @@ def test_kitchen_sink(self):
mail_settings = MailSettings()
mail_settings.bcc_settings = BccSettings(
False, BccSettingsEmail("[email protected]"))
mail_settings.bypass_bounce_management = BypassBounceManagement(False)
mail_settings.bypass_list_management = BypassListManagement(False)
mail_settings.bypass_spam_management = BypassSpamManagement(False)
mail_settings.bypass_unsubscribe_management = BypassUnsubscribeManagement(False)
mail_settings.footer_settings = FooterSettings(
True, FooterText("w00t"), FooterHtml("<string>w00t!<strong>"))
mail_settings.sandbox_mode = SandBoxMode(True)
Expand Down Expand Up @@ -1223,9 +1227,18 @@ def test_kitchen_sink(self):
"email": "[email protected]",
"enable": false
},
"bypass_bounce_management": {
"enable": false
},
"bypass_list_management": {
"enable": false
},
"bypass_spam_management": {
"enable": false
},
"bypass_unsubscribe_management": {
"enable": false
},
"footer": {
"enable": true,
"html": "<string>w00t!<strong>",
Expand Down Expand Up @@ -1613,3 +1626,42 @@ def test_disable_tracking(self):
tracking_settings.get(),
{'click_tracking': {'enable': False, 'enable_text': False}}
)

def test_bypass_list_management(self):
from sendgrid.helpers.mail import (MailSettings, BypassListManagement)
mail_settings = MailSettings()
mail_settings.bypass_list_management = BypassListManagement(True)

self.assertEqual(
mail_settings.get(),
{
"bypass_list_management": {
"enable": True
},
},
)

def test_v3_bypass_filters(self):
from sendgrid.helpers.mail import (
MailSettings, BypassBounceManagement,
BypassSpamManagement, BypassUnsubscribeManagement
)
mail_settings = MailSettings()
mail_settings.bypass_bounce_management = BypassBounceManagement(True)
mail_settings.bypass_spam_management = BypassSpamManagement(True)
mail_settings.bypass_unsubscribe_management = BypassUnsubscribeManagement(True)

self.assertEqual(
mail_settings.get(),
{
"bypass_bounce_management": {
"enable": True
},
"bypass_spam_management": {
"enable": True
},
"bypass_unsubscribe_management": {
"enable": True
},
},
)
Loading