[asterisk-commits] asanders: testsuite/asterisk/trunk r6326 - in /asterisk/trunk/tests/rest_api/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 20 14:10:02 CST 2015


Author: asanders
Date: Tue Jan 20 14:09:54 2015
New Revision: 6326

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=6326
Log:
Added the missing files from revision 6319.


Added:
    asterisk/trunk/tests/rest_api/bridges/error/
    asterisk/trunk/tests/rest_api/bridges/error/configs/
    asterisk/trunk/tests/rest_api/bridges/error/configs/ast1/
    asterisk/trunk/tests/rest_api/bridges/error/configs/ast1/extensions.conf   (with props)
    asterisk/trunk/tests/rest_api/bridges/error/error.py   (with props)
    asterisk/trunk/tests/rest_api/bridges/error/test-config.yaml   (with props)

Added: asterisk/trunk/tests/rest_api/bridges/error/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/bridges/error/configs/ast1/extensions.conf?view=auto&rev=6326
==============================================================================
--- asterisk/trunk/tests/rest_api/bridges/error/configs/ast1/extensions.conf (added)
+++ asterisk/trunk/tests/rest_api/bridges/error/configs/ast1/extensions.conf Tue Jan 20 14:09:54 2015
@@ -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/bridges/error/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/bridges/error/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/bridges/error/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/bridges/error/error.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/bridges/error/error.py?view=auto&rev=6326
==============================================================================
--- asterisk/trunk/tests/rest_api/bridges/error/error.py (added)
+++ asterisk/trunk/tests/rest_api/bridges/error/error.py Tue Jan 20 14:09:54 2015
@@ -1,0 +1,297 @@
+"""
+Copyright (C) 2014, Digium, Inc.
+Ashley Sanders <asanders at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+"""
+
+import logging
+import requests
+import uuid
+
+LOGGER = logging.getLogger(__name__)
+
+
+class BridgeInfo(object):
+    """Lightweight helper class for storing bridge information."""
+
+    def __init__(self, name='', bridge_type=''):
+        """Constructor.
+
+        Keyword Arguments:
+        name          --  The name of the bridge (optional)
+        bridge_type   --  The type of bridge (optional)
+        """
+
+        self.name = name
+        self.bridge_type = bridge_type
+        self.uid = str(uuid.uuid4())
+
+
+class BridgeErrorTest(object):
+    """Responsible for testing error conditions during bridge creation."""
+
+    DEFAULT_TEST_NAME = "acme"
+
+    DEFAULT_TEST_TYPE = "proxy_media"
+
+    def __init__(self, ari, event):
+        """Constructor.
+
+        Keyword Arguments:
+        ari     --  The wrapper object for ARI
+        event   --  The ARI StasisStart event object
+        """
+
+        # The pass/fail state variable for this test.
+        # Note: Value is only set to 'True' during initialization.
+        self.passing = True
+
+        # Initialize the baseline bridge info objects used during the tests
+        self.baseline_bridges = [BridgeInfo('road-runner'),
+                                 BridgeInfo(),
+                                 BridgeInfo('wiley-coyote', 'holding'),
+                                 BridgeInfo('', 'mixing')]
+
+        # The channel id that stasis gives us in the event argument
+        # Needed later for tearing down the test
+        self.stasis_channel_id = event['channel']['id'] or None
+
+        # Record state of ari.allow_errors so that it can
+        # correctly be reset at the end of the test
+        self.__set_ari_allow_errors = ari.allow_errors or False
+
+    def run_test(self, ari):
+        """Runs the test.
+
+        Tries to set up the state needed by the test and running the test
+        against all baseline bridges created during setup. Then tears
+        down the state created during setup.
+
+        Keyword Arguments:
+        ari   --  The wrapper object for ARI
+        """
+
+        try:
+            self.__setup_test(ari)
+            for i in range(len(self.baseline_bridges)):
+                self.__create_duplicate_bridges(ari, self.baseline_bridges[i])
+        finally:
+            self.__tear_down_test(ari)
+        return self.passing
+
+    def __setup_test(self, ari):
+        """Sets up the state needed for the test to execute.
+
+        Configures ARI to run the test and builds two baseline bridges to use
+        during the test.
+
+        Keyword Arguments:
+        ari   --  The wrapper object for ARI
+        """
+
+        LOGGER.debug("Performing test setup ...")
+
+        # Disable ARI auto-exceptions on HTTP errors
+        ari.set_allow_errors(True)
+
+        # Create a baseline bridge using bridge 0's id and name, but no type
+        self.__create_bridge(ari,
+                             'ok',
+                             None,
+                             self.baseline_bridges[0].uid,
+                             name=self.baseline_bridges[0].name)
+
+        # Create a baseline bridge without a name or type, using bridge 1's id
+        self.__create_bridge(ari,
+                             'ok',
+                             None,
+                             self.baseline_bridges[1].uid)
+
+        # Create a baseline bridge using bridge 2's id, name, and type
+        self.__create_bridge(ari,
+                             'ok',
+                             None,
+                             self.baseline_bridges[2].uid,
+                             name=self.baseline_bridges[2].name,
+                             type=self.baseline_bridges[2].bridge_type)
+
+        # Create a baseline bridge without a name, using bridge 3's id and type
+        self.__create_bridge(ari,
+                             'ok',
+                             None,
+                             self.baseline_bridges[3].uid,
+                             name=self.baseline_bridges[3].name,
+                             type=self.baseline_bridges[3].bridge_type)
+        return
+
+    def __tear_down_test(self, ari):
+        """Tears down the state created during test setup.
+
+        Restores ARI to its previous configuration and deletes the channel
+        and bridges used during test execution.
+
+        Keyword Arguments:
+        ari   --  The wrapper object for ARI
+        """
+        LOGGER.debug("Performing test tear down ...")
+
+        # Delete stasis channel used during the test
+        ari.delete('channels', self.stasis_channel_id)
+
+        # Delete bridges created during setup
+        for i in range(len(self.baseline_bridges)):
+            self.__delete_bridge(ari, self.baseline_bridges[i])
+
+        # Restore ARI auto-exceptions on HTTP errors to its original value
+        ari.set_allow_errors(self.__set_ari_allow_errors or False)
+
+        LOGGER.debug("Test tear down complete.")
+        return
+
+    def __validate_server_response(self, expected, resp):
+        """Validates the server response against the expected response.
+
+        Keyword Arguments:
+        expected   --  The expected http status code from the server.
+        resp       --  The server response object.
+        """
+
+        expected_code = requests.codes[expected]
+        if expected_code != resp.status_code:
+            self.passing = False
+            LOGGER.error("Test Failed. Expected %d (%s), got %s (%r)",
+                         expected_code,
+                         expected,
+                         resp.status_code,
+                         resp.json())
+            return False
+        return True
+
+    def __delete_bridge(self, ari, bridge_info):
+        """Deletes the bridge using the id of the bridge_info parameter.
+
+        Keyword Arguments:
+        ari           --  ARI wrapper object.
+        bridge_info   --  Object containing info about the bridge to delete.
+        """
+
+        LOGGER.debug("Deleting bridge [%s] with id: [%s]",
+                     bridge_info.name,
+                     bridge_info.uid)
+        ari.delete('bridges', bridge_info.uid)
+        return
+
+    def __create_bridge(self,
+                        ari,
+                        expected_status_code,
+                        description,
+                        bridge_uid,
+                        **kwargs):
+
+        """Creates a bridge with the expectation of failure.
+
+        Using the parameters given, posts to the 'bridges' endpoint. Then,
+        validates the server responded with the expected status code.
+
+        Keyword Arguments:
+        ari                   --  The wrapper object for ARI
+        expected_status_code  --  The expected response from the server
+        description           --  The text to write to the log
+        bridge_uid            --  The unique id for the bridge to create
+        kwargs                --  The query parameters
+        """
+
+        if description:
+            LOGGER.debug(description)
+        resp = ari.post('bridges',
+                        bridge_uid,
+                        **kwargs)
+        self.__validate_server_response(expected_status_code, resp)
+        return
+
+    def __create_duplicate_bridges(self, ari, bridge_info):
+        """Attempts to create a duplicate bridges.
+
+        Using the details of an existing bridge provided by the bridge_info
+        parameter, exercises fifteen state combinations to post to the
+        'bridges' endpoint.
+
+        Keyword Arguments:
+        ari           --  The wrapper object for ARI
+        bridge_info   --  The baseline bridge's information to use
+        """
+
+        LOGGER.debug("Current baseline bridge: [%s]", bridge_info.uid)
+
+        # Test AD
+        description = "Attempting to create a bridge using the same id \
+                       as the current baseline bridge, but with no name \
+                       and a different type specified"
+        self.__create_bridge(ari,
+                             'internal_server_error',
+                             description,
+                             bridge_info.uid,
+                             type=self.DEFAULT_TEST_TYPE)
+
+        # Test CD
+        description = "Attempting to create a bridge, using the same id \
+                       and name as the current baseline bridge but a \
+                       different type specified"
+        self.__create_bridge(ari,
+                             'internal_server_error',
+                             description,
+                             bridge_info.uid,
+                             name=bridge_info.name,
+                             type=self.DEFAULT_TEST_TYPE)
+
+        # Test DA
+        description = "Attempting to create a bridge using the same id \
+                       as the current baseline bridge but with a \
+                       different name and no type specified"
+        self.__create_bridge(ari,
+                             'internal_server_error',
+                             description,
+                             bridge_info.uid,
+                             name=self.DEFAULT_TEST_NAME)
+
+        # Test DC
+        description = "Attempting to create a bridge, using the same id \
+                       and type as the current baseline bridge but with a \
+                       different name specified"
+        self.__create_bridge(ari,
+                             'internal_server_error',
+                             description,
+                             bridge_info.uid,
+                             name=self.DEFAULT_TEST_NAME,
+                             type=bridge_info.bridge_type)
+
+        # Test DD
+        description = "Attempting to create a bridge using the same id \
+                       as the current baseline bridge but with a \
+                       different name and a different type"
+        self.__create_bridge(ari,
+                             'internal_server_error',
+                             description,
+                             bridge_info.uid,
+                             name=self.DEFAULT_TEST_NAME,
+                             type=self.DEFAULT_TEST_TYPE)
+        return
+
+
+def on_start(ari, event, test_object):
+    """Event handler for the StasisStart event.
+
+    Keyword Arguments:
+    ari           --  The wrapper object for ARI
+    event         --  The ARI StasisStart event object
+    test_object   --  The TestCase object running the test
+    """
+
+    LOGGER.debug("Starting bridge error test: on_start(%r)", event)
+    test = BridgeErrorTest(ari, event)
+    result = test.run_test(ari)
+    LOGGER.debug("Finsihed testing for bridge creation error conditions.")
+    test_object.stop_reactor()
+    return result

Propchange: asterisk/trunk/tests/rest_api/bridges/error/error.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/bridges/error/error.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/bridges/error/error.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/bridges/error/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/bridges/error/test-config.yaml?view=auto&rev=6326
==============================================================================
--- asterisk/trunk/tests/rest_api/bridges/error/test-config.yaml (added)
+++ asterisk/trunk/tests/rest_api/bridges/error/test-config.yaml Tue Jan 20 14:09:54 2015
@@ -1,0 +1,48 @@
+testinfo:
+    summary: Test for verifying that posts to the 'bridges' endpoint fails when expected.
+    description: |
+    The following combinations of variable states are the expected failure conditions:
+    Case AD:  name/none, type/different
+    Case CD:  name/same, type/different
+    Case DA:  name/different, type/none
+    Case DB:  name/different, type/empty
+    Case DC:  name/different, type/same
+    Case DD:  name/different, type/different
+
+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
+
+test-object-config:
+    stop-on-end: False
+
+ari-config:
+    apps: testsuite
+    events:
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+                    args: []
+            count: 1
+            callback:
+                module: error
+                method: on_start
+
+properties:
+    minversion: '13.2.0'
+    dependencies:
+        - python : autobahn.websocket
+        - python : requests
+        - python : twisted
+        - python : starpy
+        - asterisk : res_ari_channels
+        - asterisk : app_echo
+        - asterisk : res_ari_bridges
+    tags:
+        - ARI

Propchange: asterisk/trunk/tests/rest_api/bridges/error/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/bridges/error/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/bridges/error/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list