[svn-commits] espiceland: testsuite/asterisk/trunk r725 - /asterisk/trunk/tests/fastagi/rec...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Aug 16 11:02:12 CDT 2010
Author: espiceland
Date: Mon Aug 16 11:02:08 2010
New Revision: 725
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=725
Log:
Test for RECORD FILE using FastAGI.
Added:
asterisk/trunk/tests/fastagi/record-file/
asterisk/trunk/tests/fastagi/record-file/run-test (with props)
asterisk/trunk/tests/fastagi/record-file/test-config.yaml (with props)
Added: asterisk/trunk/tests/fastagi/record-file/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/record-file/run-test?view=auto&rev=725
==============================================================================
--- asterisk/trunk/tests/fastagi/record-file/run-test (added)
+++ asterisk/trunk/tests/fastagi/record-file/run-test Mon Aug 16 11:02:08 2010
@@ -1,0 +1,164 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2010, Digium, Inc.
+Erin Spiceland <espiceland at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+import os
+from optparse import OptionParser
+from twisted.internet import reactor
+from starpy import fastagi
+
+sys.path.append("lib/python")
+from asterisk.asterisk import Asterisk
+from asterisk.version import AsteriskVersion
+
+class FastAGIRecordFileTest:
+ def __init__(self, argv):
+ self.passed = {
+ "DTMF": False,
+ "HANGUP": False
+ }
+ self.test = "DTMF"
+ self.timeout = 45
+ self.key = "fastagitest"
+ self.overall_result = True
+ self.agi = ""
+
+ parser = OptionParser()
+ parser.add_option("-v", "--version", dest="ast_version",
+ help="Asterisk version string")
+ (options, args) = parser.parse_args(argv)
+ self.ast_version = AsteriskVersion(options.ast_version)
+
+ # Listen for results from dialplan
+ self.agi_factory = fastagi.FastAGIFactory(self.do_test)
+ reactor.listenTCP(4573, self.agi_factory, self.timeout, '127.0.0.1')
+ reactor.callWhenRunning(self.run)
+
+ print self.ast_version
+ self.asterisk=Asterisk(base="/tmp/asterisk-testsuite/fastagi/execute")
+ self.asterisk.install_configs("tests/fastagi/configs")
+
+ def on_record_failure(self, reason):
+ if os.path.exists("/tmp/asterisk-testsuite/fastagi/execute/out.ulaw"):
+ print "file exists"
+
+ print "file size is", os.path.getsize(
+ "/tmp/asterisk-testsuite/fastagi/execute/out.ulaw"
+ )
+ self.passed[self.test] = False
+ print 'Could not record file:', reason.getTraceback()
+ if self.test is "DTMF":
+ self.test = "HANGUP"
+ reactor.callLater(2, self.launch_test())
+ else:
+ self.result_changed()
+
+ def on_record_success(self, result):
+ try:
+ digit = chr(int(result[0]))
+ except:
+ digit = None
+
+ print "Recording terminated by %s (%s) after %s bytes."\
+ % (result[1], digit, result[2])
+ if os.path.exists("/tmp/asterisk-testsuite/fastagi/execute/out.ulaw"):
+ file_size = os.path.getsize(
+ "/tmp/asterisk-testsuite/fastagi/execute/out.ulaw"
+ )
+ if file_size == 0:
+ print "The file was created, but it is empty."
+ self.passed[self.test] = False
+ elif result[2] == file_size:
+ print "Data was recorded, and data length matches what was",\
+ "reported during the %s test." % self.test
+ self.passed[self.test] = True
+ else:
+ print "Some data was recorded, but the data length does not",\
+ "match what was reported during the %s test." % self.test
+ self.passed[self.test] = False
+ else:
+ print "The file doesn't exist."
+ self.passed[self.test] = False
+
+ if self.test is "DTMF":
+ self.test = "HANGUP"
+ reactor.callLater(2, self.launch_test)
+ else:
+ self.result_changed()
+
+ # This gets invoked by the dialplan when the call is answered
+ def do_test(self, agi):
+ self.agi = agi
+ return agi.recordFile(
+ "/tmp/asterisk-testsuite/fastagi/execute/out", "ulaw", "#", "3"
+ ).addCallback(
+ self.on_record_success
+ ).addErrback(self.on_record_failure)
+
+ # Read test results and dialplan globals
+ def read_result(self):
+ self.agi.finish()
+ for t, r in self.passed.iteritems():
+ if self.passed[t] is False:
+ print "RECORD FILE did NOT work as expected when",\
+ "terminated with", t
+ self.overall_result = False
+
+ self.stop_asterisk()
+ if reactor.running:
+ print "Stopping Reactor ..."
+ reactor.stop()
+
+ def launch_test(self):
+ self.asterisk.cli_exec("core set verbose 10")
+ self.asterisk.cli_exec("agi set debug on")
+ print "Originating call to begin test which terminates recording",\
+ "with", self.test
+ if self.test is "DTMF":
+ self.asterisk.cli_originate(
+ "Local/b_exten at agitest extension e_exten at agitest"
+ )
+ elif self.test is "HANGUP":
+ self.asterisk.cli_originate(
+ "Local/b_exten at agitest extension f_exten at agitest"
+ )
+ else:
+ self.result_changed()
+
+ def start_asterisk(self):
+ print "Starting Asterisk"
+ self.asterisk.start()
+
+ def stop_asterisk(self):
+ print "Stopping Asterisk"
+ self.asterisk.stop()
+
+ # Read result before timeout
+ def result_changed(self):
+ if self.passed['DTMF'] is True and self.passed['HANGUP'] is True:
+ reactor.callLater(2, self.read_result)
+
+ def run(self):
+ self.start_asterisk()
+ reactor.callLater(2, self.launch_test)
+ reactor.callLater(self.timeout, self.read_result)
+
+def main(argv=None):
+ if argv is None:
+ argv = sys.argv
+
+ agi_test = FastAGIRecordFileTest(argv)
+ reactor.run()
+ if agi_test.overall_result is not True:
+ return 1
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main() or 0)
Propchange: asterisk/trunk/tests/fastagi/record-file/run-test
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/fastagi/record-file/run-test
------------------------------------------------------------------------------
svn:executable = *
Propchange: asterisk/trunk/tests/fastagi/record-file/run-test
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/fastagi/record-file/run-test
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/fastagi/record-file/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/record-file/test-config.yaml?view=auto&rev=725
==============================================================================
--- asterisk/trunk/tests/fastagi/record-file/test-config.yaml (added)
+++ asterisk/trunk/tests/fastagi/record-file/test-config.yaml Mon Aug 16 11:02:08 2010
@@ -1,0 +1,12 @@
+testinfo:
+ summary: 'Test AGI RECORD FILE command using FastAGI.'
+ description: |
+ 'Test AGI RECORD FILE command using FastAGI.'
+
+
+properties:
+ minversion: '1.4'
+ dependencies:
+ - app : 'python'
+ - python : 'twisted'
+ - python : 'starpy'
Propchange: asterisk/trunk/tests/fastagi/record-file/test-config.yaml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/fastagi/record-file/test-config.yaml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/fastagi/record-file/test-config.yaml
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the svn-commits
mailing list