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)
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>' )
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écessaire et d\'autres</Say></Response>' )
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>' )
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>' )
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>' )
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>' )
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>')
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écessaire et d\'autres</Say></Response>' )
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())
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)
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)
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)
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" />')
def testSayBadAppend(self): """ should raise exceptions for wrong appending """ self.improperAppend(twiml.Say(""))