Skip to content

Commit

Permalink
Add tests for receiving call gather verb
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudi Giesler committed Apr 13, 2015
1 parent b4435d6 commit d7daad5
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions vumi_twilio_api/tests/test_twilio_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,105 @@ def test_receive_call_parsing_hangup_verb(self):
reply['session_event'], TransportUserMessage.SESSION_CLOSE)
self.assertEqual(reply['in_reply_to'], msg['message_id'])

@inlineCallbacks
def test_receive_call_parsing_gather_verb_defaults(self):
response = twiml.Response()
response.gather()
self.twiml_server.add_response('', response)

msg = self.app_helper.make_inbound(
'', from_addr='+54321', to_addr='+12345',
session_event=TransportUserMessage.SESSION_NEW)
yield self.app_helper.dispatch_inbound(msg)
[gather] = yield self.app_helper.wait_for_dispatched_outbound(1)
self.assertEqual(gather['helper_metadata']['voice']['wait_for'], '#')
self.assertEqual(gather['in_reply_to'], msg['message_id'])

@inlineCallbacks
def test_receive_call_parsing_gather_verb_nondefaults(self):
response = twiml.Response()
response.gather(action='/test_url', method='GET', finishOnKey='*')
self.twiml_server.add_response('', response)

msg = self.app_helper.make_inbound(
'', from_addr='+54321', to_addr='+12345',
session_event=TransportUserMessage.SESSION_NEW)
yield self.app_helper.dispatch_inbound(msg)
[gather] = yield self.app_helper.wait_for_dispatched_outbound(1)
self.assertEqual(gather['helper_metadata']['voice']['wait_for'], '*')
session = yield self.worker.session_manager.load_session('+54321')
self.assertEqual(session['Gather_Method'], 'GET')
self.assertEqual(
session['Gather_Action'], self.twiml_server.url + 'test_url')
self.assertEqual(gather['in_reply_to'], msg['message_id'])

@inlineCallbacks
def test_receive_call_parsing_gather_verb_with_subverbs(self):
response = twiml.Response()
with response.gather() as g:
g.play('test_url')
g.play('test_url2')
self.twiml_server.add_response('', response)

msg = self.app_helper.make_inbound(
'', from_addr='+54231', to_addr='+12345',
session_event=TransportUserMessage.SESSION_NEW)
yield self.app_helper.dispatch_inbound(msg)
[gather1, gather2] = yield self.app_helper.wait_for_dispatched_outbound(1)
self.assertEqual(
gather1['helper_metadata']['voice']['speech_url'], 'test_url')
self.assertEqual(
gather2['helper_metadata']['voice']['speech_url'], 'test_url2')
self.assertEqual(
gather2['helper_metadata']['voice']['wait_for'], '#')

@inlineCallbacks
def test_receive_call_parsing_gather_verb_with_reply(self):
response = twiml.Response()
response.gather(action='reply.xml')
self.twiml_server.add_response('', response)
response = twiml.Response()
response.play('test_url')
self.twiml_server.add_response('reply.xml', response)

msg = self.app_helper.make_inbound(
'', from_addr='+54231', to_addr='+12345',
session_event=TransportUserMessage.SESSION_NEW)
yield self.app_helper.dispatch_inbound(msg)
[rep] = yield self.app_helper.wait_for_dispatched_outbound(1)
reply = rep.reply('123')
yield self.app_helper.dispatch_inbound(reply)
[_, play] = yield self.app_helper.wait_for_dispatched_outbound(1)
self.assertEqual(
play['helper_metadata']['voice']['speech_url'], 'test_url')
request = self.twiml_server.requests[-1]
self.assertEqual(request['filename'], 'reply.xml')
self.assertEqual(request['request'].method, 'POST')
self.assertEqual(request['request'].args['Digits'], ['123'])

@inlineCallbacks
def test_receive_call_parsing_gather_verb_with_reply_get_request(self):
response = twiml.Response()
response.gather(action='reply.xml', method='GET')
self.twiml_server.add_response('', response)
response = twiml.Response()
response.play('test_url')
self.twiml_server.add_response('reply.xml', response)

msg = self.app_helper.make_inbound(
'', from_addr='+54231', to_addr='+12345',
session_event=TransportUserMessage.SESSION_NEW)
yield self.app_helper.dispatch_inbound(msg)
[rep] = yield self.app_helper.wait_for_dispatched_outbound(1)
reply = rep.reply('123')
yield self.app_helper.dispatch_inbound(reply)
[_, play] = yield self.app_helper.wait_for_dispatched_outbound(1)
self.assertEqual(
play['helper_metadata']['voice']['speech_url'], 'test_url')
request = self.twiml_server.requests[-1]
self.assertEqual(request['filename'], 'reply.xml')
self.assertEqual(request['request'].method, 'GET')

@inlineCallbacks
def test_outgoing_call_ended_status_callback(self):
self.twiml_server.add_response('callback.xml', twiml.Response())
Expand Down

0 comments on commit d7daad5

Please sign in to comment.