Beispiel #1
0
def Twilio_record_complete(request):
	import cPickle

	# Save debugging data
	sid = request.POST['CallSid']
	status = request.POST['CallStatus']

	log = TwilioCallGatherTest.objects.get(callid=sid)
	log.recordingurl = request.POST['RecordingUrl']

	debugData = cPickle.loads(log.debug_data.encode('ascii'))
	newEntry = ['Twilio_record_complete', cPickle.dumps(request.POST)]
	debugData.append(newEntry)
	log.debug_data = cPickle.dumps(debugData)

	log.save()

	# We don't care about which session this is associated with as all
	# verification is the same across all sessions.
	r = twilio.Response()
	say = twilio.Say("Thank you. Goodbye.", voice=twilio.Say.MAN, language=twilio.Say.ENGLISH)
	r.append(say)
	hangup = twilio.Hangup()
	r.append(hangup)

	debugData.append(str(r))
	log.debug_data = cPickle.dumps(debugData)
	log.save()

	return HttpResponse(str(r), mimetype=settings.TWILIO_RESPONSE_MIMETYPE)
Beispiel #2
0
 def testEmptySay(self):
     """should be a say with no text"""
     r = Response()
     r.append(twiml.Say(""))
     self.assertEquals(
         self.strip(r),
         '<?xml version="1.0" encoding="UTF-8"?><Response><Say /></Response>'
     )
Beispiel #3
0
 def testSayFrench(self):
     """should say hello monkey"""
     r = Response()
     r.append(twiml.Say(u"nécessaire et d'autres"))
     self.assertEquals(
         unicode(r),
         '<?xml version="1.0" encoding="UTF-8"?><Response><Say>n&#233;cessaire et d\'autres</Say></Response>'
     )
Beispiel #4
0
 def testSayLoopGreatBritian(self):
     """should say have a woman say hello monkey and loop 3 times"""
     r = Response()
     r.append(twiml.Say("Hello Monkey", language="en-gb"))
     r = self.strip(r)
     self.assertEquals(
         r,
         '<?xml version="1.0" encoding="UTF-8"?><Response><Say language="en-gb">Hello Monkey</Say></Response>'
     )
Beispiel #5
0
 def testSayLoop(self):
     """should say hello monkey and loop 3 times"""
     r = Response()
     r.append(twiml.Say("Hello Monkey", loop=3))
     r = self.strip(r)
     self.assertEquals(
         r,
         '<?xml version="1.0" encoding="UTF-8"?><Response><Say loop="3">Hello Monkey</Say></Response>'
     )
Beispiel #6
0
 def testSayHelloWorld(self):
     """should say hello monkey"""
     r = Response()
     r.append(twiml.Say("Hello World"))
     r = self.strip(r)
     self.assertEquals(
         r,
         '<?xml version="1.0" encoding="UTF-8"?><Response><Say>Hello World</Say></Response>'
     )
Beispiel #7
0
 def testSayLoopWoman(self):
     """ should say have a woman say hello monkey and loop 3 times """
     r = Response()
     r.append(twiml.Say("Hello Monkey", loop=3, voice=twiml.Say.WOMAN))
     r = self.strip(r)
     assert_equal(
         r,
         '<?xml version="1.0" encoding="UTF-8"?><Response><Say loop="3" voice="woman">Hello Monkey</Say></Response>'
     )
Beispiel #8
0
 def testNestedSayPlayPause(self):
     """ a gather with a say, play, and pause """
     r = Response()
     g = twiml.Gather()
     g.append(twiml.Say("Hey"))
     g.append(twiml.Play("hey.mp3"))
     g.append(twiml.Pause())
     r.append(g)
     r = self.strip(r)
     assert_equal(r, '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><Say>Hey</Say><Play>hey.mp3</Play><Pause /></Gather></Response>')
Beispiel #9
0
 def testSayFrench(self):
     """should say hello monkey"""
     r = Response()
     r.append(
         twiml.Say(u("n\xe9cessaire et d'autres"))
     )  # it works on python 2.6 with the from __future__ import unicode_literal
     self.assertEquals(
         text_type(r),
         '<?xml version="1.0" encoding="UTF-8"?><Response><Say>n&#233;cessaire et d\'autres</Say></Response>'
     )
Beispiel #10
0
 def improperAppend(self, verb):
     self.assertRaises(TwimlException, verb.append, twiml.Say(""))
     self.assertRaises(TwimlException, verb.append, twiml.Gather())
     self.assertRaises(TwimlException, verb.append, twiml.Play(""))
     self.assertRaises(TwimlException, verb.append, twiml.Record())
     self.assertRaises(TwimlException, verb.append, twiml.Hangup())
     self.assertRaises(TwimlException, verb.append, twiml.Reject())
     self.assertRaises(TwimlException, verb.append, twiml.Redirect())
     self.assertRaises(TwimlException, verb.append, twiml.Dial())
     self.assertRaises(TwimlException, verb.append, twiml.Conference(""))
     self.assertRaises(TwimlException, verb.append, twiml.Sms(""))
     self.assertRaises(TwimlException, verb.append, twiml.Pause())
Beispiel #11
0
def Twilio_callGather_complete(request):
	import cPickle

	# Save debugging data
	sid = request.POST['CallSid']
	status = request.POST['CallStatus']
	key = request.POST['Digits']

	log = TwilioCallGatherTest.objects.get(callid=sid)

	debugData = cPickle.loads(log.debug_data.encode('ascii'))
	newEntry = ['Twilio_callGather_complete', cPickle.dumps(request.POST)]
	debugData.append(newEntry)
	log.debug_data = cPickle.dumps(debugData)

	log.save()

	# We don't care about which session this is associated with as all
	# verification is the same across all sessions.
	r = twilio.Response()
	if (key):
		say = twilio.Say("You pressed the %s key" % (key, ),
						voice=twilio.Say.MAN, language=twilio.Say.ENGLISH)
	else:
		say = twilio.Say("No key press was recorded.", 
						voice=twilio.Say.MAN, language=twilio.Say.ENGLISH)
	r.append(say)
	hangup = twilio.Hangup()
	r.append(hangup)

	log.success = log.success + '2'  # should be 11 or 101 here
	debugData.append(str(r))
	log.debug_data = cPickle.dumps(debugData)
	log.save()

	return HttpResponse(str(r), mimetype=settings.TWILIO_RESPONSE_MIMETYPE)
Beispiel #12
0
def Twilio_record(request):
	import cPickle

	# Save debugging data
	sid = request.POST['CallSid']
	status = request.POST['CallStatus']

	log = TwilioRecordTest.objects.get(callid=sid)

	if (not log.debug_data):
		debugData = []
	else:
		debugData = cPickle.loads(log.debug_data.encode('ascii'))
	newEntry = ['Twilio_record', cPickle.dumps(request.POST)]
	debugData.append(newEntry)
	log.debug_data = cPickle.dumps(debugData)

	log.save()

	# We don't care about which session this is associated with as all
	# verification is the same across all sessions.
	r = twilio.Response()
	say = twilio.Say("After the tone, please press 1, 2, and 3, then pound to finish.", 
			voice=twilio.Say.MAN, language=twilio.Say.ENGLISH)
	r.append(say)

	abs_uri = '://'.join([settings.SERVER_PROTOCOL, settings.SERVER_ADDRESS])
	url = reverse('MHLogin.tests.views.Twilio_record_complete')

	record = twilio.Record(
				action=urljoin(abs_uri, url),
				transcribe=False,
				finishOnKey='#',
				playBeep='true',
				timeout=30,
				)
	r.append(record)

	debugData.append(str(r))
	log.debug_data = cPickle.dumps(debugData)
	log.save()

	return HttpResponse(str(r), mimetype=settings.TWILIO_RESPONSE_MIMETYPE)
Beispiel #13
0
def Twilio_callGather(request):
	import cPickle

	# Save debugging data
	sid = request.POST['CallSid']
	status = request.POST['CallStatus']

	log = TwilioCallGatherTest.objects.get(callid=sid)

	if (not log.debug_data):
		debugData = []
	else:
		debugData = cPickle.loads(log.debug_data.encode('ascii'))
	newEntry = ['Twilio_callGather', cPickle.dumps(request.POST)]
	debugData.append(newEntry)
	log.debug_data = cPickle.dumps(debugData)

	log.save()

	# We don't care about which session this is associated with as all
	# verification is the same across all sessions.
	r = twilio.Response()
	if (status != 'completed'):
		abs_uri = '://'.join([settings.SERVER_PROTOCOL, settings.SERVER_ADDRESS])
		url = reverse('MHLogin.tests.views.Twilio_callGather_complete')

		gather = twilio.Gather(action=urljoin(abs_uri, url),
					numDigits=1, finishOnKey='', timeout=10)
		gather.append(twilio.Say("Please press the number one.", 
					voice=twilio.Say.MAN, language=twilio.Say.ENGLISH))
		r.append(gather)

	log.success = log.success + '1'  # should be 11 or 101 here
	debugData.append(str(r))
	log.debug_data = cPickle.dumps(debugData)
	log.save()

	return HttpResponse(str(r), mimetype=settings.TWILIO_RESPONSE_MIMETYPE)
Beispiel #14
0
 def testSayAddAttribute(self):
     """ add attribute """
     r = twiml.Say("", foo="bar")
     r = self.strip(r)
     assert_equal(r, '<?xml version="1.0" encoding="UTF-8"?><Say foo="bar" />')
Beispiel #15
0
 def testSayBadAppend(self):
     """ should raise exceptions for wrong appending """
     self.improperAppend(twiml.Say(""))