Allow an empty body when attachment is provided (#156)

This commit is contained in:
Gerald 2023-12-24 03:35:10 +08:00 committed by GitHub
parent 9d3f8c7a33
commit 4ad2bb1c03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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',

View File

@ -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: