def testRedirectMethod(self): r = twilio.Response() r.append(twilio.Redirect(url="example.com", method="POST")) r = self.strip(r) self.assertEquals( r, '<Response><Redirect method="POST">example.com</Redirect></Response>' )
def testRedirectMethodGetParams(self): r = twilio.Response() r.append( twilio.Redirect(url="example.com?id=34&action=hey", method="POST")) r = self.strip(r) self.assertEquals( r, '<Response><Redirect method="POST">example.com?id=34&action=hey</Redirect></Response>' )
def testImproperNesting(self): """ bad nesting""" verb = twilio.Gather() self.assertRaises(twilio.TwilioException, verb.append, twilio.Gather()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Record()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Hangup()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Redirect()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Dial()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Conference("")) self.assertRaises(twilio.TwilioException, verb.append, twilio.Sms(""))
def improperAppend(self, verb): self.assertRaises(twilio.TwilioException, verb.append, twilio.Say("")) self.assertRaises(twilio.TwilioException, verb.append, twilio.Gather()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Play("")) self.assertRaises(twilio.TwilioException, verb.append, twilio.Record()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Hangup()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Redirect()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Dial()) self.assertRaises(twilio.TwilioException, verb.append, twilio.Conference("")) self.assertRaises(twilio.TwilioException, verb.append, twilio.Sms("")) self.assertRaises(twilio.TwilioException, verb.append, twilio.Pause())
# The same XML can be created above using the convenience methods r = twilio.Response() r.addSay("Hello World", voice=twilio.Say.MAN, language=twilio.Say.FRENCH, loop=10) r.addDial("4155551212", timeLimit=45) r.addPlay("http://www.mp3.com") print r # =========================================================================== # Using Gather, Redirect r = twilio.Response() g = r.append(twilio.Gather(numDigits=1)) g.append(twilio.Say("Press 1")) r.append(twilio.Redirect()) print r """ outputs: <Response> <Gather numDigits="1"> <Say>Press 1</Say> </Gather> <Redirect/> </Response> """ # =========================================================================== # Adding a Say verb multiple times r = twilio.Response() s = twilio.Say("Press 1") r.append(s)
def testBadAppend(self): """ should raise exceptions for wrong appending""" self.improperAppend(twilio.Redirect())
def testAddAttribute(self): """add attribute""" r = twilio.Redirect("", foo="bar") r = self.strip(r) self.assertEquals(r, '<Redirect foo="bar"/>')
def testRedirectEmpty(self): r = twilio.Response() r.append(twilio.Redirect()) r = self.strip(r) self.assertEquals(r, '<Response><Redirect/></Response>')
def redirect(self, url, method=HTTP_METHOD_GET): self.last_verb = twilio_official.Redirect(url, method) self.twilio_response.append(self.last_verb) return self