Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added unit tests and fixed a few small bugs with Sms and Redirect

  • Loading branch information...
commit b514ec8c542e423c895f2069d833aa18ef498e0b 1 parent 4bba819
Kyle Conroy authored
Showing with 96 additions and 1 deletion.
  1. +95 −0 tests/twimltests.py
  2. +1 −1  twilio.py
95 tests/twimltests.py
View
@@ -17,6 +17,7 @@ def improperAppend(self, verb):
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())
class TestResponse(TwilioTest):
@@ -270,6 +271,100 @@ def testConvienceMethod(self):
r.addDial()
r = self.strip(r)
self.assertEquals(r, '<Response><Dial/></Response>')
+
+ def testAddNumber(self):
+ """add a number to a dial"""
+ r = twilio.Response()
+ d = twilio.Dial()
+ d.append(twilio.Number("1231231234"))
+ r.append(d)
+ r = self.strip(r)
+ self.assertEquals(r, '<Response><Dial><Number>1231231234</Number></Dial></Response>')
+
+ def testAddNumberConvience(self):
+ """add a number to a dial, convience method"""
+ r = twilio.Response()
+ d = r.addDial()
+ d.addNumber("1231231234")
+ r = self.strip(r)
+ self.assertEquals(r, '<Response><Dial><Number>1231231234</Number></Dial></Response>')
+
+ def testAddConference(self):
+ """ add a conference to a dial"""
+ r = twilio.Response()
+ d = twilio.Dial()
+ d.append(twilio.Conference("My Room"))
+ r.append(d)
+ r = self.strip(r)
+ self.assertEquals(r, '<Response><Dial><Conference>My Room</Conference></Dial></Response>')
+
+ def testAddConferenceConvenceMethod(self):
+ """ add a conference to a dial, conviently"""
+ r = twilio.Response()
+ d = r.addDial()
+ d.addConference("My Room")
+ r = self.strip(r)
+ self.assertEquals(r, '<Response><Dial><Conference>My Room</Conference></Dial></Response>')
+
+ def testAddAttribute(self):
+ """add attribute"""
+ r = twilio.Conference("MyRoom",foo="bar")
+ r = self.strip(r)
+ self.assertEquals(r, '<Conference foo="bar">MyRoom</Conference>')
+
+
+ def testBadAppend(self):
+ """ should raise exceptions for wrong appending"""
+ self.improperAppend(twilio.Conference("Hello"))
+
+
+class TestGather(TwilioTest):
+
+ def testEmpty(self):
+ """ a gather with nothing inside"""
+ r = twilio.Response()
+ r.append(twilio.Gather())
+ r = self.strip(r)
+ self.assertEquals(r, '<Response><Gather/></Response>')
+
+ def testNestedSayPlayPause(self):
+ """ a gather with a say, play, and pause"""
+ r = twilio.Response()
+ g = twilio.Gather()
+ g.append(twilio.Say("Hey"))
+ g.append(twilio.Play("hey.mp3"))
+ g.append(twilio.Pause())
+ r.append(g)
+ r = self.strip(r)
+ self.assertEquals(r, '<Response><Gather><Say>Hey</Say><Play>hey.mp3</Play><Pause/></Gather></Response>')
+
+
+ def testNestedSayPlayPauseConvience(self):
+ """ a gather with a say, play, and pause"""
+ r = twilio.Response()
+ g = r.addGather()
+ g.addSay("Hey")
+ g.addPlay("hey.mp3")
+ g.addPause()
+ r = self.strip(r)
+ self.assertEquals(r, '<Response><Gather><Say>Hey</Say><Play>hey.mp3</Play><Pause/></Gather></Response>')
+
+ def testAddAttribute(self):
+ """add attribute"""
+ r = twilio.Gather(foo="bar")
+ r = self.strip(r)
+ self.assertEquals(r, '<Gather foo="bar"/>')
+
+ 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(""))
if __name__ == '__main__':
unittest.main()
2  twilio.py
View
@@ -299,7 +299,7 @@ class Redirect(Verb):
POST = 'POST'
def __init__(self, url=None, method=None, **kwargs):
- Verb.__init__(self, **kwargs)
+ Verb.__init__(self, method=method, **kwargs)
if method and (method != self.GET and method != self.POST):
raise TwilioException( \
"Invalid method parameter, must be 'GET' or 'POST'")
Please sign in to comment.
Something went wrong with that request. Please try again.