8000 Throw exception on appending non-TwiML · jstacoder/twilio-python@664c1fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 664c1fb

Browse files
committed
Throw exception on appending non-TwiML
1 parent c374d0b commit 664c1fb

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

tests/unit/twiml/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import unittest
22

3+
from nose.tools import raises
34
from six import text_type
45

6+
from twilio.twiml import TwiMLException, TwiML
7+
58

69
class TwilioTest(unittest.TestCase):
710
def strip(self, xml):
811
return text_type(xml)
12+
13+
@raises(TwiMLException)
14+
def test_append_fail(self):
15+
t = TwiML()
16+
t.append('foobar')

twilio/twiml/__init__.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def lower_camel(string):
99
return result[0].lower() + result[1:]
1010

1111

12+
class TwiMLException(Exception):
13+
pass
14+
15+
1216
class TwiML(object):
1317
"""
1418
Twilio basic verb object.
@@ -50,7 +54,23 @@ def to_xml(self, xml_declaration=True):
5054
else:
5155
return xml
5256

57+
def append(self, verb):
58+
"""
59+
Add a TwiML doc
60+
:param verb: TwiML Document
61+
:return:
62+
"""
63+
if not isinstance(verb, TwiML):
64+
raise TwiMLException()
65+
66+
self.verbs.append(verb)
67+
return self
68+
5369
def xml(self):
70+
"""
71+
Convert to XML
72+
:return: Generated TwiML
73+
"""
5474
el = ET.Element(self.name)
5575

5676
keys = self.attrs.keys()
@@ -70,7 +90,3 @@ def xml(self):
7090
el.append(verb.xml())
7191

7292
return el
73-
74-
def append(self, verb):
75-
self.verbs.append(verb)
76-
return self

0 commit comments

Comments
 (0)
0