[svn-commits] mmichelson: testsuite/asterisk/trunk r6192 - in /asterisk/trunk: lib/python/a...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jan 7 13:32:00 CST 2015


Author: mmichelson
Date: Wed Jan  7 13:31:55 2015
New Revision: 6192

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=6192
Log:
Add tests for continuation and origination.

There was already a test for continuation, but this expands the test to cover many more
test cases.

This also adds a test originating calls to different dialplan locations to make sure that
different combinations of extension, context, priority, and label work as expected.

Review https://reviewboard.asterisk.org/r/4284


Added:
    asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/
    asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/configs/
    asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/configs/ast1/
    asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/configs/ast1/extensions.conf   (with props)
    asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/test-config.yaml   (with props)
Modified:
    asterisk/trunk/lib/python/asterisk/ari.py
    asterisk/trunk/tests/rest_api/channels/tests.yaml
    asterisk/trunk/tests/rest_api/continue/configs/ast1/extensions.conf
    asterisk/trunk/tests/rest_api/continue/rest_continue.py
    asterisk/trunk/tests/rest_api/continue/test-config.yaml

Modified: asterisk/trunk/lib/python/asterisk/ari.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/ari.py?view=diff&rev=6192&r1=6191&r2=6192
==============================================================================
--- asterisk/trunk/lib/python/asterisk/ari.py (original)
+++ asterisk/trunk/lib/python/asterisk/ari.py Wed Jan  7 13:31:55 2015
@@ -432,9 +432,10 @@
         :throws: requests.exceptions.HTTPError
         """
         url = self.build_url(*args)
+        json = kwargs.pop('json', None)
         LOGGER.info("PUT %s %r", url, kwargs)
         return self.raise_on_err(requests.put(url, params=kwargs,
-                                              auth=self.userpass))
+                                              json=json, auth=self.userpass))
 
     def post(self, *args, **kwargs):
         """Send a POST request to ARI.
@@ -445,9 +446,10 @@
         :throws: requests.exceptions.HTTPError
         """
         url = self.build_url(*args)
+        json = kwargs.pop('json', None)
         LOGGER.info("POST %s %r", url, kwargs)
         return self.raise_on_err(requests.post(url, params=kwargs,
-                                               auth=self.userpass))
+                                               json=json, auth=self.userpass))
 
     def delete(self, *args, **kwargs):
         """Send a DELETE request to ARI.

Added: asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/configs/ast1/extensions.conf?view=auto&rev=6192
==============================================================================
--- asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/configs/ast1/extensions.conf (added)
+++ asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/configs/ast1/extensions.conf Wed Jan  7 13:31:55 2015
@@ -1,0 +1,41 @@
+[default]
+exten => echo,1,Answer()
+same => n,Echo()
+same => n,Hangup()
+
+exten => test,1,UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 2,Hangup()
+same => 3,UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 4,Hangup()
+same => 5(dopey),UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 6,Hangup()
+same => 7(doc),UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 8,Hangup()
+same => 9,UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 10,Hangup()
+same => 11,UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 12,Hangup()
+
+; Having an h extension prevents _. from matching when the channel hangs up
+exten => h,1,NoOp()
+
+exten => _.,1,UserEvent(Failed)
+
+[grumpy]
+exten => test,1,UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 2,Hangup()
+same => 3,UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 4,Hangup()
+same => 5(sleepy),UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 6,Hangup()
+same => 7(bashful),UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 8,Hangup()
+same => 9,UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 10,Hangup()
+same => 11,UserEvent(${IF($[${location} = ${EXTEN}@${CONTEXT}:${PRIORITY}]?Success:Failed)})
+same => 12,Hangup()
+
+; Having an h extension prevents _. from matching when the channel hangs up
+exten => h,1,NoOp()
+
+exten => _.,1,UserEvent(Failed)

Propchange: asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/configs/ast1/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

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

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

Added: asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/test-config.yaml?view=auto&rev=6192
==============================================================================
--- asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/test-config.yaml (added)
+++ asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/test-config.yaml Wed Jan  7 13:31:55 2015
@@ -1,0 +1,128 @@
+testinfo:
+    summary: 'Test ARI origination to dialplan locations'
+    description: |
+        'This attempts to test originating to the dialplan, using all
+        combinations of extension, context, priority, and label. The
+        originations go in the following order:
+        * Only extension specified
+        * Extension and priority specified
+        * Extension and label specified
+        * Extension, priority, and label specified
+        * Extension and numeric label specified
+        * Extension, priority, and numeric label specified
+        * All of the above repeated, this time specifying a context.
+
+        In total there are 12 originations performed. Each origination
+        sets a channel variable on the channel that specifies where we
+        expect the origination to end up. A user event is emitted from
+        the dialplan to indicate if the results meet expectations.'
+
+properties:
+    minversion: '13.2.0'
+    dependencies:
+        - python: autobahn.websocket
+        - python: requests
+        - python: twisted
+        - python: starpy
+        - asterisk: res_ari_channels
+        - asterisk: app_userevent
+        - asterisk: app_echo
+    tags:
+        - ARI
+
+test-modules:
+    test-object:
+        config-section: originate-config
+        typename: ari.AriOriginateTestObject
+    modules:
+        -
+            config-section: ami-config
+            typename: ami.AMIEventModule
+
+
+originate-config:
+    test-iterations:
+        -
+            endpoint: 'Local/echo at default'
+            extension: 'test'
+            json: {'variables': {'location': 'test at default:1'}}
+        -
+            endpoint: 'Local/echo at default'
+            extension: 'test'
+            priority: 3
+            json: {'variables': {'location': 'test at default:3'}}
+        -
+            endpoint: 'Local/echo at default'
+            extension: 'test'
+            label: 'dopey'
+            json: {'variables': {'location': 'test at default:5'}}
+        -
+            endpoint: 'Local/echo at default'
+            extension: 'test'
+            priority: 5
+            label: 'doc'
+            json: {'variables': {'location': 'test at default:7'}}
+        -
+            endpoint: 'Local/echo at default'
+            extension: 'test'
+            label: '9'
+            json: {'variables': {'location': 'test at default:9'}}
+        -
+            endpoint: 'Local/echo at default'
+            extension: 'test'
+            priority: 5
+            label: '11'
+            json: {'variables': {'location': 'test at default:11'}}
+        -
+            endpoint: 'Local/echo at default'
+            context: 'grumpy'
+            extension: 'test'
+            json: {'variables': {'location': 'test at grumpy:1'}}
+        -
+            endpoint: 'Local/echo at default'
+            context: 'grumpy'
+            extension: 'test'
+            priority: 3
+            json: {'variables': {'location': 'test at grumpy:3'}}
+        -
+            endpoint: 'Local/echo at default'
+            context: 'grumpy'
+            extension: 'test'
+            label: 'sleepy'
+            json: {'variables': {'location': 'test at grumpy:5'}}
+        -
+            endpoint: 'Local/echo at default'
+            context: 'grumpy'
+            extension: 'test'
+            priority: 5
+            label: 'bashful'
+            json: {'variables': {'location': 'test at grumpy:7'}}
+        -
+            endpoint: 'Local/echo at default'
+            context: 'grumpy'
+            extension: 'test'
+            label: '9'
+            json: {'variables': {'location': 'test at grumpy:9'}}
+        -
+            endpoint: 'Local/echo at default'
+            context: 'grumpy'
+            extension: 'test'
+            priority: 5
+            label: '11'
+            json: {'variables': {'location': 'test at grumpy:11'}}
+
+ami-config:
+    -
+        type: 'headermatch'
+        conditions:
+            match:
+                Event: 'UserEvent'
+                UserEvent: 'Success'
+        count: '12'
+    -
+        type: 'headermatch'
+        conditions:
+            match:
+                Event: 'UserEvent'
+                UserEvent: 'Failed'
+        count: '0'

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

Propchange: asterisk/trunk/tests/rest_api/channels/originate_to_dialplan/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

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

Modified: asterisk/trunk/tests/rest_api/channels/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/channels/tests.yaml?view=diff&rev=6192&r1=6191&r2=6192
==============================================================================
--- asterisk/trunk/tests/rest_api/channels/tests.yaml (original)
+++ asterisk/trunk/tests/rest_api/channels/tests.yaml Wed Jan  7 13:31:55 2015
@@ -9,3 +9,4 @@
     - test: 'snoop_id'
     - dir: 'playback'
     - test: 'connected_line_update'
+    - test: 'originate_to_dialplan'

Modified: asterisk/trunk/tests/rest_api/continue/configs/ast1/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/continue/configs/ast1/extensions.conf?view=diff&rev=6192&r1=6191&r2=6192
==============================================================================
--- asterisk/trunk/tests/rest_api/continue/configs/ast1/extensions.conf (original)
+++ asterisk/trunk/tests/rest_api/continue/configs/ast1/extensions.conf Wed Jan  7 13:31:55 2015
@@ -1,7 +1,63 @@
 [default]
 
-exten => s,1,NoOp()
-	same => n,Answer()
-	same => n,Stasis(testsuite)
-	same => n,Stasis(testsuite,fin)
-	same => n,Hangup()
+;Having an h extension prevents the _. from matching when the channel hangs up
+exten => h,1,NoOp()
+
+exten => _.,1,UserEvent(Failed)
+
+exten => s,1,Answer()
+	same => 2,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 3,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 4,UserEvent(Failed)
+	same => 5,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 6,UserEvent(Failed)
+	same => 7(eggs),Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 8,UserEvent(Failed)
+	same => 9(toast),Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 10,UserEvent(Failed)
+	same => 11,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 12,UserEvent(Failed)
+	same => 13,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+
+exten => bacon,1,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 2,UserEvent(Failed)
+	same => 3,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 4,UserEvent(Failed)
+	same => 5(muffin),Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 6,UserEvent(Failed)
+	same => 7(bagel),Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 8,UserEvent(Failed)
+	same => 9,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 10,UserEvent(Failed)
+	same => 11,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+
+[taters]
+
+;Having an h extension prevents the _. from matching when the channel hangs up
+exten => h,1,NoOp()
+
+exten => _.,1,UserEvent(Failed)
+
+exten => s,1,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 2,UserEvent(Failed)
+	same => 3,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 4,UserEvent(Failed)
+	same => 5(hollandaise),Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 6,UserEvent(Failed)
+	same => 7(cereal),Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 8,UserEvent(Failed)
+	same => 9,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 10,UserEvent(Failed)
+	same => 11,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+
+exten => biscuit,1,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 2,UserEvent(Failed)
+	same => 3,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 4,UserEvent(Failed)
+	same => 5(sausage),Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 6,UserEvent(Failed)
+	same => 7(pancakes),Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 8,UserEvent(Failed)
+	same => 9,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})
+	same => 10,UserEvent(Failed)
+	same => 11,Stasis(testsuite,${EXTEN}@${CONTEXT}:${PRIORITY})

Modified: asterisk/trunk/tests/rest_api/continue/rest_continue.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/continue/rest_continue.py?view=diff&rev=6192&r1=6191&r2=6192
==============================================================================
--- asterisk/trunk/tests/rest_api/continue/rest_continue.py (original)
+++ asterisk/trunk/tests/rest_api/continue/rest_continue.py Wed Jan  7 13:31:55 2015
@@ -1,6 +1,7 @@
 '''
-Copyright (C) 2013, Digium, Inc.
+Copyright (C) 2013-2014, Digium, Inc.
 David M. Lee, II <dlee at digium.com>
+Mark Michelson <mmichelson at digium.com>
 
 This program is free software, distributed under the terms of
 the GNU General Public License Version 2.
@@ -8,35 +9,103 @@
 
 import logging
 
-logger = logging.getLogger(__name__)
+LOGGER = logging.getLogger(__name__)
 
-id = None
+# Successive places to continue the call in the dialplan
+CONTINUATIONS = [
+    None,
 
-STASIS_END_EVENTS = 0
+    # Specifying no context or extension
+    {},
+    {'priority': 5},
+    {'label': 'eggs'},
+    {'priority': 5, 'label': 'toast'},
+    {'label': '11'},
+    {'priority': 5, 'label': '13'},
 
+    # Specifying extension but no context
+    {'extension': 'bacon'},
+    {'extension': 'bacon', 'priority': 3},
+    {'extension': 'bacon', 'label': 'muffin'},
+    {'extension': 'bacon', 'priority': 5, 'label': 'bagel'},
+    {'extension': 'bacon', 'label': '9'},
+    {'extension': 'bacon', 'priority': 5, 'label': '11'},
+
+    # Specifying context but no extension
+    {'context': 'taters'},
+    {'context': 'taters', 'priority': 3},
+    {'context': 'taters', 'label': 'hollandaise'},
+    {'context': 'taters', 'priority': 5, 'label': 'cereal'},
+    {'context': 'taters', 'label': '9'},
+    {'context': 'taters', 'priority': 5, 'label': '11'},
+
+    # Specifying context and extension
+    {'context': 'taters', 'extension': 'biscuit'},
+    {'context': 'taters', 'extension': 'biscuit', 'priority': 3},
+    {'context': 'taters', 'extension': 'biscuit', 'label': 'sausage'},
+    {'context': 'taters', 'extension': 'biscuit', 'priority': 5, 'label': 'pancakes'},
+    {'context': 'taters', 'extension': 'biscuit', 'label': '9'},
+    {'context': 'taters', 'extension': 'biscuit', 'priority': 5, 'label': '11'},
+]
+
+# Spacing used in this list helps line up with continuations in previous list
+EXPECTATIONS = [
+    's at default:2',
+
+    's at default:3',
+    's at default:5',
+    's at default:7',
+    's at default:9',
+    's at default:11',
+    's at default:13',
+
+    'bacon at default:1',
+    'bacon at default:3',
+    'bacon at default:5',
+    'bacon at default:7',
+    'bacon at default:9',
+    'bacon at default:11',
+
+    's at taters:1',
+    's at taters:3',
+    's at taters:5',
+    's at taters:7',
+    's at taters:9',
+    's at taters:11',
+
+    'biscuit at taters:1',
+    'biscuit at taters:3',
+    'biscuit at taters:5',
+    'biscuit at taters:7',
+    'biscuit at taters:9',
+    'biscuit at taters:11',
+]
+
+CURRENT_EVENT = 0
 
 def on_start(ari, event, test_object):
-    logger.debug("on_start(%r)" % event)
-    global id
-    id = event['channel']['id']
-    ari.post('channels', id, 'continue')
+    location = event['args'][0]
+    global CURRENT_EVENT
+
+    if location != EXPECTATIONS[CURRENT_EVENT]:
+        LOGGER.error("Stasis entered from {0}, expected {1}".format(location,
+            EXPECTATIONS[CURRENT_EVENT]))
+        return False
+
+    LOGGER.info("Stasis entered from expected location {0}".format(location))
+    CURRENT_EVENT += 1
+    if CURRENT_EVENT == len(CONTINUATIONS):
+        ari.delete('channels', event['channel']['id'])
+        return True
+
+    ari.post('channels', event['channel']['id'], 'continue',
+             **CONTINUATIONS[CURRENT_EVENT])
     return True
 
-
 def on_end(ari, event, test_object):
-    global id
-    global STASIS_END_EVENTS
-
-    logger.debug("on_end(%r)" % event)
-    STASIS_END_EVENTS += 1
-    if (STASIS_END_EVENTS == 2):
+    # We don't really care about StasisEnd until the final one
+    if CURRENT_EVENT == len(CONTINUATIONS):
+        LOGGER.info("Final StasisEnd received. Stopping reactor")
         test_object.stop_reactor()
 
-    return id == event['channel']['id']
-
-
-def on_second_start(ari, event, test_object):
-    global id
-    logger.debug("on_second_start(%r)" % event)
-    ari.delete('channels', id)
-    return id == event['channel']['id']
+    return True

Modified: asterisk/trunk/tests/rest_api/continue/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/continue/test-config.yaml?view=diff&rev=6192&r1=6191&r2=6192
==============================================================================
--- asterisk/trunk/tests/rest_api/continue/test-config.yaml (original)
+++ asterisk/trunk/tests/rest_api/continue/test-config.yaml Wed Jan  7 13:31:55 2015
@@ -1,8 +1,16 @@
 testinfo:
     summary: Test continuing on from the RESTful API back to the dialplan
     description: |
-        This test simply waits for a call via the WebSocket, then hits the
-        continue controller to send it back to the dialplan.
+        "This exhaustively tests the continue operation on channel resource. The
+        channel is entered into Stasis and then continued to the dialplan in a particular
+        location. At that location, the channel then re-enters Stasis. Each time the
+        channel enters Stasis, the channel gives its current dialplan location as an
+        application argument. The Stasis application checks this against its expected
+        entrance locations in order to determine if the continuation put the channel
+        into the expected place in the dialplan.
+
+        The dialplan also has 'traps' that will emit UserEvents that will automatically
+        fail the test if the channel reaches that extension."
 
 test-modules:
     add-test-to-search-path: True
@@ -12,6 +20,8 @@
     modules:
         -   config-section: ari-config
             typename: ari.WebSocketEventModule
+        -   config-section: ami-config
+            typename: ami.AMIEventModule
 
 test-object-config:
     stop-on-end: False
@@ -22,31 +32,31 @@
                 match:
                     type: StasisStart
                     application: testsuite
-                    args: []
-            count: 1
             callback:
                 module: rest_continue
                 method: on_start
+            count: '25'
         -   conditions:
                 match:
                     type: StasisEnd
                     application: testsuite
-            count: 2
             callback:
                 module: rest_continue
                 method: on_end
-        -   conditions:
-                match:
-                    type: StasisStart
-                    application: testsuite
-                    args: [fin]
-            count: 1
-            callback:
-                module: rest_continue
-                method: on_second_start
+            count: '25'
+
+ami-config:
+    -
+        type: 'headermatch'
+        conditions:
+            match:
+                Event: 'UserEvent'
+                UserEvent: 'Failed'
+        count: '0'
+
 
 properties:
-    minversion: '12.0.0'
+    minversion: '13.2.0'
     dependencies:
         - python : autobahn.websocket
         - python : requests




More information about the svn-commits mailing list