Skip to content

Commit

Permalink
Added unit tests and fixed a few small bugs with Sms and Redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Conroy committed Feb 12, 2010
1 parent 4bba819 commit b514ec8
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
95 changes: 95 additions & 0 deletions tests/twimltests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion twilio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
Expand Down

0 comments on commit b514ec8

Please sign in to comment.