SendGrid Attachment Support Added (#1190)

This commit is contained in:
Chris Caron
2024-08-27 16:32:52 -04:00
committed by GitHub
parent 3cb270cee8
commit ca50cb7820
4 changed files with 146 additions and 1 deletions

View File

@@ -28,9 +28,13 @@
from unittest import mock
import os
import pytest
import requests
from apprise import Apprise
from apprise import NotifyType
from apprise import AppriseAttachment
from apprise.plugins.sendgrid import NotifySendGrid
from helpers import AppriseURLTester
@@ -38,6 +42,9 @@ from helpers import AppriseURLTester
import logging
logging.disable(logging.CRITICAL)
# Attachment Directory
TEST_VAR_DIR = os.path.join(os.path.dirname(__file__), 'var')
# a test UUID we can use
UUID4 = '8b799edf-6f98-4d3a-9be7-2862fb4e5752'
@@ -161,3 +168,36 @@ def test_plugin_sendgrid_edge_cases(mock_post, mock_get):
from_email='l2g@example.com',
bcc=('abc@def.com', '!invalid'),
cc=('abc@test.org', '!invalid')), NotifySendGrid)
@mock.patch('requests.get')
@mock.patch('requests.post')
def test_plugin_sendgrid_attachments(mock_post, mock_get):
"""
NotifySendGrid() Attachments
"""
request = mock.Mock()
request.status_code = requests.codes.ok
# Prepare Mock
mock_post.return_value = request
mock_get.return_value = request
path = os.path.join(TEST_VAR_DIR, 'apprise-test.gif')
attach = AppriseAttachment(path)
obj = Apprise.instantiate('sendgrid://abcd:user@example.com')
assert isinstance(obj, NotifySendGrid)
assert obj.notify(
body='body', title='title', notify_type=NotifyType.INFO,
attach=attach) is True
mock_post.reset_mock()
mock_get.reset_mock()
# Try again in a use case where we can't access the file
with mock.patch("builtins.open", side_effect=OSError):
assert obj.notify(
body='body', title='title', notify_type=NotifyType.INFO,
attach=attach) is False