[asterisk-commits] mjordan: testsuite/asterisk/trunk r3013 - in /asterisk/trunk/tests/apps/voice...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 26 08:43:15 CST 2012


Author: mjordan
Date: Thu Jan 26 08:43:10 2012
New Revision: 3013

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3013
Log:
Make the bulk of the leave_voicemail tests AMI driven

This is again being done to take advantage of the TEST_FRAMEWORK's test AMI
event.  This makes these tests more stable.

Modified:
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/configs/ast2/extensions.conf
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/configs/ast2/extensions.conf
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/configs/ast2/extensions.conf
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/test-config.yaml

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/configs/ast2/extensions.conf?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/configs/ast2/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/configs/ast2/extensions.conf Thu Jan 26 08:43:10 2012
@@ -1,10 +1,21 @@
-; Tests exiting out of the VoiceMail application through various contexts
+[voicemailCaller]
 
-[sendvoicemail]
-    exten => 1234,1,NoOp()
-    same => n,Wait(10)
-    same => n,Verbose(1, Playing back ${TALK_AUDIO})
-    same => n,Playback(${TALK_AUDIO})
-    same => n,SendDTMF(#)
-    same => n,Wait(3)
-    same => n,Hangup()
+exten => sendDTMF,1,NoOp()
+	same => n,Verbose(1, Sending DTMF Signal ${DTMF_TO_SEND})
+	same => n,SendDTMF(${DTMF_TO_SEND})
+	same => n,Goto(voicemailCaller,wait,1)
+
+exten => hangup,1,NoOp()
+	same => n,Verbose(1, Hanging up)
+	same => n,Hangup()
+
+exten => wait,1,NoOp()
+	same => n,Wait(10000)
+
+exten => sendAudioWithDTMF,1,NoOp()
+	same => n,Verbose(1, Sending audio file ${TALK_AUDIO})
+	same => n,Playback(${TALK_AUDIO})
+	same => n,Verbose(1, Sending DTMF Signal ${DTMF_TO_SEND})
+	same => n,SendDTMF(${DTMF_TO_SEND})
+	same => n,Goto(voicemailCaller,wait,1)
+

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/run-test?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/run-test Thu Jan 26 08:43:10 2012
@@ -19,10 +19,78 @@
 from asterisk.asterisk import Asterisk
 from asterisk.TestCase import TestCase
 from asterisk.voicemail import VoiceMailMailboxManagement
+from asterisk.voicemail import VoiceMailState
+from asterisk.voicemail import VoiceMailTest
 
 logger = logging.getLogger(__name__)
 
-class LeaveVoicemailForwarding(TestCase):
+"""
+TestState that is the entry point for the VoiceMail application
+"""
+class StartVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+
+    def handleStateChange(self, ami, event):
+        state = event['state']
+        if state == 'PLAYBACK':
+            message = event['message']
+
+            if message == 'vm-intro':
+                self.changeState(IntroVoiceMailState(self.controller, self.voiceMailTest))
+            else:
+                self.handleDefaultState(event)
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "START"
+
+"""
+TestState that occurs when the Intro message is read, and will start the audio playback at the beep.
+After this the test states transition to a pending until switched back to Start by the reception
+of a UserEvent.
+"""
+class IntroVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+
+    def handleStateChange(self, ami, event):
+        state = event['state']
+        if state == 'PLAYBACK':
+            message = event['message']
+
+            if message == 'beep':
+                """ A beep indicates we need to stream some sound file over - use the same sound file for everything """
+                audioFile = os.path.join(os.getcwd(), "%s/sounds/talking" % (self.voiceMailTest.testParentDir))
+                self.voiceMailTest.sendSoundFileWithDTMF(audioFile, "#")
+                self.changeState(PendingVoiceMailState(self.controller, self.voiceMailTest))
+            else:
+                self.handleDefaultState(event)
+        else:
+            self.handleDefaultState(event)
+    def getStateName(self):
+        return "INTRO"
+
+"""
+TestState that occurs between leaving voicemails
+"""
+class PendingVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+        """ Reset the reactor timeout """
+        self.voiceMailTest.reset_timeout()
+
+    def handleStateChange(self, ami, event):
+        pass
+
+    def getStateName(self):
+        return "PENDING"
+
+class LeaveVoicemailForwarding(VoiceMailTest):
 
     """
     The parent directory that this test resides in
@@ -31,54 +99,66 @@
 
     def __init__(self):
         super(LeaveVoicemailForwarding, self).__init__()
-
-        self.testCounter = 0
+        self.testParentDir = "tests/apps/voicemail"
+        self.testResultsReceived = 0
+        self.reactor_timeout = 45
+        self.test_counter = 0
+        self.extensions = [1234,5678]
+
         self.create_asterisk(2)
 
 
     def ami_connect(self, ami):
         super(LeaveVoicemailForwarding, self).ami_connect(ami)
-
         self.audioFile = os.path.join(os.getcwd(), "%s/sounds/talking" % (self.testParentDir))
 
-        ami.registerEvent('UserEvent', self.user_event)
-
-        if (ami.id != 0):
-            self.ast[ami.id].cli_exec("dialplan set global TALK_AUDIO " + self.audioFile)
-
-            df1 = ami.originate("sip/ast1/1234", "sendvoicemail", "1234", 1)
-            df1.addErrback(self.handleOriginateFailure)
-
-            df2 = ami.originate("sip/ast1/5678", "sendvoicemail", "1234", 1)
-            df2.addErrback(self.handleOriginateFailure)
+        """ Record which AMI instance we've received and attempt to set up the test controller """
+        if (ami.id == 0):
+            ami.registerEvent('UserEvent', self.user_event)
+            self.amiReceiver = ami
+        elif (ami.id == 1):
+            self.amiSender = ami
+            self.astSender = self.ast[self.amiSender.id]
+        self.createTestController()
+        if (self.testStateController != None):
+            startObject = StartVoiceMailState(self.testStateController, self)
+            self.testStateController.changeState(startObject)
+
+        if not (ami.id == 0):
+            self.originate_call()
+
+    def originate_call(self):
+        extension = self.extensions[self.test_counter]
+        logger.info("Originating call to sip/ast1/" + str(extension))
+        df = self.amiSender.originate("sip/ast1/" + str(extension), "voicemailCaller", "wait", 1, None, "CallId-" + str(extension), None, None, None, {}, True )
+        df.addErrback(self.handleOriginateFailure)
 
     def user_event(self, ami, event):
-
         if event['userevent'] != 'TestResult':
             return
 
-        self.testCounter += 1
-
-        if event["result"] != "fail":
-            logger.info("Received non-failure result " + event['result'])
-            if self.testCounter == 2:
-                logger.info("Received all expected results; stopping Reactor")
-                self.passed = True
-                self.stop_reactor()
-        else:
-            self.passed = False
+        self.testResultsReceived += 1
+        if event['result'] == "pass":
+            self.passed = True
+            logger.info("VoiceMail successfully exited")
+        else:
             logger.warn("VoiceMail did not successfully exit:")
             logger.warn("result: %s" % (event['result'],))
-            logger.warn("expected: %s" % (expected))
             logger.warn("error: %s" % (event['error'],))
+
+        if self.testResultsReceived == 2:
+            logger.info("All results received; stopping reactor")
             self.stop_reactor()
+        else:
+            """ Originate the next call and reset the state machine """
+            self.test_counter += 1
+            self.senderChannel = "SIP/ast1-0000000" + str(self.test_counter)
+            self.testStateController.changeState(StartVoiceMailState(self.testStateController, self))
+            self.originate_call()
 
 
     def run(self):
         super(LeaveVoicemailForwarding, self).run()
-
-        """ Create the AMI factories
-        """
         self.create_ami_factory(2)
 
 def main():
@@ -87,9 +167,7 @@
     voicemailManager = VoiceMailMailboxManagement(test.ast[0])
 
     test.start_asterisk()
-
     reactor.run()
-
     test.stop_asterisk()
 
     logger.info("Verifying voicemails (test result: [" + str(test.passed) + "])")

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/test-config.yaml?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding/test-config.yaml Thu Jan 26 08:43:10 2012
@@ -7,7 +7,7 @@
 
 properties:
     minversion: '1.8.9'
-    testconditions:
+    buildoption: 'TEST_FRAMEWORK'
     testconditions:
         - name: 'threads'
           ignoredThreads:

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/configs/ast2/extensions.conf?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/configs/ast2/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/configs/ast2/extensions.conf Thu Jan 26 08:43:10 2012
@@ -1,10 +1,21 @@
-; Tests exiting out of the VoiceMail application through various contexts
+[voicemailCaller]
 
-[sendvoicemail]
-exten => 1234,1,NoOp()
-    same => n,Wait(10)
-    same => n,Verbose(1, Playing back ${TALK_AUDIO})
-    same => n,Playback(${TALK_AUDIO})
-    same => n,SendDTMF(#)
-    same => n,Wait(3)
-    same => n,Hangup()
+exten => sendDTMF,1,NoOp()
+	same => n,Verbose(1, Sending DTMF Signal ${DTMF_TO_SEND})
+	same => n,SendDTMF(${DTMF_TO_SEND})
+	same => n,Goto(voicemailCaller,wait,1)
+
+exten => hangup,1,NoOp()
+	same => n,Verbose(1, Hanging up)
+	same => n,Hangup()
+
+exten => wait,1,NoOp()
+	same => n,Wait(10000)
+
+exten => sendAudioWithDTMF,1,NoOp()
+	same => n,Verbose(1, Sending audio file ${TALK_AUDIO})
+	same => n,Playback(${TALK_AUDIO})
+	same => n,Verbose(1, Sending DTMF Signal ${DTMF_TO_SEND})
+	same => n,SendDTMF(${DTMF_TO_SEND})
+	same => n,Goto(voicemailCaller,wait,1)
+

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/run-test?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/run-test Thu Jan 26 08:43:10 2012
@@ -20,10 +20,78 @@
 from asterisk.asterisk import Asterisk
 from asterisk.TestCase import TestCase
 from asterisk.voicemail import VoiceMailMailboxManagement
+from asterisk.voicemail import VoiceMailState
+from asterisk.voicemail import VoiceMailTest
 
 logger = logging.getLogger(__name__)
 
-class LeaveVoicemailForwardingAutoUrgent(TestCase):
+"""
+TestState that is the entry point for the VoiceMail application
+"""
+class StartVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+
+    def handleStateChange(self, ami, event):
+        state = event['state']
+        if state == 'PLAYBACK':
+            message = event['message']
+
+            if message == 'vm-intro':
+                self.changeState(IntroVoiceMailState(self.controller, self.voiceMailTest))
+            else:
+                self.handleDefaultState(event)
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "START"
+
+"""
+TestState that occurs when the Intro message is read, and will start the audio playback at the beep.
+After this the test states transition to a pending until switched back to Start by the reception
+of a UserEvent.
+"""
+class IntroVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+
+    def handleStateChange(self, ami, event):
+        state = event['state']
+        if state == 'PLAYBACK':
+            message = event['message']
+
+            if message == 'beep':
+                """ A beep indicates we need to stream some sound file over - use the same sound file for everything """
+                audioFile = os.path.join(os.getcwd(), "%s/sounds/talking" % (self.voiceMailTest.testParentDir))
+                self.voiceMailTest.sendSoundFileWithDTMF(audioFile, "#")
+                self.changeState(PendingVoiceMailState(self.controller, self.voiceMailTest))
+            else:
+                self.handleDefaultState(event)
+        else:
+            self.handleDefaultState(event)
+    def getStateName(self):
+        return "INTRO"
+
+"""
+TestState that occurs between leaving voicemails
+"""
+class PendingVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+        """ Reset the reactor timeout """
+        self.voiceMailTest.reset_timeout()
+
+    def handleStateChange(self, ami, event):
+        pass
+
+    def getStateName(self):
+        return "PENDING"
+
+class LeaveVoicemailForwardingAutoUrgent(VoiceMailTest):
 
     """
     The parent directory that this test resides in
@@ -32,22 +100,38 @@
 
     def __init__(self):
         super(LeaveVoicemailForwardingAutoUrgent, self).__init__()
-
+        self.testParentDir = "tests/apps/voicemail"
+        self.testResultsReceived = 0
+        self.reactor_timeout = 45
+        self.test_counter = 0
+        self.extensions = [1234]
         self.create_asterisk(2)
 
 
     def ami_connect(self, ami):
         super(LeaveVoicemailForwardingAutoUrgent, self).ami_connect(ami)
-
         self.audioFile = os.path.join(os.getcwd(), "%s/sounds/talking" % (self.testParentDir))
 
-        ami.registerEvent('UserEvent', self.user_event)
+        """ Record which AMI instance we've received and attempt to set up the test controller """
+        if (ami.id == 0):
+            ami.registerEvent('UserEvent', self.user_event)
+            self.amiReceiver = ami
+        elif (ami.id == 1):
+            self.amiSender = ami
+            self.astSender = self.ast[self.amiSender.id]
+        self.createTestController()
+        if (self.testStateController != None):
+            startObject = StartVoiceMailState(self.testStateController, self)
+            self.testStateController.changeState(startObject)
 
-        if (ami.id != 0):
-            self.ast[ami.id].cli_exec("dialplan set global TALK_AUDIO " + self.audioFile)
+        if not (ami.id == 0):
+            self.originate_call()
 
-            df1 = ami.originate("sip/ast1/1234", "sendvoicemail", "1234", 1)
-            df1.addErrback(self.handleOriginateFailure)
+    def originate_call(self):
+        extension = self.extensions[self.test_counter]
+        logger.info("Originating call to sip/ast1/" + str(extension))
+        df = self.amiSender.originate("sip/ast1/" + str(extension), "voicemailCaller", "wait", 1, None, "CallId-" + str(extension), None, None, None, {}, True )
+        df.addErrback(self.handleOriginateFailure)
 
     def user_event(self, ami, event):
 
@@ -69,9 +153,6 @@
 
     def run(self):
         super(LeaveVoicemailForwardingAutoUrgent, self).run()
-
-        """ Create the AMI factories
-        """
         self.create_ami_factory(2)
 
 def main():
@@ -80,9 +161,7 @@
     voicemailManager = VoiceMailMailboxManagement(test.ast[0])
 
     test.start_asterisk()
-
     reactor.run()
-
     test.stop_asterisk()
 
     logger.info("Verifying voicemails (test result: [" + str(test.passed) + "])")

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/test-config.yaml?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_forwarding_auto_urgent/test-config.yaml Thu Jan 26 08:43:10 2012
@@ -7,7 +7,7 @@
 
 properties:
     minversion: '1.8.9'
-    testconditions:
+    buildoption: 'TEST_FRAMEWORK'
     testconditions:
         - name: 'threads'
           ignoredThreads:

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/test-config.yaml?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_nominal/test-config.yaml Thu Jan 26 08:43:10 2012
@@ -8,6 +8,7 @@
 
 properties:
     minversion: '1.8'
+    buildoption: 'TEST_FRAMEWORK'
     testconditions:
         - name: 'threads'
           ignoredThreads:

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/configs/ast2/extensions.conf?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/configs/ast2/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/configs/ast2/extensions.conf Thu Jan 26 08:43:10 2012
@@ -1,10 +1,21 @@
-; Tests exiting out of the VoiceMail application through various contexts
+[voicemailCaller]
 
-[sendvoicemail]
-exten => 1234,1,NoOp()
-    same => n,Wait(10)
-    same => n,Verbose(1, Playing back ${TALK_AUDIO})
-    same => n,Playback(${TALK_AUDIO})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Hangup()
+exten => sendDTMF,1,NoOp()
+	same => n,Verbose(1, Sending DTMF Signal ${DTMF_TO_SEND})
+	same => n,SendDTMF(${DTMF_TO_SEND})
+	same => n,Goto(voicemailCaller,wait,1)
+
+exten => hangup,1,NoOp()
+	same => n,Verbose(1, Hanging up)
+	same => n,Hangup()
+
+exten => wait,1,NoOp()
+	same => n,Wait(10000)
+
+exten => sendAudioWithDTMF,1,NoOp()
+	same => n,Verbose(1, Sending audio file ${TALK_AUDIO})
+	same => n,Playback(${TALK_AUDIO})
+	same => n,Verbose(1, Sending DTMF Signal ${DTMF_TO_SEND})
+	same => n,SendDTMF(${DTMF_TO_SEND})
+	same => n,Goto(voicemailCaller,wait,1)
+

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/run-test?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/run-test Thu Jan 26 08:43:10 2012
@@ -19,59 +19,139 @@
 from asterisk.asterisk import Asterisk
 from asterisk.TestCase import TestCase
 from asterisk.voicemail import VoiceMailMailboxManagement
+from asterisk.voicemail import VoiceMailState
+from asterisk.voicemail import VoiceMailTest
 
 logger = logging.getLogger(__name__)
 
-class LeaveVoicemailPriority(TestCase):
+"""
+TestState that is the entry point for the VoiceMail application
+"""
+class StartVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+
+    def handleStateChange(self, ami, event):
+        state = event['state']
+        if state == 'PLAYBACK':
+            message = event['message']
+
+            if message == 'vm-intro':
+                self.changeState(IntroVoiceMailState(self.controller, self.voiceMailTest))
+            else:
+                self.handleDefaultState(event)
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "START"
+
+"""
+TestState that occurs when the Intro message is read, and will start the audio playback at the beep.
+After this the test states transition to a pending until switched back to Start by the reception
+of a UserEvent.
+"""
+class IntroVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+
+    def handleStateChange(self, ami, event):
+        state = event['state']
+        if state == 'PLAYBACK':
+            message = event['message']
+
+            if message == 'beep':
+                """ A beep indicates we need to stream some sound file over - use the same sound file for everything """
+                audioFile = os.path.join(os.getcwd(), "%s/sounds/talking" % (self.voiceMailTest.testParentDir))
+                self.voiceMailTest.sendSoundFileWithDTMF(audioFile, "#")
+                self.changeState(PendingVoiceMailState(self.controller, self.voiceMailTest))
+            else:
+                self.handleDefaultState(event)
+        else:
+            self.handleDefaultState(event)
+    def getStateName(self):
+        return "INTRO"
+
+"""
+TestState that occurs between leaving voicemails
+"""
+class PendingVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+        """ Reset the reactor timeout """
+        self.voiceMailTest.reset_timeout()
+
+    def handleStateChange(self, ami, event):
+        pass
+
+    def getStateName(self):
+        return "PENDING"
+
+class LeaveVoicemailPriority(VoiceMailTest):
 
     def __init__(self):
         super(LeaveVoicemailPriority, self).__init__()
         self.testParentDir = "tests/apps/voicemail"
-        self.testCounter = 0
-        self.reactor_timeout = 60
+        self.testResultsReceived = 0
+        self.reactor_timeout = 45
+        self.test_counter = 0
+        self.extensions = [1234,5678]
+
         self.create_asterisk(2)
 
     def ami_connect(self, ami):
         super(LeaveVoicemailPriority, self).ami_connect(ami)
-
         self.audioFile = os.path.join(os.getcwd(), "%s/sounds/talking" % (self.testParentDir))
 
+        """ Record which AMI instance we've received and attempt to set up the test controller """
         if (ami.id == 0):
             ami.registerEvent('UserEvent', self.user_event)
+            self.amiReceiver = ami
+        elif (ami.id == 1):
+            self.amiSender = ami
+            self.astSender = self.ast[self.amiSender.id]
+        self.createTestController()
+        if (self.testStateController != None):
+            startObject = StartVoiceMailState(self.testStateController, self)
+            self.testStateController.changeState(startObject)
 
-        if (ami.id != 0):
-            self.ast[ami.id].cli_exec("dialplan set global TALK_AUDIO " + self.audioFile)
+        if not (ami.id == 0):
+            self.originate_call()
 
-            df1 = ami.originate("sip/ast1/1234", "sendvoicemail", "1234", 1)
-            df1.addErrback(self.handleOriginateFailure)
-
-            df2 = ami.originate("sip/ast1/5678", "sendvoicemail", "1234", 1)
-            df2.addErrback(self.handleOriginateFailure)
+    def originate_call(self):
+        extension = self.extensions[self.test_counter]
+        logger.info("Originating call to sip/ast1/" + str(extension))
+        df = self.amiSender.originate("sip/ast1/" + str(extension), "voicemailCaller", "wait", 1, None, "CallId-" + str(extension), None, None, None, {}, True )
+        df.addErrback(self.handleOriginateFailure)
 
     def user_event(self, ami, event):
-
         if event['userevent'] != 'TestResult':
             return
 
-        self.testCounter += 1
-
-        if event["result"] != "fail":
-            logger.info("Received non-failure result " + event['result'])
-            if self.testCounter == 2:
-                logger.info("Received all expected results; stopping Reactor")
-                self.passed = True
-                self.stop_reactor()
+        self.testResultsReceived += 1
+        if event['result'] == "pass":
+            self.passed = True
+            logger.info("VoiceMail successfully exited")
         else:
-            self.passed = False
             logger.warn("VoiceMail did not successfully exit:")
             logger.warn("result: %s" % (event['result'],))
-            logger.warn("expected: %s" % (expected))
             logger.warn("error: %s" % (event['error'],))
+
+        if self.testResultsReceived == 2:
+            logger.info("All results received; stopping reactor")
             self.stop_reactor()
+        else:
+            """ Originate the next call and reset the state machine """
+            self.test_counter += 1
+            self.senderChannel = "SIP/ast1-0000000" + str(self.test_counter)
+            self.testStateController.changeState(StartVoiceMailState(self.testStateController, self))
+            self.originate_call()
 
     def run(self):
         super(LeaveVoicemailPriority, self).run()
-
         self.create_ami_factory(2)
 
 def main():
@@ -80,9 +160,7 @@
     voicemailManager = VoiceMailMailboxManagement(test.ast[0])
 
     test.start_asterisk()
-
     reactor.run()
-
     test.stop_asterisk()
 
     logger.info("Verifying voicemails (test result: [" + str(test.passed) + "])")

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/test-config.yaml?view=diff&rev=3013&r1=3012&r2=3013
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_priority/test-config.yaml Thu Jan 26 08:43:10 2012
@@ -6,6 +6,7 @@
 
 properties:
     minversion: '1.8'
+    buildoption: 'TEST_FRAMEWORK'
     testconditions:
         - name: 'threads'
           ignoredThreads:




More information about the asterisk-commits mailing list