Skip to content

Instantly share code, notes, and snippets.

@erikcw
Created October 27, 2011 21:08
Show Gist options
  • Save erikcw/1320881 to your computer and use it in GitHub Desktop.
Save erikcw/1320881 to your computer and use it in GitHub Desktop.
Unittest demonstrating attribute stripping.
import xml.etree.ElementTree as ET
from twilio import twiml
from django.test import TestCase
class TwimlTest(TestCase):
def test_twiml_conference_verb(self):
"""
Sanity check for TwiML generation.
"""
r = twiml.Response()
import ipdb; ipdb.set_trace()
with r.dial() as dial:
dial.conference("TestConferenceAttributes", beep=False, waitUrl="", startConferenceOnEnter=True, endConferenceOnExit=True)
xml = r.toxml()
#parse twiml XML string with Element Tree and inspect structure
tree = ET.fromstring(xml)
self.assertIsNotNone(tree.find(".//Dial/Conference"))
#check Conference tag attributes
conf = tree.find(".//Dial/Conference")
self.assertEqual(conf.text.strip(), "TestConferenceAttributes")
self.assertEqual(conf.get('beep'), "false")
self.assertEqual(conf.get('waitUrl'), "")
self.assertEqual(conf.get('startConferenceOnJoin'), "true")
self.assertEqual(conf.get('endConferenceOnExit'), "true")
@erikcw
Copy link
Author

erikcw commented Oct 27, 2011

Note that this tests both the problem with Twilio striping the False, 0, and '' attributes.

It also test the boolean uppercase issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment