8000 Merge pull request #316 from twilio/next-gen-twiml · DropByDrop/twilio-python@b3e48e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b3e48e6

Browse files
authored
Merge pull request twilio#316 from twilio/next-gen-twiml
Next gen twiml
2 parents 8e47d61 + ed160fd commit b3e48e6

File tree

9 files changed

+1570
-1171
lines changed

9 files changed

+1570
-1171
lines changed

tests/unit/test_twiml.py

Lines changed: 0 additions & 593 deletions
This file was deleted.

tests/unit/twiml/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
3+
from nose.tools import raises
4+
from six import text_type
5+
6+
from twilio.twiml import TwiMLException, TwiML
7+
8+
9+
class TwilioTest(unittest.TestCase):
10+
def strip(self, xml):
11+
return text_type(xm 10000 l)
12+
13+
@raises(TwiMLException)
14+
def test_append_fail(self):
15+
t = TwiML()
16+
t.append('foobar')
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from nose.tools import assert_equal
2+
from tests.unit.twiml import TwilioTest
3+
from twilio.twiml.messaging_response import MessagingResponse, Body, Media
4+
5+
6+
class TestResponse(TwilioTest):
7+
8+
def test_empty_response(self):
9+
r = MessagingResponse()
10+
assert_equal(
11+
self.strip(r),
12+
'<?xml version="1.0" encoding="UTF-8"?><Response />'
13+
)
14+
15+
def test_response(self):
16+
r = MessagingResponse()
17+
r.message('Hello')
18+
r.redirect(url='example.com')
19+
20+
assert_equal(
21+
self.strip(r),
22+
'<?xml version="1.0" encoding="UTF-8"?><Response><Message>Hello</Message><Redirect url="example.com" /></Response>'
23+
)
24+
25+
def test_response_chain(self):
26+
r = MessagingResponse().message('Hello').redirect(url='example.com')
27+
28+
assert_equal(
29+
self.strip(r),
30+
'<?xml version="1.0" encoding="UTF-8"?><Response><Message>Hello</Message><Redirect url="example.com" /></Response>'
31+
)
32+
33+
34+
class TestMessage(TwilioTest):
35+
36+
def test_body(self):
37+
r = MessagingResponse()
38+
r.message('Hello')
39+
40+
assert_equal(
41+
self.strip(r),
42+
'<?xml version="1.0" encoding="UTF-8"?><Response><Message>Hello</Message></Response>'
43+
)
44+
45+
def test_nested_body(self):
46+
b = Body('Hello World')
47+
48+
r = MessagingResponse()
49+
r.append(b)
50+
51+
assert_equal(
52+
self.strip(r),
53+
'<?xml version="1.0" encoding="UTF-8"?><Response><Body>Hello World</Body></Response>'
54+
)
55+
56+
def test_nested_body_media(self):
57+
b = Body('Hello World')
58+
m = Media('hey.jpg')
59+
60+
r = MessagingResponse()
61+
r.append(b)
62+
r.append(m)
63+
64+
assert_equal(
65+
self.strip(r),
66+
'<?xml version="1.0" encoding="UTF-8"?><Response><Body>Hello World</Body><Media>hey.jpg</Media></Response>'
67+
)
68+
69+
70+
class TestRedirect(TwilioTest):
71+
def test_redirect(self):
72+
r = MessagingResponse()
73+
r.redirect(url='example.com')
74+
75+
assert_equal(
76+
self.strip(r),
77+
'<?xml version="1.0" encoding="UTF-8"?><Response><Redirect url="example.com" /></Response>'
78+
)

0 commit comments

Comments
 (0)
0