[asterisk-dev] Change in testsuite[master]: tests/rest_api/channels/hold: Add a default Hold action test

Matt Jordan (Code Review) asteriskteam at digium.com
Fri Mar 27 22:21:12 CDT 2015


Matt Jordan has uploaded a new change for review.

  https://gerrit.asterisk.org/17

Change subject: tests/rest_api/channels/hold: Add a default Hold action test
......................................................................

tests/rest_api/channels/hold: Add a default Hold action test

This test verifies that a channel that initiates a call hold will have the
Hold event raised for it, and that a channel that removes a call hold will
have an Unhold event raised for it.

The test puts two Local channels into a Bridge together. When both channels
are in a bridge, an ARI POST /hold operation is performed on the first
channel. When the Hold event is received, an ARI DELETE /hold operation is
performed on the same channel. When the Unhold event is received, the
channels are removed from the bridge and hung up, and the bridge is destroyed.

ASTERISK-24922
Reported by: Matt Jordan

Change-Id: I9786cb0829e39b33a8dbc130e53fd15a1b5e0d68
---
A tests/rest_api/channels/hold/hold_action/configs/ast1/extensions.conf
A tests/rest_api/channels/hold/hold_action/hold_action.py
A tests/rest_api/channels/hold/hold_action/test-config.yaml
M tests/rest_api/channels/hold/tests.yaml
4 files changed, 208 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/17/17/1

diff --git a/tests/rest_api/channels/hold/hold_action/configs/ast1/extensions.conf b/tests/rest_api/channels/hold/hold_action/configs/ast1/extensions.conf
new file mode 100644
index 0000000..df8f90c
--- /dev/null
+++ b/tests/rest_api/channels/hold/hold_action/configs/ast1/extensions.conf
@@ -0,0 +1,14 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,Answer()
+	same => n,Stasis(testsuite)
+	same => n,Hangup()
+
+exten => second,1,NoOp()
+	same => n,Answer()
+	same => n,Stasis(testsuite,second)
+	same => n,Hangup()
+
+exten => echo,1,NoOp()
+	same => n,Echo()
diff --git a/tests/rest_api/channels/hold/hold_action/hold_action.py b/tests/rest_api/channels/hold/hold_action/hold_action.py
new file mode 100644
index 0000000..202fcea
--- /dev/null
+++ b/tests/rest_api/channels/hold/hold_action/hold_action.py
@@ -0,0 +1,92 @@
+'''
+Copyright (C) 2015, 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 uuid
+import logging
+
+LOGGER = logging.getLogger(__name__)
+
+
+class TestTracker(object):
+    """Object that keeps track of the test"""
+
+    def __init__(self):
+        self.channel_one = None
+        self.channel_two = None
+        self.bridge = None
+
+TEST = TestTracker()
+
+
+def on_first_start(ari, event, test_object):
+    global TEST
+    LOGGER.debug("on_start(%r)" % event)
+
+    TEST.channel_one = event['channel']['id']
+
+    second_channel_id = str(uuid.uuid4())
+    ari.post('channels', second_channel_id, endpoint='Local/second at default',
+             extension='echo', context='default', priority=1)
+
+    return True
+
+
+def on_second_start(ari, event, test_object):
+    global TEST
+    LOGGER.debug("on_start(%r)" % event)
+
+    TEST.channel_two = event['channel']['id']
+
+    TEST.bridge = ari.post('bridges', 'test-bridge',
+                           type='mixing,dtmf_events').json()['id']
+
+    ari.post('bridges', TEST.bridge, 'addChannel',
+             channel='%s,%s' % (TEST.channel_one, TEST.channel_two))
+    return True
+
+
+def on_entered_bridge(ari, event, test_object):
+    global TEST
+    LOGGER.debug("on_entered_bridge(%r)" % event)
+
+    bridge = event['bridge']
+    if len(bridge['channels']) == 2:
+        ari.post('channels', TEST.channel_one, 'hold')
+    return True
+
+
+def on_hold(ari, event, test_object):
+    global TEST
+    LOGGER.debug("on_hold(%r)" % event)
+
+    ari.delete('channels', TEST.channel_one, 'hold')
+    return True
+
+
+def on_unhold(ari, event, test_object):
+    global TEST
+    LOGGER.debug("on_unhold(%r)" % event)
+
+    ari.post('bridges', TEST.bridge, 'removeChannel', channel=TEST.channel_one)
+    ari.post('bridges', TEST.bridge, 'removeChannel', channel=TEST.channel_two)
+
+    test_object.set_passed(True)
+    return True
+
+
+def on_left_bridge(ari, event, test_object):
+    global TEST
+    LOGGER.debug('on_left_bridge(%r)' % event)
+
+    bridge = event['bridge']
+    if len(bridge['channels']) == 0:
+        ari.delete('channels', TEST.channel_one)
+        ari.delete('channels', TEST.channel_two)
+        ari.delete('bridges', TEST.bridge)
+
+    return True
diff --git a/tests/rest_api/channels/hold/hold_action/test-config.yaml b/tests/rest_api/channels/hold/hold_action/test-config.yaml
new file mode 100644
index 0000000..769afaf
--- /dev/null
+++ b/tests/rest_api/channels/hold/hold_action/test-config.yaml
@@ -0,0 +1,101 @@
+testinfo:
+    summary: "Verify that Hold can be posted/deleted on a channel"
+    description: |
+        "This test verifies that a channel that initiates a call hold
+        will have the Hold event raised for it, and that a channel that
+        removes a call hold will have an Unhold event raised for it.
+        The test puts two Local channels into a Bridge together. When
+        both channels are in a bridge, an ARI POST /hold operation is
+        performed on the first channel. When the Hold event is received,
+        an ARI DELETE /hold operation is performed on the same channel.
+        When the Unhold event is received, the channels are removed from
+        the bridge and hung up, and the bridge is destroyed."
+
+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:
+    apps: testsuite
+
+ari-config:
+    apps: testsuite
+    events:
+        -
+            conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+                    args: []
+            count: 1
+            callback:
+                module: hold_action
+                method: on_first_start
+        -
+            conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+                    args: ['second']
+            count: 1
+            callback:
+                module: hold_action
+                method: on_second_start
+        -
+            conditions:
+                match:
+                    type: ChannelEnteredBridge
+            count: 2
+            callback:
+                module: hold_action
+                method: on_entered_bridge
+        -
+            conditions:
+                match:
+                    type: ChannelHold
+                    application: testsuite
+                    channel:
+                        name: 'Local/s at default-.*'
+            count: 1
+            callback:
+                module: hold_action
+                method: on_hold
+        -
+            conditions:
+                match:
+                    type: ChannelUnhold
+                    application: testsuite
+                    channel:
+                        name: 'Local/s at default-.*'
+            count: 1
+            callback:
+                module: hold_action
+                method: on_unhold
+        -
+            conditions:
+                match:
+                    type: ChannelLeftBridge
+            count: 2
+            callback:
+                module: hold_action
+                method: on_left_bridge
+
+
+properties:
+    minversion: '13.4.0'
+    dependencies:
+        - python : autobahn.websocket
+        - python : requests
+        - python : twisted
+        - python : starpy
+        - asterisk : app_stasis
+        - asterisk : res_ari_channels
+        - asterisk : res_ari_bridges
+    tags:
+        - ARI
diff --git a/tests/rest_api/channels/hold/tests.yaml b/tests/rest_api/channels/hold/tests.yaml
index 799f1b3..7626704 100644
--- a/tests/rest_api/channels/hold/tests.yaml
+++ b/tests/rest_api/channels/hold/tests.yaml
@@ -1,2 +1,3 @@
 tests:
+    - test: 'hold_action'
     - test: 'hold_intercept'

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9786cb0829e39b33a8dbc130e53fd15a1b5e0d68
Gerrit-PatchSet: 1
Gerrit-Project: testsuite
Gerrit-Branch: master
Gerrit-Owner: Matt Jordan <mjordan at digium.com>



More information about the asterisk-dev mailing list