[svn-commits] mjordan: testsuite/asterisk/trunk r5268 - in /asterisk/trunk/tests/rest_api/r...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jul 18 16:58:26 CDT 2014


Author: mjordan
Date: Fri Jul 18 16:58:21 2014
New Revision: 5268

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=5268
Log:
recording/stored: Add nominal and off-nominal tests for copy operation

This patch adds tests to the Asterisk Test Suite for copying a stored
recording. Two tests are added for the operation, nominal and off-nominal.

* nominal - makes a live recording and finishes it. When finished, it takes
  the resulting stored recording and copies it. The resulting stored
  recording object is checked to see if it has the expected name and format.
* off nominal - makes a live recording and finishes it. When finished, it
  makes a copy in the same fashion as nominal. Two off nominal checks are
  then made:
  - an attempt to copy the recording again to the same location. This
    verifies that we get a 409.
  - an attempt to copy an unknown stored recording. This verifies that we
    get a 404.

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

ASTERISK-24036

Added:
    asterisk/trunk/tests/rest_api/recording/stored/
    asterisk/trunk/tests/rest_api/recording/stored/copy/
    asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/
    asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/
    asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/ast1/
    asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/ast1/extensions.conf   (with props)
    asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/recording.py   (with props)
    asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/test-config.yaml   (with props)
    asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/
    asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/
    asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/ast1/
    asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/ast1/extensions.conf   (with props)
    asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/recording.py   (with props)
    asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/test-config.yaml   (with props)
    asterisk/trunk/tests/rest_api/recording/stored/copy/tests.yaml   (with props)
    asterisk/trunk/tests/rest_api/recording/stored/tests.yaml   (with props)
Modified:
    asterisk/trunk/tests/rest_api/recording/tests.yaml

Added: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/ast1/extensions.conf?view=auto&rev=5268
==============================================================================
--- asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/ast1/extensions.conf (added)
+++ asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/ast1/extensions.conf Fri Jul 18 16:58:21 2014
@@ -1,0 +1,6 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,Answer()
+	same => n,Stasis(testsuite)
+	same => n,Hangup()

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/recording.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/recording.py?view=auto&rev=5268
==============================================================================
--- asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/recording.py (added)
+++ asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/recording.py Fri Jul 18 16:58:21 2014
@@ -1,0 +1,140 @@
+"""
+Copyright (C) 2014, Digium, Inc.
+Joshua Colp <jcolp at digium.com>
+Matt Jordan <mjordan at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+import logging
+import requests
+from twisted.internet import reactor
+
+LOGGER = logging.getLogger(__name__)
+
+class TestLogic(object):
+    """A small object used to hold test data between events"""
+
+    def __init__(self):
+        """Constructor"""
+        self.channel_id = None
+        self.test_object = None
+        self.ari = None
+
+TEST = TestLogic()
+
+
+def fail_test():
+    """Fail the running test
+    """
+    TEST.test_object.set_passed(False)
+    TEST.test_object.stop_reactor()
+
+
+def on_start(ari, event, test_object):
+    """Handle StasisStart event
+
+    This will kick off a recording of superfly
+
+    Keyword Arguments:
+    event The StasisStart event
+    test_object Our one and only test object
+    """
+    TEST.test_object = test_object
+    TEST.ari = ari
+
+    TEST.channel_id = event['channel']['id']
+
+    LOGGER.info("Channel '%s' connected to Stasis. Starting the test")
+    TEST.ari.post('channels', TEST.channel_id, 'answer')
+    try:
+        TEST.ari.post('channels', TEST.channel_id, 'record',
+                      name="superfly", format="wav")
+    except requests.exceptions.HTTPError:
+        LOGGER.error("Failed to record.")
+        fail_test()
+        return
+    LOGGER.info("Baseline recording started successfully.")
+    return True
+
+def on_recording_started(ari, event, test_object):
+    """Handler for the RecordingStarted event
+
+    This will stop the recording after 2 seconds
+
+    Keyword Arguments:
+    event The RecordingStarted event
+    test_object Our one and only test object
+    """
+    LOGGER.info("Recording started")
+
+    def _stop_recording(ari):
+        """Stop the live recording
+
+        Keyword Arguments:
+        ari The ARI object, passed in as a convenience
+        """
+        LOGGER.info("Now stopping recording")
+        try:
+            ari.post('recordings/live', 'superfly', 'stop')
+        except requests.exceptions.HTTPError:
+            LOGGER.error('Failed to stop recording.')
+            fail_test()
+            return True
+
+    reactor.callLater(2, _stop_recording, TEST.ari)
+    return True
+
+def on_recording_finished(ari, event, test_object):
+    """Handler for the RecordingFinished
+
+    Verify we have superfly as a stored recording, then
+    make a copy of it as superfreak in a subfolder 'copy'
+
+    Keyword Arguments:
+    event The RecordingFinished event
+    test_object Our one and only test object
+    """
+    LOGGER.info("Recording finished")
+
+    try:
+        stored = TEST.ari.get('recordings/stored', 'superfly').json()
+    except requests.exceptions.HTTPError:
+        LOGGER.error('Failed to get stored recording of superfly')
+        fail_test()
+        return
+
+    if stored['name'] != 'superfly':
+        LOGGER.error('Stored recording of superfly has incorrect name')
+        fail_test()
+        return
+    elif stored['format'] != 'wav':
+        LOGGER.error('Stored recording of superfly has incorrect format')
+        fail_test()
+        return
+
+    try:
+        superfreak = TEST.ari.post('recordings/stored', 'superfly', 'copy',
+            destinationRecordingName='copy/superfreak').json()
+    except requests.exceptions.HTTPError:
+        LOGGER.error('Failed to get copied recording superfreak')
+        fail_test()
+
+    if superfreak['name'] != 'copy/superfreak':
+        LOGGER.error('Stored recording of superfreak has incorrect name')
+        fail_test()
+        return
+    elif superfreak['format'] != 'wav':
+        LOGGER.error('Stored recording of superfreak has incorrect format')
+        fail_test()
+        return
+
+    LOGGER.info("Recording stopped and copied successfully. Leave Stasis.")
+    try:
+        TEST.ari.post('channels', TEST.channel_id, 'continue')
+    except requests.exceptions.HTTPError:
+        LOGGER.error('Failed to leave stasis. Crud.')
+        fail_test()
+        return
+    return True

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/recording.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/recording.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/recording.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/test-config.yaml?view=auto&rev=5268
==============================================================================
--- asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/test-config.yaml (added)
+++ asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/test-config.yaml Fri Jul 18 16:58:21 2014
@@ -1,0 +1,61 @@
+testinfo:
+    summary: Test copying a stored recording.
+    description: |
+        This test does the following:
+        - Makes a recording
+        - Verifies that we have a stored recording
+        - Copies the stored recording
+
+test-modules:
+    add-test-to-search-path: True
+    test-object:
+        config-section: test-object-config
+        typename: ari.AriTestObject
+    modules:
+        -   config-section: ari-config
+            typename: ari.WebSocketEventModule
+
+ari-config:
+    apps: testsuite
+    events:
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+                    args: []
+            count: 1
+            callback:
+                module: recording
+                method: on_start
+        -   conditions:
+                match:
+                    type: RecordingStarted
+            callback:
+                module: recording
+                method: on_recording_started
+            count: 1
+        -   conditions:
+                match:
+                    type: RecordingFinished
+            callback:
+                module: recording
+                method: on_recording_finished
+            count: 1
+        -   conditions:
+                match:
+                    type: StasisEnd
+                    application: testsuite
+            count: 1
+
+properties:
+    minversion: '12.5.0'
+    dependencies:
+        - python : autobahn.websocket
+        - python : requests
+        - python : twisted
+        - python : starpy
+        - asterisk : res_ari_channels
+        - asterisk : res_ari_recordings
+        - asterisk : app_echo
+    tags:
+        - ARI

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/nominal/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/ast1/extensions.conf?view=auto&rev=5268
==============================================================================
--- asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/ast1/extensions.conf (added)
+++ asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/ast1/extensions.conf Fri Jul 18 16:58:21 2014
@@ -1,0 +1,6 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,Answer()
+	same => n,Stasis(testsuite)
+	same => n,Hangup()

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/recording.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/recording.py?view=auto&rev=5268
==============================================================================
--- asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/recording.py (added)
+++ asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/recording.py Fri Jul 18 16:58:21 2014
@@ -1,0 +1,142 @@
+"""
+Copyright (C) 2014, Digium, Inc.
+Joshua Colp <jcolp at digium.com>
+Matt Jordan <mjordan at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+import logging
+import requests
+from twisted.internet import reactor
+
+LOGGER = logging.getLogger(__name__)
+
+class TestLogic(object):
+    """A small object used to hold test data between events"""
+
+    def __init__(self):
+        """Constructor"""
+        self.channel_id = None
+        self.test_object = None
+        self.ari = None
+
+TEST = TestLogic()
+
+
+def fail_test():
+    """Fail the running test
+    """
+    TEST.test_object.set_passed(False)
+    TEST.test_object.stop_reactor()
+
+
+def on_start(ari, event, test_object):
+    """Handle StasisStart event
+
+    This will kick off a recording of superfly
+
+    Keyword Arguments:
+    event The StasisStart event
+    test_object Our one and only test object
+    """
+    TEST.test_object = test_object
+    TEST.ari = ari
+
+    TEST.channel_id = event['channel']['id']
+
+    LOGGER.info("Channel '%s' connected to Stasis. Starting the test")
+    TEST.ari.post('channels', TEST.channel_id, 'answer')
+    try:
+        TEST.ari.post('channels', TEST.channel_id, 'record',
+                      name="superfly", format="wav")
+    except requests.exceptions.HTTPError:
+        LOGGER.error("Failed to record.")
+        fail_test()
+        return
+    LOGGER.info("Baseline recording started successfully.")
+    return True
+
+def on_recording_started(ari, event, test_object):
+    """Handler for the RecordingStarted event
+
+    This will stop the recording after 2 seconds
+
+    Keyword Arguments:
+    event The RecordingStarted event
+    test_object Our one and only test object
+    """
+    LOGGER.info("Recording started")
+
+    def _stop_recording(ari):
+        """Stop the live recording
+
+        Keyword Arguments:
+        ari The ARI object, passed in as a convenience
+        """
+        LOGGER.info("Now stopping recording")
+        try:
+            ari.post('recordings/live', 'superfly', 'stop')
+        except requests.exceptions.HTTPError:
+            LOGGER.error('Failed to stop recording.')
+            fail_test()
+            return True
+
+    reactor.callLater(2, _stop_recording, TEST.ari)
+    return True
+
+def on_recording_finished(ari, event, test_object):
+    """Handler for the RecordingFinished
+
+    Verify we have superfly as a stored recording, then
+    make a copy of it as superfreak in a subfolder 'copy'
+
+    Keyword Arguments:
+    event The RecordingFinished event
+    test_object Our one and only test object
+    """
+    LOGGER.info("Recording finished")
+    got_exception = False
+
+    try:
+        stored = TEST.ari.get('recordings/stored', 'superfly').json()
+    except requests.exceptions.HTTPError:
+        LOGGER.error('Failed to get stored recording of superfly')
+        fail_test()
+        return
+
+    try:
+        superfreak = TEST.ari.post('recordings/stored', 'superfly', 'copy',
+            destinationRecordingName='copy/superfreak').json()
+    except requests.exceptions.HTTPError:
+        LOGGER.error('Failed to get copied recording superfreak')
+        fail_test()
+        return
+
+    # Start the off nominal tests
+    TEST.ari.set_allow_errors(True)
+
+    bad_recording = TEST.ari.post('recordings/stored', 'superfly', 'copy',
+        destinationRecordingName='copy/superfreak')
+    if bad_recording.status_code != 409:
+        LOGGER.error('Expected to get response 409, got %d' % bad_recording.status_code)
+        fail_test()
+        return
+
+    bad_recording = TEST.ari.post('recordings/stored', 'not-superfly', 'copy',
+        destinationRecordingName='copy/super-duper-freak')
+    if bad_recording.status_code != 404:
+        LOGGER.error('Expected to get response 404, got %d' % bad_recording.status_code)
+        fail_test()
+        return
+
+    TEST.ari.set_allow_errors(False)
+    LOGGER.info("Recording stopped and copied successfully. Leave Stasis.")
+    try:
+        TEST.ari.post('channels', TEST.channel_id, 'continue')
+    except requests.exceptions.HTTPError:
+        LOGGER.error('Failed to leave stasis. Crud.')
+        fail_test()
+        return
+    return True

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/recording.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/recording.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/recording.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/test-config.yaml?view=auto&rev=5268
==============================================================================
--- asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/test-config.yaml (added)
+++ asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/test-config.yaml Fri Jul 18 16:58:21 2014
@@ -1,0 +1,64 @@
+testinfo:
+    summary: Test off nominal copying of a stored recording.
+    description: |
+        This test does the following:
+        - Makes a recording
+        - Verifies that we have a stored recording
+        - Attempts to copy a non-existant recording
+        - Attempts to overwrite a copy
+        All of these are expected to fail with appropriate
+        error codes.
+
+test-modules:
+    add-test-to-search-path: True
+    test-object:
+        config-section: test-object-config
+        typename: ari.AriTestObject
+    modules:
+        -   config-section: ari-config
+            typename: ari.WebSocketEventModule
+
+ari-config:
+    apps: testsuite
+    events:
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+                    args: []
+            count: 1
+            callback:
+                module: recording
+                method: on_start
+        -   conditions:
+                match:
+                    type: RecordingStarted
+            callback:
+                module: recording
+                method: on_recording_started
+            count: 1
+        -   conditions:
+                match:
+                    type: RecordingFinished
+            callback:
+                module: recording
+                method: on_recording_finished
+            count: 1
+        -   conditions:
+                match:
+                    type: StasisEnd
+                    application: testsuite
+            count: 1
+
+properties:
+    minversion: '12.5.0'
+    dependencies:
+        - python : autobahn.websocket
+        - python : requests
+        - python : twisted
+        - python : starpy
+        - asterisk : res_ari_channels
+        - asterisk : res_ari_recordings
+        - asterisk : app_echo
+    tags:
+        - ARI

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/off-nominal/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/recording/stored/copy/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/recording/stored/copy/tests.yaml?view=auto&rev=5268
==============================================================================
--- asterisk/trunk/tests/rest_api/recording/stored/copy/tests.yaml (added)
+++ asterisk/trunk/tests/rest_api/recording/stored/copy/tests.yaml Fri Jul 18 16:58:21 2014
@@ -1,0 +1,4 @@
+# Enter tests here in the order they should be considered for execution:
+tests:
+    - test: 'nominal'
+    - test: 'off-nominal'

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/tests.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/tests.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/recording/stored/copy/tests.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/recording/stored/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/recording/stored/tests.yaml?view=auto&rev=5268
==============================================================================
--- asterisk/trunk/tests/rest_api/recording/stored/tests.yaml (added)
+++ asterisk/trunk/tests/rest_api/recording/stored/tests.yaml Fri Jul 18 16:58:21 2014
@@ -1,0 +1,2 @@
+tests:
+    - dir: 'copy'

Propchange: asterisk/trunk/tests/rest_api/recording/stored/tests.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/recording/stored/tests.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/recording/stored/tests.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/trunk/tests/rest_api/recording/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/recording/tests.yaml?view=diff&rev=5268&r1=5267&r2=5268
==============================================================================
--- asterisk/trunk/tests/rest_api/recording/tests.yaml (original)
+++ asterisk/trunk/tests/rest_api/recording/tests.yaml Fri Jul 18 16:58:21 2014
@@ -3,3 +3,4 @@
     - test: 'file_conflicts'
     - test: 'format_unavailable'
     - test: 'nominal'
+    - dir: 'stored'




More information about the svn-commits mailing list