8000 Add unit tests · jstacoder/twilio-python@bab5f05 · GitHub
[go: up one dir, main page]

Skip to content

Commit bab5f05

Browse files
committed
Add unit tests
1 parent 0af4776 commit bab5f05

File tree

3 files changed

+590
-0
lines changed

3 files changed

+590
-0
lines changed

tests/unit/twiml/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import unittest
2+
3+
from six import text_type
4+
5+
6+
class TwilioTest(unittest.TestCase):
7+
def strip(self, xml):
8+
return text_type(xml)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
26+
class TestMessage(TwilioTest):
27+
28+
def test_body(self):
29+
r = MessagingResponse()
30+
r.message('Hello')
31+
32+
assert_equal(
33+
self.strip(r),
34+
'<?xml version="1.0" encoding="UTF-8"?><Response><Message>Hello</Message></Response>'
35+
)
36+
37+
def test_nested_body(self):
38+
b = Body('Hello World')
39+
40+
r = MessagingResponse()
41+
r.append(b)
42+
43+
assert_equal(
44+
self.strip(r),
45+
'<?xml version="1.0" encoding="UTF-8"?><Response><Body>Hello World</Body></Response>'
46+
)
47+
48+
def test_nested_body_media(self):
49+
b = Body('Hello World')
50+
m = Media('hey.jpg')
51+
52+
r = MessagingResponse()
53+
r.append(b)
54+
r.append(m)
55+
56+
assert_equal(
57+
self.strip(r),
58+
'<?xml version="1.0" encoding="UTF-8"?><Response><Body>Hello World</Body><Media>hey.jpg</Media></Response>'
59+
)
60+
61+
62+
class TestRedirect(TwilioTest):
63+
def test_redirect(self):
64+
r = MessagingResponse()
65+
r.redirect(url='example.com')
66+
67+
assert_equal(
68+
self.strip(r),
69+
'<?xml version="1.0" encoding="UTF-8"?><Response><Redirect url="example.com" /></Response>'
70+
)

0 commit comments

Comments
 (0)
0