[asterisk-commits] mjordan: testsuite/asterisk/trunk r3210 - in /asterisk/trunk: lib/python/aste...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Apr 27 12:35:47 CDT 2012
Author: mjordan
Date: Fri Apr 27 12:35:42 2012
New Revision: 3210
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=3210
Log:
Add PlayMsg test for VoiceMail API
This adds a test for the VoiceMailPlayMsg application. This application
exists in the Certified Asterisk branches, and will be merged into
Asterisk 11.
Added:
asterisk/trunk/tests/apps/voicemail/play_message/
asterisk/trunk/tests/apps/voicemail/play_message/configs/
asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/
asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/extensions.conf (with props)
asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/voicemail.conf (with props)
asterisk/trunk/tests/apps/voicemail/play_message/run-test (with props)
asterisk/trunk/tests/apps/voicemail/play_message/test-config.yaml (with props)
Modified:
asterisk/trunk/lib/python/asterisk/voicemail.py
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
asterisk/trunk/tests/apps/voicemail/tests.yaml
Modified: asterisk/trunk/lib/python/asterisk/voicemail.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/voicemail.py?view=diff&rev=3210&r1=3209&r2=3210
==============================================================================
--- asterisk/trunk/lib/python/asterisk/voicemail.py (original)
+++ asterisk/trunk/lib/python/asterisk/voicemail.py Fri Apr 27 12:35:42 2012
@@ -13,6 +13,8 @@
import glob
import shutil
import logging
+import time
+import random
from asterisk import Asterisk
from config import Category
@@ -309,6 +311,7 @@
def __init__(self, ast):
self.__ast = ast
self.voicemailDirectory = self.__ast.directories['astspooldir'] + '/voicemail'
+ self.createdVoicemails = {}
"""
Creates the basic set of folders needed for a mailbox on the file system
@@ -378,6 +381,9 @@
msgName = 'msg%04d' % (msgnum)
msgEnvName = msgName + ".txt"
msgEnvPath = self.__ast.base + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':msgEnvName}
+
+ random.seed()
+ msg_id = str(int(time.time())) + "-" + str(random.randrange(0, 1, sys.maxint - 1))
f = open(msgEnvPath, 'w')
f.write(';\n')
@@ -394,6 +400,7 @@
f.write('callerid=\"Anonymous\"<555-5555>\n')
f.write('origdate=Tue Aug 9 10:05:13 PM UTC 2011\n')
f.write('origtime=1312927513\n')
+ f.write('msg_id=%s\n' % msg_id)
if (folder == self.urgentFolderName):
f.write('flag=Urgent\n')
else:
@@ -407,6 +414,10 @@
msgFormatPath = self.__ast.base + "%(vd)s/%(c)s/%(m)s/%(f)s/%(n)s" % {'vd':self.voicemailDirectory, 'c':context, 'm':mailbox, 'f':folder, 'n':msgFormatName}
audioFile = os.path.join(os.getcwd(), "%s/sounds/talking.ulaw" % (self.testParentDir))
shutil.copy(audioFile, msgFormatPath)
+
+ if folder not in self.createdVoicemails.keys():
+ self.createdVoicemails[folder] = []
+ self.createdVoicemails[folder].append((msgnum, msg_id))
return True
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=3210&r1=3209&r2=3210
==============================================================================
--- 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 Fri Apr 27 12:35:42 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=3210&r1=3209&r2=3210
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/run-test (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/run-test Fri Apr 27 12:35:42 2012
@@ -19,10 +19,36 @@
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
+"""
+
+ 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.sendDTMF()
+ self.changeState(IntroVoiceMailState(self.controller, self.voiceMailTest))
+ else:
+ self.handleDefaultState(event)
+ else:
+ self.handleDefaultState(event)
+
+ def getStateName(self):
+ return "START"
+
+class LeaveVoicemailContexts(VoiceMailTest):
"""
The parent directory that this test resides in
@@ -43,51 +69,43 @@
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
+ # 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]
+ self.createTestController()
+ if (self.testStateController != None):
+ startObject = StartVoiceMailState(self.testStateController, self)
+ self.testStateController.changeState(startObject)
LeaveVoicemailContexts.executeTest(self)
-
def executeTest(self):
logger.info("Executing test [" + str(self.testCounter) + "]")
if self.testCounter == 0:
- """
- Test exiting out before leaving voicemail and going to operator extension
- """
+ # 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
- """
+ # 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
- """
+ # 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
- """
+ # 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
- """
+ # 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)
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=3210&r1=3209&r2=3210
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/test-config.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/leave_voicemail_contexts/test-config.yaml Fri Apr 27 12:35:42 2012
@@ -5,8 +5,6 @@
other contexts when leaving a voicemail.
properties:
- # Expected to fail per ASTERISK-18243
- expectedResult: 'Fail'
minversion: '1.8'
testconditions:
- name: 'threads'
Added: asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/extensions.conf?view=auto&rev=3210
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/extensions.conf (added)
+++ asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/extensions.conf Fri Apr 27 12:35:42 2012
@@ -1,0 +1,16 @@
+
+[voicemail]
+exten => playmsg,1,NoOp()
+ same => n,GotoIf($[${LEN(${MAILCONTEXT})}=0]?nocontext:context)
+ same => n(context),VoiceMailPlayMsg(${MAILBOX}@${MAILCONTEXT},${MSGID})
+ same => n,Hangup()
+ same => n(nocontext),VoiceMailPlayMsg(${MAILBOX},${MSGID})
+ same => n,Hangup()
+
+exten => h,1,NoOp()
+ same => n,GotoIf($[${VOICEMAIL_PLAYBACKSTATUS} = SUCCESS]?pass:fail)
+ same => n(fail),UserEvent(TestResult,result: fail, status: VoiceMailPlayMsg failed to playback message ${MSGID})
+ same => n,Goto(out)
+ same => n(pass),NoOp()
+ same => n,UserEvent(TestResult,result: pass, status: VoiceMailPlayMsg successfully played back message ${MSGID})
+ same => n(out),NoOp()
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/extensions.conf
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/extensions.conf
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/extensions.conf
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/voicemail.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/voicemail.conf?view=auto&rev=3210
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/voicemail.conf (added)
+++ asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/voicemail.conf Fri Apr 27 12:35:42 2012
@@ -1,0 +1,23 @@
+; Voicemail Configuration
+
+[general]
+format = ulaw|wav49|wav
+skipms = 3000
+maxsilence = 0
+silencethreshold = 128
+maxlogins = 3
+minsecs = 0
+operator = yes
+
+[zonemessages]
+eastern = America/New_York|'vm-received' Q 'digits/at' IMp
+central = America/Chicago|'vm-received' Q 'digits/at' IMp
+central24 = America/Chicago|'vm-received' q 'digits/at' H N 'hours'
+military = Zulu|'vm-received' q 'digits/at' H N 'hours' 'phonetic/z_p'
+european = Europe/Copenhagen|'vm-received' a d b 'digits/at' HM
+
+[default]
+1234 => 1234,Mark Spencer
+
+[notdefault]
+5678 => 5678,Matt Jordan
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/voicemail.conf
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/voicemail.conf
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/configs/ast1/voicemail.conf
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/apps/voicemail/play_message/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/play_message/run-test?view=auto&rev=3210
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/play_message/run-test (added)
+++ asterisk/trunk/tests/apps/voicemail/play_message/run-test Fri Apr 27 12:35:42 2012
@@ -1,0 +1,118 @@
+#!/usr/bin/env python
+# vim: sw=3 et:
+'''
+Copyright (C) 2012, Digium, Inc.
+Matt Jordan <mjordan at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import sys
+import os
+import logging
+
+from twisted.internet import reactor
+
+sys.path.append("lib/python")
+
+from asterisk.asterisk import Asterisk
+from asterisk.TestCase import TestCase
+from asterisk.voicemail import VoiceMailMailboxManagement
+from twisted.internet import defer
+
+logger = logging.getLogger(__name__)
+
+class PlayMsg(TestCase):
+
+ def __init__(self):
+ super(PlayMsg, self).__init__()
+ self._voicemailManager = None
+ self._formats = ["ulaw","wav","WAV"]
+ self._current_test = 0
+ self._tests = []
+ self._results = []
+
+ self.create_asterisk(1)
+
+ def ami_connect(self, ami):
+ # Create the mailboxes
+ self.voicemailManager = VoiceMailMailboxManagement(self.ast[0])
+ self.voicemailManager.createMailbox("default", "1234", True)
+ self.voicemailManager.createMailbox("notdefault", "5678", True)
+
+ self.voicemailManager.createDummyVoicemail("default", "1234", self.voicemailManager.inboxFolderName, 0, self._formats)
+ self.voicemailManager.createDummyVoicemail("default", "1234", self.voicemailManager.oldFolderName, 0, self._formats)
+ self.voicemailManager.createDummyVoicemail("notdefault", "5678", self.voicemailManager.urgentFolderName, 0, self._formats)
+
+ # For each of the created voicemails, push a dictionary onto the list containing the information for that test
+ self._tests.append({"context": "default", "mailbox": "1234", "msg_id": self.voicemailManager.createdVoicemails[self.voicemailManager.inboxFolderName][0][1], "expected_result": True})
+ self._tests.append({"context": "default", "mailbox": "1234", "msg_id": self.voicemailManager.createdVoicemails[self.voicemailManager.oldFolderName][0][1], "expected_result": True})
+ self._tests.append({"context": "notdefault", "mailbox": "5678", "msg_id": self.voicemailManager.createdVoicemails[self.voicemailManager.urgentFolderName][0][1], "expected_result": True})
+ # Bad message ID
+ self._tests.append({"context": "default", "mailbox": "1234", "msg_id": "12345678", "expected_result": False})
+ # Empty mailbox
+ self._tests.append({"context": "default", "mailbox": "", "msg_id": self.voicemailManager.createdVoicemails[self.voicemailManager.inboxFolderName][0][1], "expected_result": False})
+ # Empty message ID
+ self._tests.append({"context":"default", "mailbox": "1234", "msg_id": "", "expected_result": False})
+ # Default context
+ self._tests.append({"context": "", "mailbox": "1234", "msg_id": self.voicemailManager.createdVoicemails[self.voicemailManager.oldFolderName][0][1], "expected_result": True})
+
+ ami.registerEvent('TestEvent', self.test_event_handler)
+ ami.registerEvent('UserEvent', self.user_event_handler)
+
+ self._start_test(ami)
+
+ def _start_test(self, ami):
+ test = self._tests[self._current_test]
+ logger.debug("Setting context=%s; mailbox=%s; msgid=%s" % (test["context"], test["mailbox"], test["msg_id"]))
+ ami.originate(channel = "Local/playmsg at voicemail", application = "Echo",
+ variable={"MAILCONTEXT": test["context"], "MAILBOX": test["mailbox"], "MSGID": test["msg_id"]}).addErrback(self.handleOriginateFailure)
+
+ def test_event_handler(self, ami, event):
+ if 'state' in event and 'message' in event:
+ if event['state'] == 'PLAYBACK':
+ logger.debug("Playing back %s" % event['message'])
+
+ def user_event_handler(self, ami, event):
+ if 'userevent' not in event or 'result' not in event or 'status' not in event:
+ return
+
+ if event['result'] == 'fail' and self._tests[self._current_test]["expected_result"]:
+ logger.warning("Test %d failed: expected result was pass but UserEvent indicated failure" % self._current_test)
+ logger.warning(event['status'])
+ self._results.append(False)
+ elif event['result'] == 'pass' and not self._tests[self._current_test]["expected_result"]:
+ logger.warning("Test %d failed: expected result was fail but UserEvent indicated success" % self._current_test)
+ logger.warning(event['status'])
+ self._results.append(False)
+ else:
+ logger.info("Test %d passed" % self._current_test)
+ self._results.append(True)
+
+ self._current_test += 1
+ if (self._current_test == len(self._tests)):
+ # Evaluate the tests
+ self.passed = len([result for result in self._results if not result]) == 0
+ logger.info("All tests executed; stopping reactor")
+ self.stop_reactor()
+ else:
+ self._start_test(ami)
+ return
+
+ def run(self):
+ super(PlayMsg, self).run()
+ self.create_ami_factory()
+
+def main():
+
+ test = PlayMsg()
+ reactor.run()
+
+ if not test.passed:
+ return 1
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main() or 0)
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/run-test
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/run-test
------------------------------------------------------------------------------
svn:executable = *
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/run-test
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/run-test
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: asterisk/trunk/tests/apps/voicemail/play_message/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/play_message/test-config.yaml?view=auto&rev=3210
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/play_message/test-config.yaml (added)
+++ asterisk/trunk/tests/apps/voicemail/play_message/test-config.yaml Fri Apr 27 12:35:42 2012
@@ -1,0 +1,29 @@
+testinfo:
+ skip: 'Until digium phone support is merged into trunk'
+ summary: 'Test the VoiceMailPlayMsg application'
+ description: |
+ This test verifies playing back a voicemail using the VoiceMailPlayMsg application
+ in a variety of settings. It tests:
+ * playing a message from multiple mailboxes (in both default and non-default contexts)
+ * playing a message from multiple folders
+ * failure to play a message with no mailbox or message ID specified
+ * failure to play a message with an invalid message ID specified
+
+properties:
+ # min version is cert-1.8.11
+ minversion: '1.8.11'
+ # Skip open source Asterisk versions up to 11
+ skip: '1.8'
+ skip: '10'
+ buildoption: 'TEST_FRAMEWORK'
+ testconditions:
+ - name: 'threads'
+ ignoredThreads:
+ - 'netconsole'
+ dependencies:
+ - python : 'twisted'
+ - python : 'starpy'
+ - asterisk: 'app_voicemail'
+ tags:
+ - voicemail
+ - apps
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/test-config.yaml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/test-config.yaml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: asterisk/trunk/tests/apps/voicemail/play_message/test-config.yaml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: asterisk/trunk/tests/apps/voicemail/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/apps/voicemail/tests.yaml?view=diff&rev=3210&r1=3209&r2=3210
==============================================================================
--- asterisk/trunk/tests/apps/voicemail/tests.yaml (original)
+++ asterisk/trunk/tests/apps/voicemail/tests.yaml Fri Apr 27 12:35:42 2012
@@ -28,3 +28,4 @@
- test: 'check_voicemail_dialout'
- test: 'check_voicemail_reply'
- test: 'check_voicemail_while_leaving_msg'
+ - test: 'play_message'
More information about the asterisk-commits
mailing list