Skip to content

Instantly share code, notes, and snippets.

@atkinson
Created December 5, 2011 21:37
Show Gist options
  • Save atkinson/1435489 to your computer and use it in GitHub Desktop.
Save atkinson/1435489 to your computer and use it in GitHub Desktop.
tropo test
#!/usr/bin/env python
try:
import cjson as jsonlib
jsonlib.dumps = jsonlib.encode
jsonlib.loads = jsonlib.decode
except ImportError:
try:
from django.utils import simplejson as jsonlib
except ImportError:
try:
import simplejson as jsonlib
except ImportError:
import json as jsonlib
import unittest
import sys
sys.path = ['..'] + sys.path
from tropo import Choices, Say, Tropo
class TestTropoPython(unittest.TestCase):
"""
Class implementing a set of unit tests for TropoPython.
"""
TO = "8005551212"
MY_PHONE = "6021234567"
RECORDING_URL = "/receive_recording.py"
ID = "foo"
S3_URL = "http://s3.amazonaws.com/xxx_s3_bucket/hello.wav"
VOICE = 'Grace'
def test_voice(self):
"""
Test the "record" Tropo class method.
"""
tropo = Tropo()
url = "/receive_recording.py"
choices_obj = Choices("", terminator="#").json
tropo.say('This is a say', voice=self.VOICE)
tropo.record(say="This is a record", url=url,
choices=choices_obj, voice=self.VOICE)
rendered = tropo.RenderJson()
pretty_rendered = tropo.RenderJson(pretty=True)
print "===============test_record================="
print "render json: %s" % pretty_rendered
if __name__ == '__main__':
"""
Unit tests.
"""
if (0):
TO = "8005551212"
ID = "foo"
URL = "http://s3.amazonaws.com/xxx_s3_bucket/hello.wav"
tropo = Tropo()
tropo.ask("[5 digits]",
say = Say("Please enter a 5 digit zip code").json)
tropo.call (TO)
tropo.conference(ID)
tropo.hangup()
tropo.message ("Hello, World", TO)
tropo.on(event="continue",
next="http://example.com/weather.py",
say="Please hold.")
tropo.record(say="Please say something for posterity",
url=URL,
choices = Choices("", terminator="#").json)
tropo.redirect(ID)
tropo.reject(ID)
tropo.startRecording(URL)
tropo.stopRecording()
tropo.transfer(TO)
tropo.message("Hello, World",
TO,
channel='TEXT',
network='SMS')
else:
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment