diff --git a/apprise_api/api/tests/test_notify.py b/apprise_api/api/tests/test_notify.py index 74ddeff..41ca2ac 100644 --- a/apprise_api/api/tests/test_notify.py +++ b/apprise_api/api/tests/test_notify.py @@ -1483,3 +1483,40 @@ def test_stateful_notify_recursion(self, mock_notify): '/notify/{}'.format(key), data=form_data, **headers) assert response.status_code == 400 assert mock_notify.call_count == 0 + + + @mock.patch('apprise.Apprise.notify') + def test_notify_no_body(self, mock_notify): + """ + Test sending a notification without a body (if supported) + """ + + key = "dummy" + + # Add some content + response = self.client.post( + '/add/{}'.format(key), + {'urls': 'onesignal://template_id:account_id@app_key/target_player_id'}) + assert response.status_code == 200 + + # Set our return value + mock_notify.return_value = True + + # Expect to fail because body is not provided + response = self.client.post( + '/notify/{}'.format(key), + data=json.dumps({}), + content_type='application/json', + ) + assert response.status_code == 400 and response.json() == { + "error": "Bad FORM Payload provided" + } + + # This now succeeds because body is set to not required explicitly + response = self.client.post( + '/notify/{}?body_not_required=true'.format(key), + data=json.dumps({}), + content_type='application/json', + ) + assert response.status_code == 200 and mock_notify.call_count == 1 + diff --git a/apprise_api/api/tests/test_stateless_notify.py b/apprise_api/api/tests/test_stateless_notify.py index db87416..e6eef43 100644 --- a/apprise_api/api/tests/test_stateless_notify.py +++ b/apprise_api/api/tests/test_stateless_notify.py @@ -757,3 +757,35 @@ def test_notify_with_filters(self, mock_send): # nothing was changed assert N_MGR['json'].enabled is True + + @mock.patch('apprise.Apprise.notify') + def test_notify_no_body(self, mock_notify): + """ + Test sending a notification without a body (if supported) + """ + + # Set our return value + mock_notify.return_value = True + + # Prepare our JSON data + json_data = { + 'urls': 'onesignal://template_id:account_id@app_key/target_player_id', + } + + # Expect to fail because body is not provided + response = self.client.post( + '/notify/', + data=json.dumps(json_data), + content_type='application/json', + ) + assert response.status_code == 400 and response.json() == { + "error": "Payload lacks minimum requirements" + } + + # This now succeeds because body is set to not required explicitly + response = self.client.post( + '/notify/?body_not_required=true', + data=json.dumps(json_data), + content_type='application/json', + ) + assert response.status_code == 200 and mock_notify.call_count == 1