From 4ad2bb1c033ca1d71bb6d8c937492c9b185a8a4e Mon Sep 17 00:00:00 2001 From: Gerald Date: Sun, 24 Dec 2023 03:35:10 +0800 Subject: [PATCH] Allow an empty body when attachment is provided (#156) --- apprise_api/api/forms.py | 1 + apprise_api/api/tests/test_notify.py | 20 ++++++++++++++++++++ apprise_api/api/views.py | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apprise_api/api/forms.py b/apprise_api/api/forms.py index d63868e..6a4d868 100644 --- a/apprise_api/api/forms.py +++ b/apprise_api/api/forms.py @@ -136,6 +136,7 @@ class NotifyForm(forms.Form): widget=forms.Textarea( attrs={'placeholder': _('Define your message body here...')}), max_length=apprise.NotifyBase.body_maxlen, + required=False, ) # Attachment Support diff --git a/apprise_api/api/tests/test_notify.py b/apprise_api/api/tests/test_notify.py index fbe19e3..cee59ff 100644 --- a/apprise_api/api/tests/test_notify.py +++ b/apprise_api/api/tests/test_notify.py @@ -82,6 +82,26 @@ class NotifyTests(SimpleTestCase): # Reset our mock object mock_notify.reset_mock() + # Preare our form data + form_data = {} + attach_data = { + 'attachment': SimpleUploadedFile( + "attach.txt", b"content here", content_type="text/plain") + } + + # At a minimum, just an attachment is required + form = NotifyForm(form_data, attach_data) + assert form.is_valid() + + # Send our notification + response = self.client.post( + '/notify/{}'.format(key), form.cleaned_data) + assert response.status_code == 200 + assert mock_notify.call_count == 1 + + # Reset our mock object + mock_notify.reset_mock() + # Preare our form data form_data = { 'body': 'test notifiction', diff --git a/apprise_api/api/views.py b/apprise_api/api/views.py index 968aa3d..da5e7ab 100644 --- a/apprise_api/api/views.py +++ b/apprise_api/api/views.py @@ -691,7 +691,7 @@ class NotifyView(View): content['title'] = request.GET['title'] # Some basic error checking - if not content.get('body') or \ + if not content.get('body') and not attach or \ content.get('type', apprise.NotifyType.INFO) \ not in apprise.NOTIFY_TYPES: