8000 Next gen twiml by jingming · Pull Request #316 · twilio/twilio-python · GitHub
[go: up one dir, main page]

Skip to content

Next gen twiml #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file < 8000 /div>
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Throw exception on appending non-TwiML
  • Loading branch information
jingming committed Mar 7, 2017
commit 664c1fbc33cafc147ef56227fa054348e3339a98
8 changes: 8 additions & 0 deletions tests/unit/twiml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import unittest

from nose.tools import raises
from six import text_type

from twilio.twiml import TwiMLException, TwiML


class TwilioTest(unittest.TestCase):
def strip(self, xml):
return text_type(xml)

@raises(TwiMLException)
def test_append_fail(self):
t = TwiML()
t.append('foobar')
24 changes: 20 additions & 4 deletions twilio/twiml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def lower_camel(string):
return result[0].lower() + result[1:]


class TwiMLException(Exception):
pass


class TwiML(object):
"""
Twilio basic verb object.
Expand Down Expand Up @@ -50,7 +54,23 @@ def to_xml(self, xml_declaration=True):
else:
return xml

def append(self, verb):
"""
Add a TwiML doc
:param verb: TwiML Document
:return:
"""
if not isinstance(verb, TwiML):
raise TwiMLException()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a message like "can't nest responses".


self.verbs.append(verb)
return self

def xml(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or prefix with _ if not public

"""
Convert to XML
:return: Generated TwiML
"""
el = ET.Element(self.name)

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

return el

def append(self, verb):
self.verbs.append(verb)
return self
0