File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change 1
1
import unittest
2
2
3
+ from nose .tools import raises
3
4
from six import text_type
4
5
6
+ from twilio .twiml import TwiMLException , TwiML
7
+
5
8
6
9
class TwilioTest (unittest .TestCase ):
7
10
def strip (self , xml ):
8
11
return text_type (xml )
12
+
13
+ @raises (TwiMLException )
14
+ def test_append_fail (self ):
15
+ t = TwiML ()
16
+ t .append ('foobar' )
Original file line number Diff line number Diff line change @@ -9,6 +9,10 @@ def lower_camel(string):
9
9
return result [0 ].lower () + result [1 :]
10
10
11
11
12
+ class TwiMLException (Exception ):
13
+ pass
14
+
15
+
12
16
class TwiML (object ):
13
17
"""
14
18
Twilio basic verb object.
@@ -50,7 +54,23 @@ def to_xml(self, xml_declaration=True):
50
54
else :
51
55
return xml
52
56
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
+
53
69
def xml (self ):
70
+ """
71
+ Convert to XML
72
+ :return: Generated TwiML
73
+ """
54
74
el = ET .Element (self .name )
55
75
56
76
keys = self .attrs .keys ()
@@ -70,7 +90,3 @@ def xml(self):
70
90
el .append (verb .xml ())
71
91
72
92
return el
73
-
74
- def append (self , verb ):
75
- self .verbs .append (verb )
76
- return self
You can’t perform that action at this time.
0 commit comments