[asterisk-commits] dlee: branch dlee/ari-bridge-tests r4023 - in /asterisk/team/dlee/ari-bridge-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 15 09:55:18 CDT 2013


Author: dlee
Date: Thu Aug 15 09:55:16 2013
New Revision: 4023

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4023
Log:
Finish out bridging tests

Added:
    asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/
    asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/bridge_unhappy.py   (with props)
    asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/
    asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/ast1/
    asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/ast1/extensions.conf   (with props)
    asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/test-config.yaml   (with props)
Modified:
    asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py
    asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml

Modified: asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py?view=diff&rev=4023&r1=4022&r2=4023
==============================================================================
--- asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py (original)
+++ asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py Thu Aug 15 09:55:16 2013
@@ -375,7 +375,7 @@
         '''
         self.allow_errors = v
 
-    def raise_on_err(resp):
+    def raise_on_err(self, resp):
         '''Helper to raise an exception when a response is a 4xx or 5xx error.
 
         If allow_errors is True, then an exception is not raised.

Modified: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml?view=diff&rev=4023&r1=4022&r2=4023
==============================================================================
--- asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml (original)
+++ asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml Thu Aug 15 09:55:16 2013
@@ -1,5 +1,5 @@
 tests:
     - test: 'happy'
-    - test: 'sad'
+    - test: 'unhappy'
     - test: 'hangup'
     - test: 'move'

Added: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/bridge_unhappy.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/bridge_unhappy.py?view=auto&rev=4023
==============================================================================
--- asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/bridge_unhappy.py (added)
+++ asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/bridge_unhappy.py Thu Aug 15 09:55:16 2013
@@ -1,0 +1,129 @@
+'''
+Copyright (C) 2013, Digium, Inc.
+David M. Lee, II <dlee at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import inspect
+import logging
+import requests
+import traceback
+
+LOGGER = logging.getLogger(__name__)
+
+class BridgeUnhappy(object):
+    def __init__(self):
+        self.ami_channel_id = None
+        self.stasis_channel_id = None
+        self.ami_channel_ready = False
+
+    def on_start(self, ari, event):
+        if not self.ami_channel_id:
+            # Send the first channel out of Stasis
+            self.ami_channel_id = event['channel']['id']
+            ari.post('channels', self.ami_channel_id, 'continue')
+        elif not self.stasis_channel_id:
+            self.stasis_channel_id = event['channel']['id']
+        else:
+            assert False, "Too many channels!"
+        return True
+
+    def on_end(self, ari, event):
+        if event['channel']['id'] == self.ami_channel_id:
+            self.ami_channel_ready = True
+        elif event['channel']['id'] == self.stasis_channel_id:
+            pass
+        else:
+            assert False, "Unexpected channel leaving Stasis"
+        return True
+
+    def run_test(self, ari):
+        if not (self.ami_channel_id and self.stasis_channel_id and self.ami_channel_ready):
+            # Not ready to run the test
+            return
+
+        try:
+            self.passing = True
+            self.__run_test(ari)
+            assert self.passing
+        finally:
+            ari.delete('channels', self.ami_channel_id)
+            ari.delete('channels', self.stasis_channel_id)
+            ari.set_allow_errors(False)
+
+    def __run_test(self, ari):
+        bridge_id = ari.post('bridges').json()['id']
+        other_bridge_id = ari.post('bridges').json()['id']
+        ari.set_allow_errors(True)
+
+        def validate(expected, resp):
+            expected_code = requests.codes[expected]
+            if expected_code != resp.status_code:
+                self.passing = False
+                LOGGER.error("Expected %d (%s), got %s", expected_code, expected, resp.status_code)
+                # Log current stack frame
+                for line in traceback.format_stack(inspect.currentframe())[-2:-4:-1]:
+                    if line:
+                        LOGGER.error('"%s"' % line.strip())
+
+        # Add to a nonexistent bridge
+        resp = ari.post('bridges', 'i-am-not-a-bridge', 'addChannel', channel=self.stasis_channel_id)
+        validate('not_found', resp)
+
+        # Add to a nonexistent bridge
+        resp = ari.post('bridges', 'i-am-not-a-bridge', 'removeChannel', channel=self.stasis_channel_id)
+        validate('not_found', resp)
+
+        # Add a non-Stasis channel
+        resp = ari.post('bridges', bridge_id, 'addChannel', channel=self.ami_channel_id)
+        validate('unprocessable_entity', resp)
+
+        # Add a nonexistent channel
+        resp = ari.post('bridges', bridge_id, 'addChannel', channel='i-am-not-a-channel')
+        validate('bad_request', resp)
+
+        # Remove a nonexistent channel
+        resp = ari.post('bridges', bridge_id, 'removeChannel', channel='i-am-not-a-channel')
+        validate('bad_request', resp)
+
+        # Remove a Stasis channel that isn't in a bridge at all
+        resp = ari.post('bridges', bridge_id, 'removeChannel', channel=self.stasis_channel_id)
+        validate('conflict', resp)
+
+        # We need a channel in a bridge for the next few tests
+        resp = ari.post('bridges', bridge_id, 'addChannel', channel=self.stasis_channel_id)
+        resp.raise_for_status()
+
+        # Remove a channel from the wrong bridge
+        resp = ari.post('bridges', other_bridge_id, 'removeChannel', channel=self.stasis_channel_id)
+        validate('unprocessable_entity', resp)
+
+        # And, just to be safe, make sure the channel is still in its bridge
+        resp = ari.get('bridges', bridge_id)
+        resp.raise_for_status()
+        channels_in_bridge = resp.json()['channels']
+        assert [self.stasis_channel_id] == channels_in_bridge
+
+        # Okay, now remove it
+        resp = ari.post('bridges', bridge_id, 'removeChannel', channel=self.stasis_channel_id)
+        resp.raise_for_status()
+
+
+TEST = BridgeUnhappy()
+
+
+# Forward missing functions to the TEST object
+def on_start(ari, event):
+    r = TEST.on_start(ari, event)
+    if r:
+        TEST.run_test(ari)
+    return r
+
+
+def on_end(ari, event):
+    r = TEST.on_end(ari, event)
+    if r:
+        TEST.run_test(ari)
+    return r

Propchange: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/bridge_unhappy.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/bridge_unhappy.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/bridge_unhappy.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/ast1/extensions.conf?view=auto&rev=4023
==============================================================================
--- asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/ast1/extensions.conf (added)
+++ asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/ast1/extensions.conf Thu Aug 15 09:55:16 2013
@@ -1,0 +1,7 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,Answer()
+	same => n,Stasis(testsuite)
+	same => n,AGI(agi:async)
+	same => n,Hangup()

Propchange: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/test-config.yaml?view=auto&rev=4023
==============================================================================
--- asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/test-config.yaml (added)
+++ asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/test-config.yaml Thu Aug 15 09:55:16 2013
@@ -1,0 +1,56 @@
+testinfo:
+    summary: Test failure codes for bridge operations.
+    description: |
+        Create a couple of channels, and try to put then into bridges...
+        wrongly.
+
+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:
+    reactor-timeout: 10
+    test-iterations:
+        -   # Spawn two channels for this test
+            -   channel: Local/s at default
+                application: Echo
+            -   channel: Local/s at default
+                application: Echo
+
+ari-config:
+    apps: testsuite
+    events:
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+                    args: []
+            count: 2
+            callback:
+                module: bridge_unhappy
+                method: on_start
+        -   conditions:
+                match:
+                    type: StasisEnd
+                    application: testsuite
+            count: 2
+            callback:
+                module: bridge_unhappy
+                method: on_end
+
+properties:
+    minversion: '12.0.0'
+    dependencies:
+        - python : autobahn.websocket
+        - python : requests
+        - python : twisted
+        - python : starpy
+        - asterisk : res_ari_channels
+        - asterisk : app_echo
+    tags:
+        - ARI

Propchange: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/unhappy/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list