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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 7 13:46:47 CDT 2012


Author: mjordan
Date: Mon May  7 13:46:40 2012
New Revision: 3215

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3215
Log:
Update the leave_voicemail_contexts test to use the TestEventController

Since ASTERISK-18243 is fixed, the leave_voicemail_contexts test should
now be enabled.  In conjunction with this, the test was also made to use
the TestEventController, so that its execution is deterministic and not
dependent on usage of the Wait application.

Review: https://reviewboard.asterisk.org/r/1893/



Modified:
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/extensions.conf
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/voicemail.conf
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast2/extensions.conf
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/run-test
    asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/test-config.yaml

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/extensions.conf?view=diff&rev=3215&r1=3214&r2=3215
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/extensions.conf Mon May  7 13:46:40 2012
@@ -18,8 +18,8 @@
     same => n,UserEvent(TestResult,result: pass, status: VoiceMail exited successfully with USEREXIT)
     same => n,Hangup()
 
-exten => 5678,1,NoOp()
-    same => n,VoiceMail(${EXTEN}@default,u,d(othercontext))
+exten => 9000,1,NoOp()
+    same => n,VoiceMail(9000 at default,u,d)
     same => n,GotoIf($[${VMSTATUS} = USEREXIT]?pass:fail)
     same => n(fail),UserEvent(TestResult,result: fail, status: VoiceMail failed to exit successfully - returned ${VMSTATUS})
     same => n,Hangup()
@@ -27,56 +27,40 @@
     same => n,UserEvent(TestResult,result: pass, status: VoiceMail exited successfully with USEREXIT)
     same => n,Hangup()
 
-exten => 9000,1,NoOp()
-    same => n,VoiceMail(9000 at default,u)
-    same => n,GotoIf($[${VMSTATUS} = USEREXIT]?pass:fail)
-    same => n(fail),UserEvent(TestResult,result: fail, status: VoiceMail failed to exit successfully - returned ${VMSTATUS})
-    same => n,Hangup()
-    same => n(pass),NoOp()
-    same => n,UserEvent(TestResult,result: pass, status: VoiceMail exited successfully with USEREXIT)
+exten => 1,1,UserEvent(TestResult,result: 1 at voicemail,status: exited through 1 extension)
     same => n,Hangup()
 
-exten => o,1,UserEvent(TestResult,result: operator,status: exited through operator extension)
-    same => n,Wait(2)
+exten => 3,1,UserEvent(TestResult,result: 3 at voicemail,status: exited through 3 extension)
     same => n,Hangup()
 
-exten => i,1,UserEvent(TestResult,result: fail,status: failed to exit successfully)
-    same => n,Wait(2)
+exten => o,1,UserEvent(TestResult,result: operator at voicemail,status: exited through operator extension)
     same => n,Hangup()
 
-exten => e,1,UserEvent(TestResult,result: fail,status: failed to exit successfully)
-    same => n,Wait(2)
+exten => a,1,UserEvent(TestResult,result: attendant at voicemail,status: exited through a extension)
     same => n,Hangup()
 
-exten => a,1,UserEvent(TestResult,result: attendant,status: exited through a extension)
-    same => n,Wait(2)
-    same => n,Hangup()
-
-exten => t,1,UserEvent(TestResult,result: fail,status: failed to exit successfully)
-    same => n,Wait(2)
-    same => n,Hangup()
+exten => 5678,1,UserEvent(TestResult,result: 5678 at voicemail,status: exited through 5678 extension)
+	same => n,Hangup()
 
 ;
 ; Test leaving out into another context
 ;
 [othercontext]
 
-exten => 1,1,UserEvent(TestResult,result: othercontext at 1,status: exited through 1 extension)
-    same => n,Wait(2)
+exten => 1,1,UserEvent(TestResult,result: 1 at othercontext,status: exited through 1 extension)
     same => n,Hangup()
 
-exten => 3,1,UserEvent(TestResult,result: othercontext at 3,status: exited through 3 extension)
-    same => n,Wait(2)
+exten => 3,1,UserEvent(TestResult,result: 3 at othercontext,status: exited through 3 extension)
     same => n,Hangup()
 
-exten => 1234,1,UserEvent(TestResult,result: othercontext at 1234,status: exited through 1234 extension)
-    same => n,Wait(2)
+exten => 9,1,UserEvent(TestResult,result: 9 at othercontext,status: exited through 9 extension)
     same => n,Hangup()
 
-exten => 5678,1,UserEvent(TestResult,result: othercontext at 5678,status: exited through 5678 extension)
-    same => n,Wait(2)
+exten => o,1,UserEvent(TestResult,result: operator at othercontext, status: exited through operator extension)
     same => n,Hangup()
 
-exten => o,1,UserEvent(TestResult,result: othercontext at operator, status: exited through operator extension)
-    same => n,Wait(2)
+exten => a,1,UserEvent(TestResult,result: attendant at othercontext, status: exited through attendant extension)
     same => n,Hangup()
+
+exten => 5678,1,UserEvent(TestResult,result: 5678 at othercontext,status: exited through 5678 extension)
+	same => n,Hangup()

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/voicemail.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/voicemail.conf?view=diff&rev=3215&r1=3214&r2=3215
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/voicemail.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast1/voicemail.conf Mon May  7 13:46:40 2012
@@ -17,6 +17,5 @@
 european = Europe/Copenhagen|'vm-received' a d b 'digits/at' HM
 
 [default]
-1234 => 1234,Mark Spencer
-5678 => 5678,Matt Jordan
-9000 => 9000,Paul Belanger,,,exitcontext=othercontext|operator=yes
+1234 => 1234,Mark Spencer,,,operator=yes|exitcontext=othercontext
+9000 => 9000,Matt Jordan

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast2/extensions.conf?view=diff&rev=3215&r1=3214&r2=3215
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast2/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/configs/ast2/extensions.conf Mon May  7 13:46:40 2012
@@ -1,18 +1,22 @@
-; Tests exiting out of the VoiceMail application through various contexts
 
-[sendvoicemail]
-exten => _XXXX,1,NoOp()
-    same => n,Wait(3)
-    same => n,Verbose(1, Sending ${DTMF_TO_SEND} key)
-    same => n,SendDTMF(${DTMF_TO_SEND})
-    same => n,Wait(10)
-    same => n,Hangup()
+[voicemailCaller]
 
-exten => 9000,1,NoOp()
-    same => n,Wait(10)
-    same => n,Verbose(1, Playing back ${TALK_AUDIO})
-    same => n,Playback(${TALK_AUDIO})
-    same => n,Verbose(1, Sending ${DTMF_TO_SEND} key)
-    same => n,SendDTMF(${DTMF_TO_SEND})
-    same => n,Wait(10)
-    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_contexts/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/run-test?view=diff&rev=3215&r1=3214&r2=3215
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/run-test Mon May  7 13:46:40 2012
@@ -19,10 +19,41 @@
 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 LeaveVoicemailContexts(TestCase):
+class StartVoiceMailState(VoiceMailState):
+    """
+    TestState that is the entry point for the VoiceMail application.
+
+    Note that since this test is exercising leaving the VoiceMail
+    application due to DTMF transfers, it doesn't do much other then
+    wait for the intro prompt, then ask to be transferred out
+    """
+
+    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':
+                dtmf = self.voiceMailTest.get_dtmf_to_send()
+                if dtmf:
+                    self.voiceMailTest.sendDTMF(dtmf)
+            else:
+                self.handleDefaultState(event)
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "START"
+
+class LeaveVoicemailContexts(VoiceMailTest):
 
     """
     The parent directory that this test resides in
@@ -32,10 +63,20 @@
     def __init__(self):
         super(LeaveVoicemailContexts, self).__init__()
 
-        self.reactor_timeout = 45
         self.testCounter = 0
         self.create_asterisk(2)
-        self.expectedValues = {'attendant': False, 'operator': False, 'othercontext at 1': False, 'othercontext at 3': False, 'othercontext at operator': False}
+        self.expectedValues = {'operator at voicemail': False,
+                               'attendant at voicemail': False,
+                               '1 at voicemail': False,
+                               '3 at voicemail': False,
+                               '5678 at voicemail': False,
+                               'operator at othercontext': False,
+                               'attendant at othercontext': False,
+                               '1 at othercontext': False,
+                               '3 at othercontext': False,
+                               '5678 at othercontext': False,
+                               '9 at othercontext': False,}
+
         self.senderAmi = None
 
     def ami_connect(self, ami):
@@ -43,58 +84,66 @@
 
         self.audioFile = os.path.join(os.getcwd(), "%s/sounds/talking" % (self.testParentDir))
 
-        ami.registerEvent('UserEvent', self.user_event)
-
-        self.ast[ami.id].cli_exec("dialplan set global TALK_AUDIO " + self.audioFile)
-        self.ast[ami.id].cli_exec("dialplan set global DTMF_TO_SEND 1")
-
-        logger.debug("AMI ID: " + str(ami.id))
-        if (ami.id != 0):
-            self.senderAmi = ami
-            LeaveVoicemailContexts.executeTest(self)
-
-
-    def executeTest(self):
+        # Record which AMI instance we've received and attempt to set up the test controller
+        if (ami.id == 0):
+            self.amiReceiver = ami
+            ami.registerEvent('UserEvent', self.user_event)
+        elif (ami.id == 1):
+            self.amiSender = ami
+            self.amiSender.registerEvent('Newchannel', self.new_channel_handler)
+            self.astSender = self.ast[self.amiSender.id]
+        self.createTestController()
+        if (self.testStateController != None):
+            self.testStateController.changeState(StartVoiceMailState(self.testStateController, self))
+            self.execute_test()
+
+    def new_channel_handler(self, ami, event):
+        if 'channel' not in event:
+            return
+        channel = event['channel']
+        logger.debug("Setting sender channel as %s" % channel)
+        self.senderChannel = channel
+
+    def get_dtmf_to_send(self):
+        """
+        Retrieve the DTMF to send based on what test we happen to be executing
+        """
+        if self.testCounter == len(self.expectedValues) - 1:
+            logger.debug("Test exiting out before leaving voicemail and going to 9 extension in othercontext")
+            return "9"
+        elif self.testCounter % 5 == 0:
+            logger.debug("Test exiting out before leaving voicemail and going to operator extension")
+            return "0"
+        elif self.testCounter % 5 == 1:
+            logger.debug("Test exiting out before leaving voicemail and going to asterisk (a) extension")
+            return "*"
+        elif self.testCounter % 5 == 2:
+            logger.debug("Test exiting out before leaving voicemail and going to numeric 1 extension")
+            return "1"
+        elif self.testCounter % 5 == 3:
+            logger.debug("Test exiting out before leaving voicemail and going to numeric 3 extension")
+            return "3"
+        elif self.testCounter % 5 == 4:
+            logger.debug("Testing exiting out before leaving voicemail and going to numeric 5678 extension")
+            return "5678"
+
+    def execute_test(self):
         logger.info("Executing test [" + str(self.testCounter) + "]")
-        if self.testCounter == 0:
-            """
-            Test exiting out before leaving voicemail and going to operator extension
-            """
-            self.ast[self.senderAmi.id].cli_exec("dialplan set global DTMF_TO_SEND 0")
-            df = self.senderAmi.originate("sip/ast1/1234", "sendvoicemail", "1234", 1)
-            df.addErrback(self.handleOriginateFailure)
-        elif self.testCounter == 1:
-            """
-            Test exiting out before leaving voicemail and going to asterisk (a) extension
-            """
-            self.ast[self.senderAmi.id].cli_exec("dialplan set global DTMF_TO_SEND *")
-            df = self.senderAmi.originate("sip/ast1/1234", "sendvoicemail", "1234", 1)
-            df.addErrback(self.handleOriginateFailure)
-        elif self.testCounter == 2:
-            """
-            Test exiting out before leaving voicemail and going to numeric 1 extension
-            """
-            self.ast[self.senderAmi.id].cli_exec("dialplan set global DTMF_TO_SEND 1")
-            df = self.senderAmi.originate("sip/ast1/1234", "sendvoicemail", "1234", 1)
-            df.addErrback(self.handleOriginateFailure)
-        elif self.testCounter == 3:
-            """
-            Test exiting out before leaving voicemail and going to numeric 3 extension
-            """
-            self.ast[self.senderAmi.id].cli_exec("dialplan set global DTMF_TO_SEND 3")
-            df = self.senderAmi.originate("sip/ast1/5678", "sendvoicemail", "5678", 1)
-            df.addErrback(self.handleOriginateFailure)
-        elif self.testCounter == 4:
-            """
-            Test exiting out before leaving voicemail and going to operator extension in a different context
-            """
-            self.ast[self.senderAmi.id].cli_exec("dialplan set global DTMF_TO_SEND 0")
-            df = self.senderAmi.originate("sip/ast1/9000", "sendvoicemail", "9000", 1)
-            df.addErrback(self.handleOriginateFailure)
-        else:
-            logger.warn("Test iterated [" + str(self.testCounter) + "] - expected less than 5")
-
-        self.testCounter +=1
+        self.reset_timeout()
+        if self.testCounter < 5:
+            # The first 5 tests start out in extension 9000
+            self.amiSender.originate(channel = "sip/ast1/9000",
+                context = "voicemailCaller",
+                exten = "wait",
+                priority= 1).addErrback(self.handleOriginateFailure)
+        elif self.testCounter < len(self.expectedValues):
+            self.amiSender.originate(channel = "sip/ast1/1234",
+                context = "voicemailCaller",
+                exten = "wait",
+                priority = 1).addErrback(self.handleOriginateFailure)
+        else:
+            logger.warn("Test iterated [" + str(self.testCounter) + "] - expected less than %d"
+                % len(self.expectedValues))
 
     def user_event(self, ami, event):
 
@@ -105,7 +154,6 @@
             logger.info("Received non-failure result " + event['result'])
             if event['result'] in self.expectedValues:
                 self.expectedValues[event['result']] = True
-                self.passed = True
             else:
                 logger.warn("Unsupported or unexpected result: " + event['result'])
         else:
@@ -114,11 +162,12 @@
             logger.warn("error: %s" % (event['status'],))
             self.passed = False
 
-        if self.testCounter == 5:
+        self.testCounter += 1
+        if self.testCounter == len(self.expectedValues):
             self.stop_reactor()
         else:
-            logger.debug("AMI ID is 1; testCounter is " + str(self.testCounter) + " - attempting to execute next test")
-            self.executeTest()
+            self.execute_test()
+        return
 
     def run(self):
         super(LeaveVoicemailContexts, self).run()
@@ -133,30 +182,16 @@
     test = LeaveVoicemailContexts()
     voicemailManager = VoiceMailMailboxManagement(test.ast[0])
 
-    test.start_asterisk()
-
     reactor.run()
 
-    test.stop_asterisk()
-
-    """
-    Verify that we received all expected results
-    """
+    # Verify that we received all expected results
+    test.passed = True
     for k, v in test.expectedValues.items():
         if not v:
-            logger.warn("Failed to receive expected result: " + k)
+            logger.warning("%s: %s" % (k, str(v)))
             test.passed = False
-
-    """
-    Verify that no messages were left
-    """
-    if test.passed:
-        formats = ["ulaw","wav","WAV"]
-        if voicemailManager.checkVoicemailExists("default","9000",0,formats) \
-        or voicemailManager.checkVoicemailExists("default","1234",0,formats) \
-        or voicemailManager.checkVoicemailExists("default","5678",0,formats):
-            logger.warn("Voicemails were left for default/1234, default/9000, or default/5678 - expected none")
-            test.passed = False
+        else:
+            logger.info("%s: %s" % (k, str(v)))
 
     if not test.passed:
         return 1

Modified: asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/test-config.yaml?view=diff&rev=3215&r1=3214&r2=3215
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/test-config.yaml Mon May  7 13:46:40 2012
@@ -5,9 +5,7 @@
         other contexts when leaving a voicemail.
 
 properties:
-    # Expected to fail per ASTERISK-18243
-    expectedResult: 'Fail'
-    minversion: '1.8'
+    minversion: '1.8.0.0'
     testconditions:
         - name: 'threads'
           ignoredThreads:




More information about the asterisk-commits mailing list