Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Add test for HTTP errors that are not opt out errors to still be raised.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudi Giesler committed Jan 22, 2015
1 parent 9070cd8 commit 2408854
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions go_http/tests/test_send.py
Expand Up @@ -9,6 +9,8 @@
from go_http.send import HttpApiSender, LoggingSender
from go_http.exceptions import UserOptedOutException

from requests.exceptions import HTTPError


class RecordingAdapter(TestAdapter):
""" Record the request that was handled by the adapter.
Expand Down Expand Up @@ -86,6 +88,27 @@ def test_send_to_opted_out(self):
self.assertEqual(
e.reason, 'Recipient with msisdn to-addr-1 has opted out')

def test_send_to_other_http_error(self):
"""
HTTP errors should not be raised as UserOptedOutExceptions if they are
not user opted out errors.
"""
self.session.mount(
"http://example.com/api/v1/go/http_api_nostream/conv-key/"
"messages.json", TestAdapter(
json.dumps({
"success": False,
"reason": "No unicorns were found"
}),
status=400))
try:
self.sender.send_text('to-addr-1', 'foo')
except HTTPError as e:
self.assertEqual(e.response.status_code, 400)
response = e.response.json()
self.assertFalse(response['success'])
self.assertEqual(response['reason'], "No unicorns were found")

def test_fire_metric(self):
adapter = RecordingAdapter(
json.dumps({"success": True, "reason": "Yay"}))
Expand Down

0 comments on commit 2408854

Please sign in to comment.