[asterisk-commits] pabelanger: testsuite/asterisk/trunk r1888 - in /asterisk/trunk/tests/fastagi...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 22 13:46:31 CDT 2011


Author: pabelanger
Date: Mon Aug 22 13:46:28 2011
New Revision: 1888

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1888
Log:
Update test to use TestCase class.

Added:
    asterisk/trunk/tests/fastagi/stream-file/configs/
      - copied from r1887, asterisk/trunk/tests/fastagi/connect/configs/
Modified:
    asterisk/trunk/tests/fastagi/stream-file/run-test

Modified: asterisk/trunk/tests/fastagi/stream-file/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/fastagi/stream-file/run-test?view=diff&rev=1888&r1=1887&r2=1888
==============================================================================
--- asterisk/trunk/tests/fastagi/stream-file/run-test (original)
+++ asterisk/trunk/tests/fastagi/stream-file/run-test Mon Aug 22 13:46:28 2011
@@ -8,93 +8,40 @@
 '''
 
 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
-
-workingdir = "/tmp/asterisk-testsuite/fastagi/stream-file"
-testdir = "tests/fastagi"
+from asterisk.TestCase import TestCase
 
 
-class FastAGIStreamFileTest:
+class FastAGIStreamFileTest(TestCase):
     def __init__(self, argv):
-        self.passed = False
-        self.timeout = 30
+        TestCase.__init__(self, argv)
 
-        parser = OptionParser()
-        parser.add_option("-v", "--version", dest="ast_version",
-                          help="Asterisk version string")
-        parser.add_option("-n", dest="test_name",
-                help="Test name")
-
-        (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)
-
-        self.ast1 = Asterisk(base=workingdir)
-        self.ast1.install_configs("%s/configs/ast1" % (testdir))
-
-    def on_failure(self, reason):
-        print 'Could not run streamFile: ', reason.getTraceback()
-        self.agi.finish()
+        self.create_asterisk()
+        self.create_fastagi_factory()
 
     # result of 0 indicates success
     def finish_test(self, result):
         if result[0] == 0 and result[1] > 100:
             self.passed = True
-
-        self.result_changed()
+        self.stop_reactor()
 
     # This gets invoked by the dialplan when the call is answered
     # send STREAM FILE command and wait for results
-    def do_test(self, agi):
-        self.agi = agi
+    def fastagi_connect(self, agi):
         print "Connection established."
         return agi.streamFile("beep", "").addCallback(
-            self.finish_test).addErrback(self.on_failure)
-
-    def read_result(self):
-        self.stop_reactor()
-
-        if self.passed is True:
-            print "Success"
-        else:
-            print "Failed"
-
-    def stop_reactor(self):
-        print "Stopping Reactor ..."
-        if reactor.running:
-            reactor.stop()
+            self.finish_test)
 
     def launch_test(self):
         print "Originating call to begin test."
-        self.ast1.cli_originate("Local/505 at agitest extension echo at agitest")
-
-    def start_asterisk(self):
-        print "Starting Asterisk"
-        self.ast1.start()
-
-    def stop_asterisk(self):
-        print "Stopping Asterisk"
-        self.ast1.stop()
-
-    # Read result before timeout
-    def result_changed(self):
-        if self.passed is True:
-            self.read_result()
+        self.ast[0].cli_originate("Local/505 at agitest extension echo at agitest")
 
     def run(self):
+        TestCase.run(self)
         self.launch_test()
-        reactor.callLater(self.timeout, self.stop_reactor)
 
 
 def main(argv=None):




More information about the asterisk-commits mailing list