[Asterisk-code-review] testsuite: Added test for 'move' REST API call. (testsuite[13])

Benjamin Keith Ford asteriskteam at digium.com
Mon Jan 21 09:49:04 CST 2019


Benjamin Keith Ford has uploaded this change for review. ( https://gerrit.asterisk.org/10897


Change subject: testsuite: Added test for 'move' REST API call.
......................................................................

testsuite: Added test for 'move' REST API call.

Added a new test that covers some simple use cases of the new 'move'
REST API call, which moves a channel from one application to another
without having to leave Stasis and re-enter dialplan. It tests a few
basic scenarios by putting a channel into Stasis and calling 'move' in
various ways, including trying to move to an application that doesn't
exist, moving to an application without specifying arguments, moving to
an application while specifying a single argument, and moving to an
application while specifying multiple arguments. If the channel leaves
Stasis and enters dialplan for any reason, a UserEvent is in place that
will catch it and fail the test.

Change-Id: I83a2da829dc363727de8c7b56680d21692011e40
---
A tests/rest_api/move/configs/ast1/extensions.conf
A tests/rest_api/move/rest_move.py
A tests/rest_api/move/test-config.yaml
M tests/rest_api/tests.yaml
4 files changed, 169 insertions(+), 0 deletions(-)



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

diff --git a/tests/rest_api/move/configs/ast1/extensions.conf b/tests/rest_api/move/configs/ast1/extensions.conf
new file mode 100644
index 0000000..64b8b3d
--- /dev/null
+++ b/tests/rest_api/move/configs/ast1/extensions.conf
@@ -0,0 +1,10 @@
+[default]
+
+exten => _.,1,UserEvent(Failed)
+
+exten => s,1,Answer()
+ same => n,Stasis(testsuite,destination)
+ same => n,UserEvent(Failed)
+ same => n,Hangup()
+
+exten => h,1,NoOp()
diff --git a/tests/rest_api/move/rest_move.py b/tests/rest_api/move/rest_move.py
new file mode 100644
index 0000000..5777abc
--- /dev/null
+++ b/tests/rest_api/move/rest_move.py
@@ -0,0 +1,37 @@
+'''
+Copyright (C) 2019, Digium, Inc.
+Ben Ford <bford at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import logging
+
+LOGGER = logging.getLogger(__name__)
+
+def on_start(ari, event, test_object):
+
+    app = event['application']
+    chan_id = event['channel']['id']
+
+    if app == "testsuite":
+        # Do this post first - nothing should happen
+        ari.post('channels', chan_id, 'move', app="i-dont-exist")
+        ari.post('channels', chan_id, 'move', app='no-args')
+    elif app == "no-args":
+        ari.post('channels', chan_id, 'move', app='one-arg', appArgs='apples')
+    elif app == "one-arg":
+        ari.post('channels', chan_id, 'move', app="multiple-args", appArgs='apples,bananas,carrots')
+    elif app == "multiple-args":
+        ari.delete('channels', event['channel']['id'])
+
+    return True
+
+def on_end(ari, event, test_object):
+
+    if event['application'] == "multiple-args":
+        LOGGER.info("Final StasisEnd received. Stopping reactor")
+        test_object.stop_reactor()
+
+    return True
diff --git a/tests/rest_api/move/test-config.yaml b/tests/rest_api/move/test-config.yaml
new file mode 100644
index 0000000..e35ff18
--- /dev/null
+++ b/tests/rest_api/move/test-config.yaml
@@ -0,0 +1,121 @@
+testinfo:
+    summary: Test moving from one Stasis application to another.
+    description: |
+        "Test that moving from one Stasis application to another via the
+        move REST API call. That channel should remain in Stasis for the
+        entire duration of the test, until the very end. A UserEvent is
+        in place to ensure that the channel does not leave Stasis, and
+        will fail the test if triggered.
+        
+        A few different scenarios are covered:
+            - Moving from one app to another
+            - Switching apps and supplying one argument
+            - Switching apps and supplying multiple arguments
+            - Attempting to switch to a non-existent app"
+
+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
+        -   config-section: ami-config
+            typename: ami.AMIEventModule
+
+test-object-config:
+    apps: testsuite,no-args,one-arg,multiple-args
+    stop-on-end: False
+
+ari-config:
+    events:
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+            callback:
+                module: rest_move
+                method: on_start
+            count: '1'
+        -   conditions:
+                match:
+                    type: StasisEnd
+                    application: testsuite
+            callback:
+                module: rest_move
+                method: on_end
+            count: '1'
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: no-args
+            callback:
+                module: rest_move
+                method: on_start
+            count: '1'
+        -   conditions:
+                match:
+                    type: StasisEnd
+                    application: no-args
+            callback:
+                module: rest_move
+                method: on_end
+            count: '1'
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: one-arg
+                    args: ['apples']
+            callback:
+                module: rest_move
+                method: on_start
+            count: '1'
+        -   conditions:
+                match:
+                    type: StasisEnd
+                    application: one-arg
+            callback:
+                module: rest_move
+                method: on_end
+            count: '1'
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: multiple-args
+                    args: ['apples','bananas','carrots']
+            callback:
+                module: rest_move
+                method: on_start
+            count: '1'
+        -   conditions:
+                match:
+                    type: StasisEnd
+                    application: multiple-args
+            callback:
+                module: rest_move
+                method: on_end
+            count: '1'
+
+ami-config:
+    -
+        type: 'headermatch'
+        conditions:
+            match:
+                Event: 'UserEvent'
+                UserEvent: 'Failed'
+        count: '0'
+
+
+properties:
+    dependencies:
+        - python : autobahn.websocket
+        - python : requests
+        - python : twisted
+        - python : starpy
+        - asterisk : res_ari_channels
+        - asterisk : app_echo
+    tags:
+        - ARI
+
+
diff --git a/tests/rest_api/tests.yaml b/tests/rest_api/tests.yaml
index ac9303c..8968f8f 100644
--- a/tests/rest_api/tests.yaml
+++ b/tests/rest_api/tests.yaml
@@ -17,3 +17,4 @@
     - dir:  'events'
     - dir:  'message'
     - dir:  'external_interaction'
+    - test: 'move'

-- 
To view, visit https://gerrit.asterisk.org/10897
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: testsuite
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I83a2da829dc363727de8c7b56680d21692011e40
Gerrit-Change-Number: 10897
Gerrit-PatchSet: 1
Gerrit-Owner: Benjamin Keith Ford <bford at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190121/60a593f2/attachment-0001.html>


More information about the asterisk-code-review mailing list