[asterisk-commits] pabelanger: branch pabelanger/testClass r1509 - in /asterisk/team/pabelanger/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 17 17:28:11 CDT 2011


Author: pabelanger
Date: Tue May 17 17:28:04 2011
New Revision: 1509

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=1509
Log:
Add fastagi factory to TestCase
Convert fastagi/connect to use TestCase

Added:
    asterisk/team/pabelanger/testClass/tests/fastagi/connect/configs/
      - copied from r1508, asterisk/team/pabelanger/testClass/tests/fastagi/configs/
Modified:
    asterisk/team/pabelanger/testClass/lib/python/asterisk/TestCase.py
    asterisk/team/pabelanger/testClass/runtests.py
    asterisk/team/pabelanger/testClass/tests/fastagi/connect/configs/ast1/manager.conf
    asterisk/team/pabelanger/testClass/tests/fastagi/connect/run-test

Modified: asterisk/team/pabelanger/testClass/lib/python/asterisk/TestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/pabelanger/testClass/lib/python/asterisk/TestCase.py?view=diff&rev=1509&r1=1508&r2=1509
==============================================================================
--- asterisk/team/pabelanger/testClass/lib/python/asterisk/TestCase.py (original)
+++ asterisk/team/pabelanger/testClass/lib/python/asterisk/TestCase.py Tue May 17 17:28:04 2011
@@ -8,15 +8,19 @@
 '''
 
 import sys
+import logging
 from optparse import OptionParser
 from twisted.internet import reactor
-from starpy import manager
+from starpy import manager, fastagi
 
 from asterisk import Asterisk
+
+log = logging.getLogger('TestCase')
 
 class TestCase(object):
     ast = []
     ami = []
+    fastagi = []
     reactor_timeout = 30
     passed = False
 
@@ -31,7 +35,7 @@
         parser = OptionParser()
         parser.add_option("-v", "--version", dest="ast_version",
                 help="Asterisk version string")
-        parser.add_option("--test-name", dest="test_name",
+        parser.add_option("-n", dest="test_name",
                 help="Test name")
         parser.add_option("--valgrind", action="store_true",
                 dest="valgrind", default=False,
@@ -78,6 +82,16 @@
             self.ami_factory.login(host).addCallbacks(self.ami_connect,
                     self.ami_login_error)
 
+    def create_fastagi_factory(self, count=1):
+
+        for c in range(count):
+            host = "127.0.0.%d" % (c + 1)
+            self.fastagi.append(None)
+            print "Creating FastAGI Factory %d ..." % (c + 1)
+            self.fastagi_factory = fastagi.FastAGIFactory(self.fastagi_connect)
+            reactor.listenTCP(4573, self.fastagi_factory,
+                    self.reactor_timeout, host)
+
     def start_asterisk(self):
         """
 

Modified: asterisk/team/pabelanger/testClass/runtests.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/pabelanger/testClass/runtests.py?view=diff&rev=1509&r1=1508&r2=1509
==============================================================================
--- asterisk/team/pabelanger/testClass/runtests.py (original)
+++ asterisk/team/pabelanger/testClass/runtests.py Tue May 17 17:28:04 2011
@@ -147,7 +147,7 @@
         cmd = [
             "%s/run-test" % self.test_name,
             "-v", str(self.ast_version),
-            "--test-name", str(self.test_name)
+            "-n", str(self.test_name)
         ]
         if self.options.valgrind:
             cmd.append("--valgrind")

Modified: asterisk/team/pabelanger/testClass/tests/fastagi/connect/configs/ast1/manager.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/pabelanger/testClass/tests/fastagi/connect/configs/ast1/manager.conf?view=diff&rev=1509&r1=1508&r2=1509
==============================================================================
--- asterisk/team/pabelanger/testClass/tests/fastagi/connect/configs/ast1/manager.conf (original)
+++ asterisk/team/pabelanger/testClass/tests/fastagi/connect/configs/ast1/manager.conf Tue May 17 17:28:04 2011
@@ -7,4 +7,3 @@
 secret = mysecret
 read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
 write = system,call,agent,user,config,command,reporting,originate
-

Modified: asterisk/team/pabelanger/testClass/tests/fastagi/connect/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/pabelanger/testClass/tests/fastagi/connect/run-test?view=diff&rev=1509&r1=1508&r2=1509
==============================================================================
--- asterisk/team/pabelanger/testClass/tests/fastagi/connect/run-test (original)
+++ asterisk/team/pabelanger/testClass/tests/fastagi/connect/run-test Tue May 17 17:28:04 2011
@@ -8,79 +8,37 @@
 '''
 
 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/connect"
-testdir = "tests/fastagi"
+from asterisk.TestCase import TestCase
 
 
-class FastAGIConnectTest:
+class FastAGIConnectTest(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")
-        (options, args) = parser.parse_args(argv)
-        self.ast_version = AsteriskVersion(options.ast_version)
+        self.create_asterisk()
+        self.create_fastagi_factory()
 
-        # 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))
-
-    # This gets invoked by the dialplan when the call is answered
-    # Disconnect agi and set test result values
-    def do_test(self, agi):
+    def fastagi_connect(self, agi):
         print "Connection established."
         self.passed = True
         self.result_changed()
         return agi.finish()
 
-    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()
-
     def launch_test(self):
         print "Originating call to begin test."
-        self.ast1.cli_originate("Local/501 at agitest extension echo at agitest")
+        self.ast[0].cli_originate("Local/501 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.stop_reactor()
 
     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