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

allow empty body when attachment is provided #156

Merged
merged 1 commit into from
Dec 23, 2023
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
1 change: 1 addition & 0 deletions apprise_api/api/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions apprise_api/api/tests/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ def test_notify_by_loaded_urls(self, mock_notify):
# 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',
Expand Down
2 changes: 1 addition & 1 deletion apprise_api/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def post(self, request, key):
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:

Expand Down