[Asterisk-code-review] testsuite: Misc updates to tests/apps/mixmonitor (testsuite[master])

Mark Michelson asteriskteam at digium.com
Fri Aug 14 11:56:52 CDT 2015


Mark Michelson has submitted this change and it was merged.

Change subject: testsuite: Misc updates to tests/apps/mixmonitor
......................................................................


testsuite: Misc updates to tests/apps/mixmonitor

* Refactored the run-test code.

* Fixed PEP8 findings.

* Removed unnecessary files.  The testaudio[1-3].raw files should have
never been checked in and the manager.conf file did not override anything
important.

Change-Id: I157df77b3b7970aa8c45e75e6f4345ab213801f7
---
A tests/apps/mixmonitor/.gitignore
M tests/apps/mixmonitor/configs/ast1/extensions.conf
D tests/apps/mixmonitor/configs/ast1/manager.conf
M tests/apps/mixmonitor/run-test
M tests/apps/mixmonitor/test-config.yaml
D tests/apps/mixmonitor/testaudio1.raw
D tests/apps/mixmonitor/testaudio2.raw
D tests/apps/mixmonitor/testaudio3.raw
8 files changed, 64 insertions(+), 59 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/tests/apps/mixmonitor/.gitignore b/tests/apps/mixmonitor/.gitignore
new file mode 100644
index 0000000..0ac3d2b
--- /dev/null
+++ b/tests/apps/mixmonitor/.gitignore
@@ -0,0 +1 @@
+testaudio*.raw
diff --git a/tests/apps/mixmonitor/configs/ast1/extensions.conf b/tests/apps/mixmonitor/configs/ast1/extensions.conf
index 648be60..6d3a4b9 100644
--- a/tests/apps/mixmonitor/configs/ast1/extensions.conf
+++ b/tests/apps/mixmonitor/configs/ast1/extensions.conf
@@ -5,6 +5,7 @@
 [listener]
 exten => s,1,Answer()
 exten => s,n,Echo()
+exten => s,n,HangUp()
 
 [test1]
 exten => s,1,Answer()
@@ -17,19 +18,19 @@
 ; StopMixMonitor failed to let go of the file as we could not play it back
 exten => s,n(stopnow),HangUp()
 ; StopMixMonitor worked, now test stopping on hangup
-exten => s,n(domore), MixMonitor(${TESTAUDIO2})
+exten => s,n(domore),MixMonitor(${TESTAUDIO2})
 exten => s,n,Playback(${TALK_AUDIO})
 exten => s,n,HangUp()
 
-exten => h,1,UserEvent(test1, status: ${PLAYBACKSTATUS})
+exten => h,1,UserEvent(test1,status: ${PLAYBACKSTATUS})
 
 [test2]
 ; Test 2 verifies the TESTAUDIO2 file was released during hangup of the previous test
 exten => s,1,PlayBack(${TESTAUDIO2})
 exten => s,n,GoToIf($[${PLAYBACKSTATUS} = SUCCESS]?domore2:stopnow2)
 exten => s,n(stopnow2),HangUp()
-exten => s,n(domore2), MixMonitor(${TESTAUDIO3})
+exten => s,n(domore2),MixMonitor(${TESTAUDIO3})
 exten => s,n,Playback(${TALK_AUDIO})
 exten => s,n,HangUp()
 
-exten => h,1,UserEvent(test2, status: ${PLAYBACKSTATUS})
+exten => h,1,UserEvent(test2,status: ${PLAYBACKSTATUS})
diff --git a/tests/apps/mixmonitor/configs/ast1/manager.conf b/tests/apps/mixmonitor/configs/ast1/manager.conf
deleted file mode 100644
index 3cb7aad..0000000
--- a/tests/apps/mixmonitor/configs/ast1/manager.conf
+++ /dev/null
@@ -1,9 +0,0 @@
-[general]
-enabled = yes
-port = 5038
-bindaddr = 127.0.0.1
-
-[user]
-secret = mysecret
-read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
-write = system,call,agent,user,config,command,reporting,originate
diff --git a/tests/apps/mixmonitor/run-test b/tests/apps/mixmonitor/run-test
index 6d7e670..816ee3a 100755
--- a/tests/apps/mixmonitor/run-test
+++ b/tests/apps/mixmonitor/run-test
@@ -1,8 +1,9 @@
 #!/usr/bin/env python
 '''
-Copyright (C) 2010-2014, Digium, Inc.
+Copyright (C) 2010-2015, Digium, Inc.
 David Vossel <dvossel at digium.com>
 Matt Jordan <mjordan at digium.com>
+Richard Mudgett <rmudgett at digium.com>
 
 This program is free software, distributed under the terms of
 the GNU General Public License Version 2.
@@ -22,72 +23,80 @@
 
 LOGGER = logging.getLogger(__name__)
 
+
 class MixMonitorTest(TestCase):
     def __init__(self):
         super(MixMonitorTest, self).__init__()
 
         self.passed = False
-        self.last_step = ""
-        # playback file is 2559 bytes of ulaw, that will come out to be ~41118 of wav
+
+        # playback file is 2559 bytes of ulaw,
+        # that will come out to be ~41118 of wav
         self.expectedfilesize = 41118
         self.filesizetolerance = 5000
-        self.audiofile1size = -1
-        self.audiofile2size = -1
-        self.audiofile3size = -1
 
-        self.audiofile1 = os.path.join(os.getcwd(), "%s/testaudio1" % (testdir))
-        self.audiofile2 = os.path.join(os.getcwd(), "%s/testaudio2" % (testdir))
-        self.audiofile3 = os.path.join(os.getcwd(), "%s/testaudio3" % (testdir))
+        self.audiofile1 = os.path.join(os.getcwd(), testdir + "/testaudio1")
+        self.audiofile2 = os.path.join(os.getcwd(), testdir + "/testaudio2")
+        self.audiofile3 = os.path.join(os.getcwd(), testdir + "/testaudio3")
 
-        self.talkingaudio = os.path.join(os.getcwd(), "%s/sounds/talking" % (testdir))
+        # Remove any output files from a previous run
+        self.unlink_file(self.audiofile1 + ".raw")
+        self.unlink_file(self.audiofile2 + ".raw")
+        self.unlink_file(self.audiofile3 + ".raw")
+
+        self.talkingaudio = os.path.join(os.getcwd(), testdir + "/sounds/talking")
 
         self.create_asterisk()
+
+    def unlink_file(self, filename):
+        if os.path.exists(filename):
+            os.unlink(filename)
+
+    def check_file(self, name, filename):
+        if not os.path.exists(filename):
+            LOGGER.error(name + " does not exist.")
+            self.passed = False
+            return
+
+        filesize = os.path.getsize(filename)
+        LOGGER.debug("%s size is %d." % (name, filesize))
+        if math.fabs(filesize - self.expectedfilesize) > self.filesizetolerance:
+            # Fail: MixMonitor is not creating the correct
+            # file size we expect.
+            LOGGER.error(name + " size is not within the size tolerance.")
+            self.passed = False
 
     def read_result(self):
         self.passed = True
         self.stop_reactor()
-        LOGGER.info("Reading result file from MixMonitor")
-        if os.path.exists(self.audiofile1 + ".raw"):
-            self.audiofile1size = os.path.getsize(self.audiofile1 + ".raw")
-        if os.path.exists(self.audiofile2 + ".raw"):
-            self.audiofile2size = os.path.getsize(self.audiofile2 + ".raw")
-        if os.path.exists(self.audiofile3 + ".raw"):
-            self.audiofile3size = os.path.getsize(self.audiofile3 + ".raw")
+        LOGGER.info("Checking MixMonitor recorded files...")
 
-        LOGGER.debug("audiofile1 size is %d, a negative size indicates the file was not present." % (self.audiofile1size, ))
-        if math.fabs(self.audiofile1size - self.expectedfilesize) > self.filesizetolerance:
-            # if this failed mixmonitor is not creating the correct file size for the time we expect.
-            LOGGER.error("audiofile1 size is not within the size tolerance.")
-            self.passed = False
+        self.check_file("audiofile1", self.audiofile1 + ".raw")
 
-        LOGGER.debug("audiofile2 size is %d, a negative size indicates the file was not present." % (self.audiofile2size, ))
-        if math.fabs(self.audiofile2size - self.expectedfilesize) > self.filesizetolerance:
-            # if this failed it is likely because StopMixMonitor never let go of audiofile1
-            LOGGER.error("audiofile2 size is not within the size tolerance.")
-            self.passed = False
+        # If this fails it is likely because StopMixMonitor never
+        # let go of audiofile1.
+        self.check_file("audiofile2", self.audiofile2 + ".raw")
 
-        LOGGER.debug("audiofile3 size is %d, a negative size indicates the file was not present." % (self.audiofile3size, ))
-        if self.audiofile3size == -1:
-            # if this failed it is likely because MixMonitor never let go of audiofile2 on hangup
-            LOGGER.error("audiofile3 file does not exist.")
-            self.passed = False
+        # If this fails it is likely because MixMonitor never let
+        # go of audiofile2 on hangup.
+        self.check_file("audiofile3", self.audiofile3 + ".raw")
 
-        if self.passed == True:
-            LOGGER.info("Test Passed... All audio files are the correct.")
+        if self.passed:
+            LOGGER.info("Test Passed... All audio files are correct.")
 
     def launch_test1(self):
         LOGGER.info("Placing call to test1 exten")
         self.ami.originate(channel="Local/s at listener",
-            context="test1",
-            exten="s",
-            priority="1")
+                           context="test1",
+                           exten="s",
+                           priority="1")
 
     def launch_test2(self):
         LOGGER.info("Placing call to test2 exten")
         self.ami.originate(channel="Local/s at listener",
-            context="test2",
-            exten="s",
-            priority="1")
+                           context="test2",
+                           exten="s",
+                           priority="1")
 
     def check_test1(self, ami, event):
         LOGGER.info("Checking Userevent")
@@ -118,16 +127,15 @@
         self.ami = ami
         self.ami.registerEvent("UserEvent", self.check_test1)
 
-        self.ami.setVar(channel = "", variable = "TESTAUDIO1", value = self.audiofile1)
-        self.ami.setVar(channel = "", variable = "TESTAUDIO2", value = self.audiofile2)
-        self.ami.setVar(channel = "", variable = "TESTAUDIO3", value = self.audiofile3)
-        self.ami.setVar(channel = "", variable = "TALK_AUDIO", value = self.talkingaudio)
+        self.ami.setVar(channel="", variable="TESTAUDIO1", value=self.audiofile1)
+        self.ami.setVar(channel="", variable="TESTAUDIO2", value=self.audiofile2)
+        self.ami.setVar(channel="", variable="TESTAUDIO3", value=self.audiofile3)
+        self.ami.setVar(channel="", variable="TALK_AUDIO", value=self.talkingaudio)
 
         self.launch_test1()
 
     def run(self):
         self.create_ami_factory()
-
 
 
 def main():
diff --git a/tests/apps/mixmonitor/test-config.yaml b/tests/apps/mixmonitor/test-config.yaml
index 6a5b727..bbe2aef 100644
--- a/tests/apps/mixmonitor/test-config.yaml
+++ b/tests/apps/mixmonitor/test-config.yaml
@@ -9,5 +9,9 @@
     dependencies:
         - python : 'twisted'
         - python : 'starpy'
+        - asterisk : 'app_echo'
+        - asterisk : 'app_mixmonitor'
+        - asterisk : 'app_playback'
+        - asterisk : 'app_userevent'
     tags:
-        - mixmonitor
\ No newline at end of file
+        - mixmonitor
diff --git a/tests/apps/mixmonitor/testaudio1.raw b/tests/apps/mixmonitor/testaudio1.raw
deleted file mode 100644
index af9ba40..0000000
--- a/tests/apps/mixmonitor/testaudio1.raw
+++ /dev/null
Binary files differ
diff --git a/tests/apps/mixmonitor/testaudio2.raw b/tests/apps/mixmonitor/testaudio2.raw
deleted file mode 100644
index af9ba40..0000000
--- a/tests/apps/mixmonitor/testaudio2.raw
+++ /dev/null
Binary files differ
diff --git a/tests/apps/mixmonitor/testaudio3.raw b/tests/apps/mixmonitor/testaudio3.raw
deleted file mode 100644
index af9ba40..0000000
--- a/tests/apps/mixmonitor/testaudio3.raw
+++ /dev/null
Binary files differ

-- 
To view, visit https://gerrit.asterisk.org/1091
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I157df77b3b7970aa8c45e75e6f4345ab213801f7
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-code-review mailing list