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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 25 13:13:08 CST 2012


Author: mjordan
Date: Wed Jan 25 13:13:04 2012
New Revision: 3008

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3008
Log:
Refactor of voicemail authentication tests to use TestController

The authentication tests were still using multiple Wait() statements
for orchestration.  Sometimes the timing would be off on the test vms,
causing the tests to fail.

All four tests have been changed to be AMI driven using the TestEvent.

Modified:
    asterisk/trunk/tests/apps/voicemail/authenticate_extensions/configs/ast2/extensions.conf
    asterisk/trunk/tests/apps/voicemail/authenticate_extensions/run-test
    asterisk/trunk/tests/apps/voicemail/authenticate_extensions/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/configs/ast2/extensions.conf
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/run-test
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast1/extensions.conf
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast2/extensions.conf
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/run-test
    asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/test-config.yaml
    asterisk/trunk/tests/apps/voicemail/authenticate_nominal/configs/ast2/extensions.conf
    asterisk/trunk/tests/apps/voicemail/authenticate_nominal/run-test
    asterisk/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml

Modified: asterisk/trunk/tests/apps/voicemail/authenticate_extensions/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_extensions/configs/ast2/extensions.conf?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_extensions/configs/ast2/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_extensions/configs/ast2/extensions.conf Wed Jan 25 13:13:04 2012
@@ -1,24 +1,25 @@
 ; Checks the authentication of a user against a mailbox and/or password combo
 ;
-; You may need to alter the Wait(5) statement if the audio prompt
-; played back by the receiver has a longer greeting then the default.
 
-[sendvoicemail]
-exten => mailboxThenTransfer,1,NoOp()
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for mailbox)
-    same => n,SendDTMF(${MAILBOX})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Verbose(1, Sending DTMF signal for transfer)
-    same => n,SendDTMF(*)
-    same => n,Wait(2)
-    same => n,Hangup()
+[voicemailCaller]
 
-exten => transfer,1,NoOp()
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for transfer)
-    same => n,SendDTMF(*)
-    same => n,Wait(2)
-    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/authenticate_extensions/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_extensions/run-test?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_extensions/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_extensions/run-test Wed Jan 25 13:13:04 2012
@@ -17,39 +17,126 @@
 sys.path.append("lib/python")
 
 from asterisk.asterisk import Asterisk
-from asterisk.TestCase import TestCase
+from asterisk.voicemail import VoiceMailState, VoiceMailTest
 
 logger = logging.getLogger(__name__)
 
-class AuthenticateExtensions(TestCase):
+"""
+TestState that attempts a login with a mailbox / incorrect password
+"""
+class LoginWithMailbox(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-login':
+                self.voiceMailTest.sendDTMF("1234")
+            elif message == 'vm-password':
+                """ Instead of sending a password, ask to be transferred to the attendant extension """
+                self.voiceMailTest.sendDTMF("*")
+                self.voiceMailTest.reset_timeout()
+            elif message == 'vm-incorrect-mailbox':
+                logger.warn("We failed to pass a valid mailbox - failing the test")
+                self.voiceMailTest.passed = False
+                self.voiceMailTest.stop_reactor()
+            else:
+                self.handleDefaultState(event)
+        elif state == 'AUTHENTICATED':
+            logger.warn("We authenticated with an invalid mailbox - failing the test")
+            self.voiceMailTest.passed = False
+            self.voiceMailTest.stop_reactor()
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "LOGIN WITH MAILBOX"
+
+"""
+TestState that attempts a login with an incorrect password only
+"""
+class LoginWithoutMailbox(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-login':
+                """ Don't login - just ask to be transferred """
+                self.voiceMailTest.sendDTMF("*")
+                self.voiceMailTest.reset_timeout()
+            elif message == 'vm-password':
+                logger.warn("We were asked a password instead of being transferred - failing the test")
+                self.voiceMailTest.passed = False
+                self.voiceMailTest.stop_reactor()
+            elif message == 'vm-incorrect-mailbox':
+                logger.warn("We failed to pass a valid mailbox - failing the test")
+                self.voiceMailTest.passed = False
+                self.voiceMailTest.stop_reactor()
+            else:
+                self.handleDefaultState(event)
+        elif state == 'AUTHENTICATED':
+            logger.warn("We authenticated with an invalid mailbox - failing the test")
+            self.voiceMailTest.passed = False
+            self.voiceMailTest.stop_reactor()
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "LOGIN WITHOUT MAILBOX"
+
+class AuthenticateExtensions(VoiceMailTest):
 
     def __init__(self):
         super(AuthenticateExtensions, self).__init__()
 
-        self.reactor_timeout = 60
+        self.test_counter = 0
         self.create_asterisk(2)
         self.pass_results = 0
 
     def ami_connect(self, ami):
         super(AuthenticateExtensions, self).ami_connect(ami)
 
-        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):
+            self.amiReceiver = ami
+            ami.registerEvent('UserEvent', self.user_event)
+        elif (ami.id == 1):
+            self.amiSender = ami
+            self.astSender = self.ast[self.amiSender.id]
+            ami.registerEvent('Hangup', self.hangup_event_handler)
+        self.createTestController()
+        if (self.testStateController != None):
+            startObject = LoginWithMailbox(self.testStateController, self)
+            self.testStateController.changeState(startObject)
 
         if not (ami.id == 0):
             self.executeTest(ami)
 
+    def hangup_event_handler(self, ami, event):
+        if self.test_counter == 0:
+            self.test_counter += 1
+            logger.debug("Hangup event received; starting next test")
+            self.executeTest(ami)
+
     def executeTest(self, ami):
-        """ Mailbox / password set to invalid mailbox, but valid password """
-        self.ast[ami.id].cli_exec("dialplan set global MAILBOX 9000")
-        self.ast[ami.id].cli_exec("dialplan set global PASSWORD 1234")
-
-        logger.debug("Originating call to sip/ast1/9000 from mailboxThenTransfer at sendvoicemail")
-        df = ami.originate("sip/ast1/9000", "sendvoicemail", "mailboxThenTransfer", 1)
-        df.addErrback(self.handleOriginateFailure)
-
-        logger.debug("Originating call to sip/ast1/9000 from transfer at sendvoicemail")
-        df = ami.originate("sip/ast1/9000", "sendvoicemail", "transfer", 1)
-        df.addErrback(self.handleOriginateFailure)
+        if self.test_counter == 0:
+            logger.debug("Originating call to sip/ast/9000")
+            df = ami.originate("sip/ast1/9000", "voicemailCaller", "wait", 1)
+            df.addErrback(self.handleOriginateFailure)
+        else:
+            self.senderChannel = "SIP/ast1-00000001"
+            startObject = LoginWithoutMailbox(self.testStateController, self)
+            self.testStateController.changeState(startObject)
+            logger.debug("Originating call to sip/ast/9000")
+            df = ami.originate("sip/ast1/9000", "voicemailCaller", "wait", 1)
+            df.addErrback(self.handleOriginateFailure)
 
     def user_event(self, ami, event):
         if event['userevent'] != 'TestResult':

Modified: asterisk/trunk/tests/apps/voicemail/authenticate_extensions/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_extensions/test-config.yaml?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_extensions/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_extensions/test-config.yaml Wed Jan 25 13:13:04 2012
@@ -6,6 +6,7 @@
 
 properties:
     minversion: '1.8'
+    buildoption: 'TEST_FRAMEWORK'
     testconditions:
         - name: 'threads'
           ignoredThreads:
@@ -17,4 +18,5 @@
     dependencies:
         - python : 'twisted'
         - python : 'starpy'
-
+        - asterisk : 'app_senddtmf'
+        - asterisk : 'app_voicemail'

Modified: asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/configs/ast2/extensions.conf?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/configs/ast2/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/configs/ast2/extensions.conf Wed Jan 25 13:13:04 2012
@@ -1,36 +1,25 @@
 ; Checks the authentication of a user against a mailbox and/or password combo
 ;
-; You may need to alter the Wait(5) statement if the audio prompt
-; played back by the receiver has a longer greeting then the default.
 
-[sendvoicemail]
-exten => invalidMailbox,1,NoOp()
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for mailbox)
-    same => n,SendDTMF(${MAILBOX})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for mailbox)
-    same => n,SendDTMF(${MAILBOX})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for mailbox)
-    same => n,SendDTMF(${MAILBOX})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(5)
-    same => n,UserEvent(TestResult,result: fail,status: failed to hang up on user after 3 attempts)
-    same => n,Wait(2)
-    same => n,Hangup()
+[voicemailCaller]
 
+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/authenticate_invalid_mailbox/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/run-test?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/run-test Wed Jan 25 13:13:04 2012
@@ -17,33 +17,78 @@
 sys.path.append("lib/python")
 
 from asterisk.asterisk import Asterisk
-from asterisk.TestCase import TestCase
+from asterisk.voicemail import VoiceMailState, VoiceMailTest
 
 logger = logging.getLogger(__name__)
 
-class AuthenticateInvalidMailbox(TestCase):
+"""
+TestState that is the entry point for the VoiceMail application
+"""
+class StartVoiceMailState(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+        self.login_attempts = 0
+
+    def handleStateChange(self, ami, event):
+        state = event['state']
+        if state == 'PLAYBACK':
+            message = event['message']
+            if message == 'vm-login' or message == 'vm-incorrect-mailbox':
+                self.voiceMailTest.sendDTMF("5555")
+                self.voiceMailTest.reset_timeout()
+                self.login_attempts += 1
+                if (self.login_attempts == 3):
+                    logger.info("Failed to login 3 times - setting test result to Pass")
+                    self.voiceMailTest.passed = True
+            elif message == 'vm-password':
+                self.voiceMailTest.sendDTMF("1234")
+            elif message == 'vm-goodbye':
+                self.voiceMailTest.hangup()
+            else:
+                self.handleDefaultState(event)
+        elif state == 'AUTHENTICATED':
+            logger.warn("We authenticated with an invalid mailbox - failing the test")
+            self.voiceMailTest.passed = False
+            self.voiceMailTest.stop_reactor()
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "START"
+
+class AuthenticateInvalidMailbox(VoiceMailTest):
 
     def __init__(self):
         super(AuthenticateInvalidMailbox, self).__init__()
-
-        self.reactor_timeout = 60
         self.create_asterisk(2)
+        self.channel = "sip/ast1/9000"
 
     def ami_connect(self, ami):
         super(AuthenticateInvalidMailbox, self).ami_connect(ami)
 
-        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):
+            self.amiReceiver = ami
+            ami.registerEvent('UserEvent', self.user_event)
+        elif (ami.id == 1):
+            self.amiSender = ami
+            self.astSender = self.ast[self.amiSender.id]
+            ami.registerEvent('Hangup', self.hangup_event_handler)
+        self.createTestController()
+        if (self.testStateController != None):
+            startObject = StartVoiceMailState(self.testStateController, self)
+            self.testStateController.changeState(startObject)
 
         if not (ami.id == 0):
             self.executeTest(ami)
 
+    def hangup_event_handler(self, ami, event):
+        logger.debug("Hangup event received; stopping reactor")
+        self.stop_reactor()
+
     def executeTest(self, ami):
-        """ Mailbox / password set to invalid mailbox, but valid password """
-        self.ast[ami.id].cli_exec("dialplan set global MAILBOX 5555")
-        self.ast[ami.id].cli_exec("dialplan set global PASSWORD 1234")
-
-        logger.debug("Originating call to sip/ast1/9000 from invalidMailbox at sendvoicemail")
-        df = ami.originate("sip/ast1/9000", "sendvoicemail", "invalidMailbox", 1)
+        df = ami.originate(self.channel, "voicemailCaller", "wait", 1)
         df.addErrback(self.handleOriginateFailure)
 
     def user_event(self, ami, event):

Modified: asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/test-config.yaml?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_invalid_mailbox/test-config.yaml Wed Jan 25 13:13:04 2012
@@ -6,6 +6,7 @@
 
 properties:
     minversion: '1.8'
+    buildoption: 'TEST_FRAMEWORK'
     testconditions:
         - name: 'threads'
           ignoredThreads:
@@ -17,4 +18,5 @@
     dependencies:
         - python : 'twisted'
         - python : 'starpy'
-
+        - asterisk : 'app_senddtmf'
+        - asterisk : 'app_voicemail'

Modified: asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast1/extensions.conf?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast1/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast1/extensions.conf Wed Jan 25 13:13:04 2012
@@ -16,4 +16,4 @@
     same => n,Verbose(1, Testing authentication of user failing to enter a valid password)
     same => n,VMAuthenticate(1234 at default)
     same => n,UserEvent(TestResult,result: fail,status: Authenticated invalid password)
-    same => n,Hangup()
+    same => n,Hangup()

Modified: asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast2/extensions.conf?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast2/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/configs/ast2/extensions.conf Wed Jan 25 13:13:04 2012
@@ -1,53 +1,25 @@
 ; Checks the authentication of a user against a mailbox and/or password combo
 ;
-; You may need to alter the Wait(5) statement if the audio prompt
-; played back by the receiver has a longer greeting then the default.
 
-[sendvoicemail]
-exten => invalidPassWithMailbox,1,NoOp()
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for mailbox)
-    same => n,SendDTMF(${MAILBOX})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for mailbox)
-    same => n,SendDTMF(${MAILBOX})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for mailbox)
-    same => n,SendDTMF(${MAILBOX})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(5)
-    same => n,UserEvent(TestResult,result: fail,status: failed to hang up on user after 3 attempts)
-    same => n,Wait(2)
-    same => n,Hangup()
+[voicemailCaller]
 
-exten => invalidPassword,1,NoOp()
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(5)
-    same => n,UserEvent(TestResult,result: fail,status: failed to hang up on user after 3 attempts)
-    same => n,Wait(2)
-    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/authenticate_invalid_password/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/run-test?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/run-test Wed Jan 25 13:13:04 2012
@@ -17,38 +17,118 @@
 sys.path.append("lib/python")
 
 from asterisk.asterisk import Asterisk
-from asterisk.TestCase import TestCase
+from asterisk.voicemail import VoiceMailState, VoiceMailTest
 
 logger = logging.getLogger(__name__)
 
-class AuthenticateInvalidPassword(TestCase):
+"""
+TestState that attempts a login with a mailbox / incorrect password
+"""
+class LoginWithMailbox(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-login' or message == 'vm-incorrect-mailbox':
+                self.voiceMailTest.sendDTMF("1234")
+            elif message == 'vm-password':
+                self.voiceMailTest.sendDTMF("5555")
+                self.voiceMailTest.reset_timeout()
+            elif message == 'vm-goodbye':
+                self.voiceMailTest.hangup()
+            else:
+                self.handleDefaultState(event)
+        elif state == 'AUTHENTICATED':
+            logger.warn("We authenticated with an invalid mailbox - failing the test")
+            self.voiceMailTest.passed = False
+            self.voiceMailTest.stop_reactor()
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "LOGIN WITH MAILBOX"
+
+"""
+TestState that attempts a login with an incorrect password only
+"""
+class LoginWithoutMailbox(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-password':
+                self.voiceMailTest.sendDTMF("5555")
+                self.voiceMailTest.reset_timeout()
+            elif message == 'vm-goodbye':
+                self.voiceMailTest.hangup()
+            else:
+                self.handleDefaultState(event)
+        elif state == 'AUTHENTICATED':
+            logger.warn("We authenticated with an invalid mailbox - failing the test")
+            self.voiceMailTest.passed = False
+            self.voiceMailTest.stop_reactor()
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "LOGIN WITHOUT MAILBOX"
+
+class AuthenticateInvalidPassword(VoiceMailTest):
 
     def __init__(self):
         super(AuthenticateInvalidPassword, self).__init__()
-
-        self.reactor_timeout = 90
+        self.test_counter = 0
         self.create_asterisk(2)
 
     def ami_connect(self, ami):
         super(AuthenticateInvalidPassword, self).ami_connect(ami)
 
-        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):
+            self.amiReceiver = ami
+            ami.registerEvent('UserEvent', self.user_event)
+        elif (ami.id == 1):
+            self.amiSender = ami
+            self.astSender = self.ast[self.amiSender.id]
+            ami.registerEvent('Hangup', self.hangup_event_handler)
+        self.createTestController()
+        if (self.testStateController != None):
+            startObject = LoginWithMailbox(self.testStateController, self)
+            self.testStateController.changeState(startObject)
 
         if not (ami.id == 0):
             self.executeTest(ami)
 
+    def hangup_event_handler(self, ami, event):
+        if self.test_counter == 0:
+            self.test_counter += 1
+            logger.debug("Hangup event received; starting next test")
+            self.executeTest(ami)
+        else:
+            logger.debug("Hangup event received; stopping reactor")
+            self.passed = True
+            self.stop_reactor()
+
     def executeTest(self, ami):
-        """ Mailbox / password set to invalid mailbox, but valid password """
-        self.ast[ami.id].cli_exec("dialplan set global MAILBOX 1234")
-        self.ast[ami.id].cli_exec("dialplan set global PASSWORD 5555")
-
-        logger.debug("Originating call to sip/ast1/9000 from invalidPassWithMailbox at sendvoicemail")
-        df = ami.originate("sip/ast1/9000", "sendvoicemail", "invalidPassWithMailbox", 1)
-        df.addErrback(self.handleOriginateFailure)
-
-        logger.debug("Originating call to sip/ast1/9001 from invalidPassword at sendvoicemail")
-        df = ami.originate("sip/ast1/9001", "sendvoicemail", "invalidPassword", 1)
-        df.addErrback(self.handleOriginateFailure)
+        if self.test_counter == 0:
+            logger.debug("Originating call to sip/ast/9000")
+            df = ami.originate("sip/ast1/9000", "voicemailCaller", "wait", 1)
+            df.addErrback(self.handleOriginateFailure)
+        else:
+            self.senderChannel = "SIP/ast1-00000001"
+            startObject = LoginWithoutMailbox(self.testStateController, self)
+            self.testStateController.changeState(startObject)
+            logger.debug("Originating call to sip/ast/9001")
+            df = ami.originate("sip/ast1/9001", "voicemailCaller", "wait", 1)
+            df.addErrback(self.handleOriginateFailure)
 
     def user_event(self, ami, event):
         if event['userevent'] != 'TestResult':

Modified: asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/test-config.yaml?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_invalid_password/test-config.yaml Wed Jan 25 13:13:04 2012
@@ -6,6 +6,7 @@
 
 properties:
     minversion: '1.8'
+    buildoption: 'TEST_FRAMEWORK'
     testconditions:
         - name: 'threads'
           ignoredThreads:
@@ -17,4 +18,5 @@
     dependencies:
         - python : 'twisted'
         - python : 'starpy'
-
+        - asterisk : 'app_senddtmf'
+        - asterisk : 'app_voicemail'

Modified: asterisk/trunk/tests/apps/voicemail/authenticate_nominal/configs/ast2/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_nominal/configs/ast2/extensions.conf?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_nominal/configs/ast2/extensions.conf (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_nominal/configs/ast2/extensions.conf Wed Jan 25 13:13:04 2012
@@ -1,26 +1,25 @@
 ; Checks the authentication of a user against a mailbox and/or password combo
 ;
-; You may need to alter the Wait(5) statement if the audio prompt
-; played back by the receiver has a longer greeting then the default.
 
-[sendvoicemail]
-exten => mailboxAndPassword,1,NoOp()
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for mailbox)
-    same => n,SendDTMF(${MAILBOX})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    same => n,SendDTMF(#)
-    same => n,Wait(1)
-    same => n,Hangup()
+[voicemailCaller]
 
-exten => password,1,NoOp()
-    same => n,Wait(5)
-    same => n,Verbose(1, Sending DTMF signal for password)
-    same => n,SendDTMF(${PASSWORD})
-    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/authenticate_nominal/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_nominal/run-test?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_nominal/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_nominal/run-test Wed Jan 25 13:13:04 2012
@@ -17,53 +17,127 @@
 sys.path.append("lib/python")
 
 from asterisk.asterisk import Asterisk
-from asterisk.TestCase import TestCase
+from asterisk.voicemail import VoiceMailTest, VoiceMailState
 
 logger = logging.getLogger(__name__)
 
-class AuthenticateNominal(TestCase):
+"""
+TestState that attempts a login with a mailbox / incorrect password
+"""
+class LoginWithMailbox(VoiceMailState):
 
-    """ Each key value pair is the mailbox / password to test """
-    credentials = [(9000, 1234), (9001, 0), (9002, 1234567890)]
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+        self.mailbox = "0"
+        self.password = "0"
+
+    def handleStateChange(self, ami, event):
+        state = event['state']
+        if state == 'PLAYBACK':
+            message = event['message']
+            if message == 'vm-login':
+                self.voiceMailTest.sendDTMF(self.mailbox)
+            elif message == 'vm-password':
+                self.voiceMailTest.sendDTMF(self.password)
+                self.voiceMailTest.reset_timeout()
+            elif message == 'vm-incorrect-mailbox':
+                logger.warn("Failed to authenticate properly, failing test")
+                self.voiceMailTest.passed = False
+                self.voiceMailTest.stop_reactor()
+            elif message == 'vm-goodbye':
+                self.voiceMailTest.hangup()
+            else:
+                self.handleDefaultState(event)
+        elif state == 'AUTHENTICATED':
+            logger.info("Authenticated for %s/%s, hanging up" % (self.mailbox, self.password))
+            self.voiceMailTest.hangup()
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "LOGIN WITH MAILBOX"
+
+"""
+TestState that attempts a login with an incorrect password only
+"""
+class LoginWithoutMailbox(VoiceMailState):
+
+    def __init__(self, controller, voiceMailTest):
+        VoiceMailState.__init__(self, controller, voiceMailTest)
+        self.mailbox = "0"
+        self.password = "0"
+
+    def handleStateChange(self, ami, event):
+        state = event['state']
+        if state == 'PLAYBACK':
+            message = event['message']
+            if message == 'vm-password':
+                self.voiceMailTest.sendDTMF(self.password)
+                self.voiceMailTest.reset_timeout()
+            elif message == 'vm-incorrect-mailbox' or message == 'vm-incorrect':
+                logger.warn("Failed to authenticate properly, failing test")
+                self.voiceMailTest.passed = False
+                self.voiceMailTest.stop_reactor()
+            elif message == 'vm-goodbye':
+                self.voiceMailTest.hangup()
+            else:
+                self.handleDefaultState(event)
+        elif state == 'AUTHENTICATED':
+            logger.info("Authenticated for %s/%s, hanging up" % (self.mailbox, self.password))
+            self.voiceMailTest.hangup()
+        else:
+            self.handleDefaultState(event)
+
+    def getStateName(self):
+        return "LOGIN WITHOUT MAILBOX"
+
+
+
+class AuthenticateNominal(VoiceMailTest):
+
+
 
     """ Test results for each iterations """
     results = [False, False, False]
 
     def __init__(self):
         super(AuthenticateNominal, self).__init__()
-
-        self.reactor_timeout = 60
-        self.senderAmi = None
+        """ Each tuple consists of the mailbox, password, expected channel and test controller object type """
+        self.credentials = [
+            ("9000", "1234", "SIP/ast1-00000000", LoginWithMailbox),
+            ("9001", "0", "SIP/ast1-00000001", LoginWithoutMailbox),
+            ("9002", "1234567890", "SIP/ast1-00000002", LoginWithoutMailbox)]
         self.create_asterisk(2)
+        self.test_counter = 0
 
     def ami_connect(self, ami):
-        ami.registerEvent('UserEvent', self.user_event)
+        super(AuthenticateNominal, self).ami_connect(ami)
 
-        if not (ami.id == 0):
-            self.testCounter = 0
-            self.senderAmi = ami
-            self.executeTest(ami)
+        """ 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.astSender = self.ast[self.amiSender.id]
+            #ami.registerEvent('Hangup', self.hangup_event_handler)
+        self.createTestController()
 
-    def executeTest(self, ami):
-        if self.testCounter > 3:
-            return
+        if (self.amiReceiver != None and self.amiSender != None):
+            self.executeTest()
 
-        credential = self.credentials[self.testCounter]
-        self.ast[ami.id].cli_exec("dialplan set global MAILBOX " + str(credential[0]))
-        self.ast[ami.id].cli_exec("dialplan set global PASSWORD " + str(credential[1]))
+    def executeTest(self):
+        tuple = self.credentials[self.test_counter]
+        startObject = tuple[3](self.testStateController, self)
+        startObject.mailbox = tuple[0]
+        startObject.password = tuple[1]
+        self.testStateController.changeState(startObject)
+        self.senderChannel = tuple[2]
 
-        """ First time through test sending a mailbox and password; otherwise we just send the password """
-        extension = ""
-        if self.testCounter == 0:
-            extension = "mailboxAndPassword"
-        else:
-            extension = "password"
-
-        logger.debug("Originating call to sip/ast1/" + str(credential[0]) + " from " + extension + "@sendvoicemail")
-        df = ami.originate("sip/ast1/" + str(credential[0]), "sendvoicemail", extension, 1)
+        logger.debug("Originating call to sip/ast1/" + tuple[0])
+        df = self.amiSender.originate("sip/ast1/" + tuple[0], "voicemailCaller", "wait", 1)
         df.addErrback(self.handleOriginateFailure)
-
-        self.testCounter += 1
+        self.test_counter += 1
 
     def user_event(self, ami, event):
         if event['userevent'] != 'TestResult':
@@ -76,20 +150,20 @@
             """
             if event['result'] == 'pass':
                 logger.info("VMAuthenticate successfully exited")
-                self.results[self.testCounter - 1] = True
+                self.results[self.test_counter - 1] = True
             else:
-                self.results[self.testCounter - 1] = False
+                self.results[self.test_counter - 1] = False
                 logger.warn("VMAuthenticate did not successfully exit:")
                 logger.warn("result: %s" % (event['result'],))
                 logger.warn("error: %s" % (event['status'],))
             """ If we've seen all the responses, stop the test """
-            if self.testCounter >= 3:
+            if self.test_counter >= 3:
                 logger.info("All responses received - Stopping Test")
                 self.stop_reactor()
 
-            if self.testCounter < 3:
+            if self.test_counter < 3:
                 super(AuthenticateNominal, self).reset_timeout()
-                self.executeTest(self.senderAmi)
+                self.executeTest()
 
     def run(self):
         super(AuthenticateNominal, self).run()

Modified: asterisk/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml?view=diff&rev=3008&r1=3007&r2=3008
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/authenticate_nominal/test-config.yaml Wed Jan 25 13:13:04 2012
@@ -7,6 +7,7 @@
 
 properties:
     minversion: '1.8'
+    buildoption: 'TEST_FRAMEWORK'
     testconditions:
         - name: 'threads'
           ignoredThreads:




More information about the asterisk-commits mailing list