[svn-commits] kharwell: testsuite/asterisk/trunk r3637 - in /asterisk/trunk/tests/pbx/call-...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Feb 11 14:16:09 CST 2013


Author: kharwell
Date: Mon Feb 11 14:16:05 2013
New Revision: 3637

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3637
Log:
Refactored the call files test.

The call files test was not taking advantage of the testing framework, thus it
duplicated much of the functionality found already in the framework.  Refactored
the call files test to use the testing framework (e.g. it now inherits from
TestCase) and the standard python logging facilities.

Reported by: Matt Jordan


Added:
    asterisk/trunk/tests/pbx/call-files/sample1.call
      - copied unchanged from r3617, asterisk/trunk/tests/pbx/call-files/sample.call
Removed:
    asterisk/trunk/tests/pbx/call-files/sample.call
Modified:
    asterisk/trunk/tests/pbx/call-files/configs/ast1/extensions.conf
    asterisk/trunk/tests/pbx/call-files/run-test

Modified: asterisk/trunk/tests/pbx/call-files/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/pbx/call-files/configs/ast1/extensions.conf?view=diff&rev=3637&r1=3636&r2=3637
==============================================================================
--- asterisk/trunk/tests/pbx/call-files/configs/ast1/extensions.conf (original)
+++ asterisk/trunk/tests/pbx/call-files/configs/ast1/extensions.conf Mon Feb 11 14:16:05 2013
@@ -1,10 +1,12 @@
 [test]
 exten => agi1,1,Answer
-exten => agi1,n,AGI(agi://127.0.0.1:4601)
+exten => agi1,n,Set(AGISIGHUP=No)
+exten => agi1,n,AGI(agi://127.0.0.1:4573)
 exten => agi1,n,Hangup
 
 exten => agi2,1,Answer
-exten => agi2,n,AGI(agi://127.0.0.1:4602)
+exten => agi2,n,Set(AGISIGHUP=No)
+exten => agi2,n,AGI(agi://127.0.0.1:4573)
 exten => agi2,n,Hangup
 
 exten => wait,1,Answer

Modified: asterisk/trunk/tests/pbx/call-files/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/pbx/call-files/run-test?view=diff&rev=3637&r1=3636&r2=3637
==============================================================================
--- asterisk/trunk/tests/pbx/call-files/run-test (original)
+++ asterisk/trunk/tests/pbx/call-files/run-test Mon Feb 11 14:16:05 2013
@@ -9,108 +9,65 @@
 
 import sys
 import os
-import time
+import logging
+
 from twisted.internet import reactor
-from starpy import fastagi
 from shutil import move, copy
 
 sys.path.append("lib/python")
-from asterisk.asterisk import Asterisk
+from asterisk.TestCase import TestCase
 
-workingdir = "pbx/call-files"
-testdir = "tests/%s" % workingdir
+LOGGER = logging.getLogger(__name__)
 
-class CallFilesTest:
+TESTDIR = os.path.dirname(os.path.realpath(__file__))
+
+class CallFilesTest(TestCase):
+
+    num_tests = 2
+
     def __init__(self):
-        self.passed = False
-        self.results = [ False, False ]
-        self.stopping = False
+        super(CallFilesTest, self).__init__()
 
-        # Test timeout in seconds
-        self.timeout = 30
+        self.test = 0
+        self.create_asterisk()
 
-        self.ast1 = Asterisk(base=workingdir)
-        self.ast1.install_configs("%s/configs/ast1" % (testdir))
+    def run(self):
+        super(CallFilesTest, self).run()
 
-        self.agi_factory1 = fastagi.FastAGIFactory(self.get_result1)
-        self.agi_factory2 = fastagi.FastAGIFactory(self.get_result2)
-        reactor.listenTCP(4601, self.agi_factory1,
-                          self.timeout, '127.0.0.1')
-        reactor.listenTCP(4602, self.agi_factory2,
-                          self.timeout, '127.0.0.1')
-        reactor.callWhenRunning(self.run)
+        self.create_fastagi_factory()
+        self.launch_test()
 
-    def get_result(self, testIndex, agi):
-        print "Got AGI connection from dialplan: Success."
-        self.results[testIndex-1] = True
-        if not (False in self.results):
-            self.passed = True
-            reactor.callLater(2, self.end)
-        return agi.finish()
+    def fastagi_connect(self, agi):
+        LOGGER.info("sample%s.call file executed." % (self.test))
 
-    def get_result1(self, agi):
-        self.get_result(1, agi)
+        if self.test < self.num_tests:
+            self.launch_test()
+        else: self.finalize()
 
-    def get_result2(self, agi):
-        self.get_result(2, agi)
+    def move_file(self, i):
+        LOGGER.info("Moving the sample%s.call file to the spool dir..." % (i))
 
-    def start_asterisk(self):
-        print "Starting Asterisk"
-        self.ast1.start()
+        copy("%s/sample%s.call" % (TESTDIR, i),
+             "%s/etc/sample%s.call" % (self.ast[0].base, i))
 
-    def stop_asterisk(self):
-        self.ast1.stop()
+        move("%s/etc/sample%s.call" % (self.ast[0].base, i), "%s%s/outgoing/" %
+             (self.ast[0].base, self.ast[0].directories["astspooldir"]))
 
     def launch_test(self):
-        for i in [ "", "2" ]:
-            print "Moving the sample%s.call file to the spool dir..." % (i)
+        self.test += 1
+        self.move_file(self.test)
 
-            copy("%s/sample%s.call" % (testdir, i),
-                 "%s/etc/sample%s.call" % (self.ast1.base, i))
-
-            move("%s/etc/sample%s.call" % (self.ast1.base, i),
-                 "%s%s/outgoing/" %
-                 (self.ast1.base,
-                  self.ast1.directories["astspooldir"]))
-
-    def run(self):
-        self.start_asterisk()
-
-        reactor.callLater(5, self.launch_test)
-        reactor.callLater(self.timeout, self.abort)
-
-    def abort(self):
-        if self.stopping: return
-        print "Aborting..."
-        self.end()
-
-    def end(self):
-        self.stopping = True
-
-        if reactor.running:
-            reactor.stop()
-
-        self.stop_asterisk()
-
-        print "Test 1 (Call File w/ Application) ... ",
-        if self.results[0]:
-            print "Passed"
-        else:
-            print "Failed"
-
-        print "Test 2 (Call File w/ Extension)   ... ",
-        if self.results[1]:
-            print "Passed"
-        else:
-            print "Failed"
+    def finalize(self):
+        self.passed = True
+        self.stop_reactor()
 
 def main():
-    # Run call-files test
-    call_files_test = CallFilesTest()
+    test = CallFilesTest()
     reactor.run()
 
-    if call_files_test.passed != True:
+    if not test.passed:
         return 1
+
     return 0
 
 if __name__ == "__main__":




More information about the svn-commits mailing list