Skip to content

Commit 2f852bf

Browse files
Merge pull request #4 from pusher/test-errors-correctly-not-json
Test that the SDK errors correctly if the server error is not JSON
2 parents 32ddedb + 6acd771 commit 2f852bf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_push_notifications.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,29 @@ def test_publish_should_raise_on_http_404_error(self):
400400
},
401401
)
402402
self.assertIn('Instance not found: blah', str(e.exception))
403+
404+
405+
def test_publish_should_error_correctly_if_error_not_json(self):
406+
pn_client = PushNotifications(
407+
'INSTANCE_ID',
408+
'SECRET_KEY'
409+
)
410+
with requests_mock.Mocker() as http_mock:
411+
http_mock.register_uri(
412+
requests_mock.ANY,
413+
requests_mock.ANY,
414+
status_code=500,
415+
text='<notjson></notjson>',
416+
)
417+
with self.assertRaises(PusherServerError) as e:
418+
pn_client.publish(
419+
interests=['donuts'],
420+
publish_body={
421+
'apns': {
422+
'aps': {
423+
'alert': 'Hello World!',
424+
},
425+
},
426+
},
427+
)
428+
self.assertIn('Unknown error: no description', str(e.exception))

0 commit comments

Comments
 (0)