[Asterisk-code-review] rest-api: Tests for external media (...testsuite[16])

Friendly Automation asteriskteam at digium.com
Tue Sep 10 13:39:42 CDT 2019


Friendly Automation has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/testsuite/+/12783 )

Change subject: rest-api:  Tests for external media
......................................................................

rest-api:  Tests for external media

Change-Id: I0ebd6bc75ea853ba5912bdf300dd60af8bb76ae8
---
A tests/rest_api/channels/external_media/nominal/configs/ast1/extensions.conf
A tests/rest_api/channels/external_media/nominal/create_with_vars.py
A tests/rest_api/channels/external_media/nominal/test-config.yaml
A tests/rest_api/channels/external_media/off-nominal/configs/ast1/extensions.conf
A tests/rest_api/channels/external_media/off-nominal/off_nominal.py
A tests/rest_api/channels/external_media/off-nominal/test-config.yaml
A tests/rest_api/channels/external_media/tests.yaml
M tests/rest_api/channels/tests.yaml
8 files changed, 208 insertions(+), 1 deletion(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/tests/rest_api/channels/external_media/nominal/configs/ast1/extensions.conf b/tests/rest_api/channels/external_media/nominal/configs/ast1/extensions.conf
new file mode 100644
index 0000000..6741734
--- /dev/null
+++ b/tests/rest_api/channels/external_media/nominal/configs/ast1/extensions.conf
@@ -0,0 +1,8 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,Answer()
+	same => n,Stasis(testsuite)
+	same => n,Hangup()
+
+
diff --git a/tests/rest_api/channels/external_media/nominal/create_with_vars.py b/tests/rest_api/channels/external_media/nominal/create_with_vars.py
new file mode 100644
index 0000000..9366376
--- /dev/null
+++ b/tests/rest_api/channels/external_media/nominal/create_with_vars.py
@@ -0,0 +1,34 @@
+'''
+Copyright (C) 2019, Sangoma Technologies Corporation
+George Joseph <gjoseph at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import json
+import requests
+
+def on_start(ari, event, obj):
+    params = {
+        'channelId': 'testsuite-default-id',
+        'external_host': '127.0.0.1:59999',
+        'app': 'testsuite',
+        'encapsulation': 'rtp',
+        'transport': 'udp',
+        'format': 'ulaw',
+        'json': {'variables': {'CALLERID(name)': 'foo'}}
+        }
+
+    resp = ari.post('channels', 'externalMedia', **params)
+
+    assert resp.json()['channel']['caller']['name'] == 'foo'
+    assert resp.json()['local_address']
+    assert resp.json()['local_port']
+
+    # Delete the channel we just created
+    ari.delete('channels', resp.json()['channel']['id'])
+    # Delete the implicit channel created by the test object
+    ari.delete('channels', event['channel']['id'])
+
+    return True
diff --git a/tests/rest_api/channels/external_media/nominal/test-config.yaml b/tests/rest_api/channels/external_media/nominal/test-config.yaml
new file mode 100644
index 0000000..02826b1
--- /dev/null
+++ b/tests/rest_api/channels/external_media/nominal/test-config.yaml
@@ -0,0 +1,45 @@
+testinfo:
+    summary: Test External Media channel creation
+    description: |
+        Creates an externalMedia channel and checks to make sure the specified
+        channel variable(s) got set.
+
+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: True
+
+ari-config:
+    apps: testsuite
+    events:
+       # This is the StasisStart for the implicit Local channel
+       # created by the test object.  When we get it, we create
+       # the externalMedia channel.
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+                    args: []
+                    channel:
+                       name: 'Local'
+            count: 1
+            callback:
+                module: create_with_vars
+                method: on_start
+
+properties:
+    dependencies:
+        - python : autobahn.websocket
+        - python : requests
+        - python : twisted
+        - python : starpy
+        - asterisk : res_ari_channels
+    tags:
+        - ARI
diff --git a/tests/rest_api/channels/external_media/off-nominal/configs/ast1/extensions.conf b/tests/rest_api/channels/external_media/off-nominal/configs/ast1/extensions.conf
new file mode 100644
index 0000000..6741734
--- /dev/null
+++ b/tests/rest_api/channels/external_media/off-nominal/configs/ast1/extensions.conf
@@ -0,0 +1,8 @@
+[default]
+
+exten => s,1,NoOp()
+	same => n,Answer()
+	same => n,Stasis(testsuite)
+	same => n,Hangup()
+
+
diff --git a/tests/rest_api/channels/external_media/off-nominal/off_nominal.py b/tests/rest_api/channels/external_media/off-nominal/off_nominal.py
new file mode 100644
index 0000000..9de234a
--- /dev/null
+++ b/tests/rest_api/channels/external_media/off-nominal/off_nominal.py
@@ -0,0 +1,62 @@
+'''
+Copyright (C) 2019, Sangoma Technologies Corporation
+George Joseph <gjoseph at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import json
+import logging
+from requests.exceptions import HTTPError
+import requests
+
+LOGGER = logging.getLogger(__name__)
+
+def try_create(ari, channel_id, host, format, encapsulation, transport, resp_code):
+
+    params = {
+        'channelId': channel_id,
+        'app': 'testsuite'
+    }
+    if host:
+        params['external_host'] = host
+    if format:
+        params['format'] = format
+    if encapsulation:
+        params['encapsulation'] = encapsulation
+    if transport:
+        params['transport'] = transport
+
+    try:
+        resp = ari.post('channels', 'externalMedia', **params)
+    except HTTPError as e:
+        if e.response.status_code != resp_code:
+            LOGGER.error("Unexpected response {0}".format(e.response))
+            return False
+        return True
+    except:
+        LOGGER.error("Unexpected exception when originating")
+        return False
+    else:
+        if resp_code != 200:
+            LOGGER.error("Originate succeeded when we expected failure")
+            return False
+        return True
+
+def on_start(ari, event, obj):
+    if event['args'] == ['FAIL']:
+        LOGGER.error("Unexpected StasisStart on duplicate ID channel")
+        return False
+
+    passed = (
+        try_create(ari, "test1", "127.0.0.1:59999", "ulaw", "rtp", "XXX", 501)     # bad transport
+        and try_create(ari, "test2", "127.0.0.1:59999", "ulaw", "YYY", "udp", 501) # bad encapsulation
+        and try_create(ari, "test3", "127.0.0.1:59999", "ulaw", "YYY", "XXX", 501) # both bad
+        and try_create(ari, "test4", None, "ulaw", "rtp", "udp", 400)              # no host
+        and try_create(ari, "test5", "127.0.0.1:59999", None, "rtp", "udp", 400)   # no format
+        and try_create(ari, "test6", "127.0.0.1:59999", "XXX", "rtp", "udp", 400)  # bad format
+        and try_create(ari, "test7", "127.0.0.1", "ulaw", "rtp", "udp", 400)       # bad host
+        )
+    ari.delete("channels", event['channel']['id'])
+    return passed
diff --git a/tests/rest_api/channels/external_media/off-nominal/test-config.yaml b/tests/rest_api/channels/external_media/off-nominal/test-config.yaml
new file mode 100644
index 0000000..d247c2e
--- /dev/null
+++ b/tests/rest_api/channels/external_media/off-nominal/test-config.yaml
@@ -0,0 +1,45 @@
+testinfo:
+    summary: Test External Media channel failure
+    description: |
+        Attempts to create an externalMedia channel with unsupported
+        or missing parameters.
+
+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: True
+
+ari-config:
+    apps: testsuite
+    events:
+       # This is the StasisStart for the implicit Local channel
+       # created by the test object.  When we get it, we
+       # try to create the externalMedia channels.
+        -   conditions:
+                match:
+                    type: StasisStart
+                    application: testsuite
+                    args: []
+                    channel:
+                       name: 'Local'
+            count: 1
+            callback:
+                module: off_nominal
+                method: on_start
+
+properties:
+    dependencies:
+        - python : autobahn.websocket
+        - python : requests
+        - python : twisted
+        - python : starpy
+        - asterisk : res_ari_channels
+    tags:
+        - ARI
diff --git a/tests/rest_api/channels/external_media/tests.yaml b/tests/rest_api/channels/external_media/tests.yaml
new file mode 100644
index 0000000..1253ff8
--- /dev/null
+++ b/tests/rest_api/channels/external_media/tests.yaml
@@ -0,0 +1,4 @@
+# Enter tests here in the order they should be considered for execution:
+tests:
+    - test: 'nominal'
+    - test: 'off-nominal'
diff --git a/tests/rest_api/channels/tests.yaml b/tests/rest_api/channels/tests.yaml
index 090788e..b585099 100644
--- a/tests/rest_api/channels/tests.yaml
+++ b/tests/rest_api/channels/tests.yaml
@@ -15,4 +15,5 @@
     - dir: 'hold'
     - test: 'originate_duplicate_id'
     - test: 'create_duplicate_id'
-    - dir: 'rtp_statistics'
\ No newline at end of file
+    - dir: 'rtp_statistics'
+    - dir: 'external_media'

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

Gerrit-Project: testsuite
Gerrit-Branch: 16
Gerrit-Change-Id: I0ebd6bc75ea853ba5912bdf300dd60af8bb76ae8
Gerrit-Change-Number: 12783
Gerrit-PatchSet: 3
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190910/e31498b8/attachment-0001.html>


More information about the asterisk-code-review mailing list