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

Commit

Permalink
Handle missing config better in http_api_nostream.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Dec 6, 2013
1 parent b64d54a commit 9a1558b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
53 changes: 25 additions & 28 deletions go/apps/http_api_nostream/tests/test_vumi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,21 @@ def raiser(*args, **kw):
raise exception_class()
self.patch(vumi_app, 'http_request_full', raiser)

@inlineCallbacks
def test_post_inbound_message_no_url(self):
self.conversation.config['http_api_nostream'].update({
'push_message_url': None,
})
yield self.conversation.save()

msg = self.msg_helper.make_inbound('in 1', message_id='1')
with LogCatcher(message='URL not configured') as lc:
yield self.dispatch_to_conv(msg, self.conversation)
[url_not_configured_log] = lc.messages()
self.assertTrue('push_message_url' in url_not_configured_log)

@inlineCallbacks
def test_post_inbound_message_unsupported_scheme(self):
# Set the URL so stuff is HTTP Posted instead of streamed.
self.conversation.config['http_api_nostream'].update({
'push_message_url': 'example.com',
})
Expand All @@ -405,12 +417,6 @@ def test_post_inbound_message_unsupported_scheme(self):

@inlineCallbacks
def test_post_inbound_message_timeout(self):
# Set the URL so stuff is HTTP Posted instead of streamed.
self.conversation.config['http_api_nostream'].update({
'push_message_url': self.mock_push_server.url,
})
yield self.conversation.save()

self._patch_http_request_full(HttpTimeoutError)
msg = self.msg_helper.make_inbound('in 1', message_id='1')
with LogCatcher(message='Timeout') as lc:
Expand All @@ -420,12 +426,6 @@ def test_post_inbound_message_timeout(self):

@inlineCallbacks
def test_post_inbound_message_dns_lookup_error(self):
# Set the URL so stuff is HTTP Posted instead of streamed.
self.conversation.config['http_api_nostream'].update({
'push_message_url': self.mock_push_server.url,
})
yield self.conversation.save()

self._patch_http_request_full(DNSLookupError)
msg = self.msg_helper.make_inbound('in 1', message_id='1')
with LogCatcher(message='DNS lookup error') as lc:
Expand All @@ -435,12 +435,6 @@ def test_post_inbound_message_dns_lookup_error(self):

@inlineCallbacks
def test_post_inbound_event(self):
# Set the URL so stuff is HTTP Posted instead of streamed.
self.conversation.config['http_api_nostream'].update({
'push_event_url': self.mock_push_server.url,
})
yield self.conversation.save()

msg1 = yield self.msg_helper.make_stored_outbound(
self.conversation, 'out 1', message_id='1')
ack1 = self.msg_helper.make_ack(msg1)
Expand All @@ -454,13 +448,22 @@ def test_post_inbound_event(self):
self.assertEqual(TransportEvent.from_json(posted_json_data), ack1)

@inlineCallbacks
def test_post_inbound_event_timeout(self):
# Set the URL so stuff is HTTP Posted instead of streamed.
def test_post_inbound_event_no_url(self):
self.conversation.config['http_api_nostream'].update({
'push_event_url': self.mock_push_server.url,
'push_event_url': None,
})
yield self.conversation.save()

msg1 = yield self.msg_helper.make_stored_outbound(
self.conversation, 'out 1', message_id='1')
ack1 = self.msg_helper.make_ack(msg1)
with LogCatcher(message='URL not configured') as lc:
yield self.dispatch_event_to_conv(ack1, self.conversation)
[url_not_configured_log] = lc.messages()
self.assertTrue('push_event_url' in url_not_configured_log)

@inlineCallbacks
def test_post_inbound_event_timeout(self):
msg1 = yield self.msg_helper.make_stored_outbound(
self.conversation, 'out 1', message_id='1')
ack1 = self.msg_helper.make_ack(msg1)
Expand All @@ -473,12 +476,6 @@ def test_post_inbound_event_timeout(self):

@inlineCallbacks
def test_post_inbound_event_dns_lookup_error(self):
# Set the URL so stuff is HTTP Posted instead of streamed.
self.conversation.config['http_api_nostream'].update({
'push_event_url': self.mock_push_server.url,
})
yield self.conversation.save()

msg1 = yield self.msg_helper.make_stored_outbound(
self.conversation, 'out 1', message_id='1')
ack1 = self.msg_helper.make_ack(msg1)
Expand Down
6 changes: 6 additions & 0 deletions go/apps/http_api_nostream/vumi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ def consume_user_message(self, message):

push_message_url = self.get_api_config(conversation,
'push_message_url')
if push_message_url is None:
log.warning("URL not configured: push_message_url")
return
yield self.push(push_message_url, message)

@inlineCallbacks
Expand All @@ -89,6 +92,9 @@ def consume_unknown_event(self, event):
config = yield self.get_message_config(event)
conversation = config.get_conversation()
push_event_url = self.get_api_config(conversation, 'push_event_url')
if push_event_url is None:
log.warning("URL not configured: push_event_url")
return
yield self.push(push_event_url, event)

@inlineCallbacks
Expand Down

0 comments on commit 9a1558b

Please sign in to comment.