Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Add test for failed http_request_full retry.
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Aug 3, 2015
1 parent b2351d7 commit 1715034
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions go/apps/http_api_nostream/tests/test_vumi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,16 @@ def test_post_inbound_message_ignored(self):
req = yield self.push_calls.get()
self.assertEqual(req, None)

def _patch_http_request_full(self, exception_class):
from go.apps.http_api_nostream import vumi_app
http_calls = []

def raiser(*args, **kw):
http_calls.append((args, kw))
raise exception_class()
self.patch(vumi_app, 'http_request_full', raiser)
return http_calls

@inlineCallbacks
def test_post_inbound_message_201_response(self):
yield self.start_app_worker()
Expand Down Expand Up @@ -913,6 +923,38 @@ def test_post_inbound_message_500_schedule_retry_failed_500(self):
% (retry_data,),
])

@inlineCallbacks
def test_post_inbound_message_500_schedule_retry_exception(self):
retry_url, retry_calls = yield self.start_retry_server()
yield self.start_app_worker({
'http_retry_api': retry_url,
})
msg_d = self.app_helper.make_dispatch_inbound(
'in 1', message_id='1', conv=self.conversation)

# return 500 response to message push
req = yield self.push_calls.get()
req.setResponseCode(500)
req.finish()

class TestException(Exception):
"""Custom test exception."""

http_calls = self._patch_http_request_full(TestException)

with LogCatcher(log_level=logging.WARNING) as lc:
yield msg_d

[(_, http_kw)] = http_calls
self.assertEqual(lc.messages(), [
"Got unexpected response code 500 from %s"
% self.get_message_url(),
"Error scheduling retry of request [account: u'test-0-user'"
", request: %r, error: TestException()]" % (http_kw['data'],),
])

self.assertEqual(retry_calls.pending, [])

@inlineCallbacks
def test_post_inbound_message_300_does_not_schedule_retry(self):
retry_url, retry_calls = yield self.start_retry_server()
Expand All @@ -933,13 +975,6 @@ def test_post_inbound_message_300_does_not_schedule_retry(self):
self.assertEqual(lc.messages(), [])
self.assertEqual(retry_calls.pending, [])

def _patch_http_request_full(self, exception_class):
from go.apps.http_api_nostream import vumi_app

def raiser(*args, **kw):
raise exception_class()
self.patch(vumi_app, 'http_request_full', raiser)

@inlineCallbacks
def test_post_inbound_message_no_url(self):
yield self.start_app_worker()
Expand Down

0 comments on commit 1715034

Please sign in to comment.