File tree Expand file tree Collapse file tree 3 files changed +35
-16
lines changed Expand file tree Collapse file tree 3 files changed +35
-16
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def strip(self, xml):
18
18
@raises (TwiMLException )
19
19
def test_append_fail (self ):
20
20
t = TwiML ()
21
- t .append ('foobar' )
21
+ t .append (12345 )
22
22
23
23
def test_format_language_none (self ):
24
24
language = None
Original file line number Diff line number Diff line change @@ -88,3 +88,24 @@ def test_redirect(self):
88
88
self .strip (r ),
89
89
'<?xml version="1.0" encoding="UTF-8"?><Response><Redirect>example.com</Redirect></Response>'
90
90
)
91
+
92
+ class TestTest (TwilioTest ):
93
+ def test_text (self ):
94
+ r = MessagingResponse ()
95
+ r .append ('No tags!' )
96
+
97
+ assert_equal (
98
+ self .strip (r ),
99
+ '<?xml version="1.0" encoding="UTF-8"?><Response>No tags!</Response>'
100
+ )
101
+
102
+ def text_mixed (self ):
103
+ r = MessagingResponse ()
104
+ r .append ('before' )
105
+ r .append (Body ('Content' ))
106
+ r .append ('after' )
107
+
108
+ assert_equal (
109
+ self .strip (r ),
110
+ '<?xml version="1.0" encoding="UTF-8"?><Response>before<Body>Content</Body>after</Response>'
111
+ )
Original file line number Diff line number Diff line change 1
- # coding=utf-8
2
- """
3
- This code was generated by
4
- \ / _ _ _| _ _
5
- | (_)\/(_)(_|\/| |(/_ v1.0.0
6
- / /
7
- """
8
-
9
1
import json
10
2
import re
11
3
import xml .etree .ElementTree as ET
@@ -79,10 +71,7 @@ def append(self, verb):
79
71
80
72
:returns: self
81
73
"""
82
- if not isinstance (verb , TwiML ):
83
- raise TwiMLException ('Only appending of TwiML is allowed' )
84
-
85
- self .verbs .append (verb )
74
+ self .nest (verb )
86
75
return self
87
76
88
77
def nest (self , verb ):
@@ -93,8 +82,8 @@ def nest(self, verb):
93
82
94
83
:returns: the TwiML verb
95
84
"""
96
- if not isinstance (verb , TwiML ):
97
- raise TwiMLException ('Only nesting of TwiML is allowed' )
85
+ if not isinstance (verb , TwiML ) and not isinstance ( verb , str ) :
86
+ raise TwiMLException ('Only nesting of TwiML and strings are allowed' )
98
87
99
88
self .verbs .append (verb )
100
89
return verb
@@ -118,7 +107,16 @@ def xml(self):
118
107
119
108
el .text = self .value
120
109
110
+ last_child = None
111
+
121
112
for verb in self .verbs :
122
- el .append (verb .xml ())
113
+ if isinstance (verb , str ):
114
+ if last_child :
115
+ last_child .tail = verb
116
+ else :
117
+ el .text = verb
118
+ else :
119
+ last_child = verb .xml ()
120
+ el .append (last_child )
123
121
124
122
return el
You can’t perform that action at this time.
0 commit comments