Skip to content

Commit

Permalink
caronc#202: Add tests for nody not required
Browse files Browse the repository at this point in the history
  • Loading branch information
phantom committed Jul 11, 2024
1 parent 0a4606f commit 6abd08e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
37 changes: 37 additions & 0 deletions apprise_api/api/tests/test_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

32 changes: 32 additions & 0 deletions apprise_api/api/tests/test_stateless_notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6abd08e

Please sign in to comment.