[asterisk-commits] mmichelson: testsuite/asterisk/trunk r5000 - in /asterisk/trunk/tests: channe...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 28 09:43:28 CDT 2014


Author: mmichelson
Date: Mon Apr 28 09:43:20 2014
New Revision: 5000

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=5000
Log:
Add tests for the new DeviceStateChanged and PresenceStateChanged tests.

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


Added:
    asterisk/trunk/tests/channels/pjsip/subscriptions/presence/repeat/
    asterisk/trunk/tests/manager/device_state_changed/
    asterisk/trunk/tests/manager/device_state_changed/ami_device_state.py   (with props)
    asterisk/trunk/tests/manager/device_state_changed/test-config.yaml   (with props)
    asterisk/trunk/tests/manager/presence_state_changed/
    asterisk/trunk/tests/manager/presence_state_changed/ami_presence_state.py   (with props)
    asterisk/trunk/tests/manager/presence_state_changed/test-config.yaml   (with props)
Modified:
    asterisk/trunk/tests/manager/tests.yaml

Added: asterisk/trunk/tests/manager/device_state_changed/ami_device_state.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/device_state_changed/ami_device_state.py?view=auto&rev=5000
==============================================================================
--- asterisk/trunk/tests/manager/device_state_changed/ami_device_state.py (added)
+++ asterisk/trunk/tests/manager/device_state_changed/ami_device_state.py Mon Apr 28 09:43:20 2014
@@ -1,0 +1,61 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2014, Digium, Inc.
+Mark Michelson <mmichelson at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import logging
+from test_case import TestCase
+
+LOGGER = logging.getLogger(__name__)
+
+STATES = [
+    'NOT_INUSE',
+    'INUSE',
+    'BUSY',
+    'INVALID',
+    'UNAVAILABLE',
+    'RINGING',
+    'RINGINUSE',
+]
+
+
+class AMIDeviceState(TestCase):
+    def __init__(self, path=None, config=None):
+        super(AMIDeviceState, self).__init__(path, config)
+        self.create_asterisk()
+        self.state_pos = 0
+
+    def run(self):
+        super(AMIDeviceState, self).run()
+        self.create_ami_factory()
+
+    def device_state_event(self, ami, event):
+        if event.get('device') != 'Custom:Eggs':
+            return
+
+        state = event.get('state')
+        expected_state = STATES[self.state_pos]
+        if state != expected_state:
+            LOGGER.error("Unexpected state received. Expected {0} but got \
+                         {1}".format(expected_state, state))
+            self.set_passed(False)
+            self.stop_reactor()
+
+        self.state_pos += 1
+        if self.state_pos >= len(STATES):
+            self.set_passed(True)
+            self.stop_reactor()
+
+    def ami_connect(self, ami):
+        ami.registerEvent('DeviceStateChange', self.device_state_event)
+        for state in STATES:
+            message = {
+                'Action': 'SetVar',
+                'Variable': 'DEVICE_STATE(Custom:Eggs)',
+                'Value': state
+            }
+            ami.sendMessage(message)

Propchange: asterisk/trunk/tests/manager/device_state_changed/ami_device_state.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/manager/device_state_changed/ami_device_state.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/manager/device_state_changed/ami_device_state.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/manager/device_state_changed/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/device_state_changed/test-config.yaml?view=auto&rev=5000
==============================================================================
--- asterisk/trunk/tests/manager/device_state_changed/test-config.yaml (added)
+++ asterisk/trunk/tests/manager/device_state_changed/test-config.yaml Mon Apr 28 09:43:20 2014
@@ -1,0 +1,21 @@
+testinfo:
+    summary: 'Test that DeviceStateChange events fire when expected.'
+    description: |
+        "A script sets a device's state many times, and we ensure that the corresponding expected
+        manager events fire in proper order."
+
+properties:
+    minversion: '13.0.0'
+    dependencies:
+        - python: 'twisted'
+        - python: 'starpy'
+        - asterisk: 'res_manager_devicestate'
+    tags:
+        - AMI
+
+test-modules:
+    add-test-to-search-path: 'True'
+    test-object:
+        config-section: object-config
+        typename: 'ami_device_state.AMIDeviceState'
+

Propchange: asterisk/trunk/tests/manager/device_state_changed/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/manager/device_state_changed/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/manager/device_state_changed/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/manager/presence_state_changed/ami_presence_state.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/presence_state_changed/ami_presence_state.py?view=auto&rev=5000
==============================================================================
--- asterisk/trunk/tests/manager/presence_state_changed/ami_presence_state.py (added)
+++ asterisk/trunk/tests/manager/presence_state_changed/ami_presence_state.py Mon Apr 28 09:43:20 2014
@@ -1,0 +1,69 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2014, Digium, Inc.
+Mark Michelson <mmichelson at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import logging
+from test_case import TestCase
+
+LOGGER = logging.getLogger(__name__)
+
+STATES = [
+    {'status': 'unavailable', 'subtype': 'scrambled', 'message': 'breakfast'},
+    {'status': 'available', 'subtype': 'fried', 'message': 'brunch'},
+    {'status': 'away', 'subtype': 'poached', 'message': 'lunch'},
+    {'status': 'xa', 'subtype': 'meringue', 'message': 'snack'},
+    {'status': 'chat', 'subtype': 'custard', 'message': 'dinner'},
+    {'status': 'dnd', 'subtype': 'souffle', 'message': 'dessert'},
+]
+
+
+class AMIPresenceState(TestCase):
+    def __init__(self, path=None, config=None):
+        super(AMIPresenceState, self).__init__(path, config)
+        self.create_asterisk()
+        self.state_pos = 0
+
+    def run(self):
+        super(AMIPresenceState, self).run()
+        self.create_ami_factory()
+
+    def check_parameter(self, event, parameter):
+        actual = event.get(parameter)
+        expected = STATES[self.state_pos][parameter]
+        if actual != expected:
+            LOGGER.error("Unexpected {0} received. Expected {1} but got \
+                         {2}".format(parameter, expected, actual))
+            self.set_passed(False)
+            self.stop_reactor()
+
+    def presence_state_event(self, ami, event):
+        if event.get('presentity') != 'CustomPresence:Eggs':
+            return
+
+        self.check_parameter(event, 'status')
+        self.check_parameter(event, 'subtype')
+        self.check_parameter(event, 'message')
+
+        self.state_pos += 1
+        if self.state_pos >= len(STATES):
+            self.set_passed(True)
+            self.stop_reactor()
+
+    def ami_connect(self, ami):
+        ami.registerEvent('PresenceStateChange', self.presence_state_event)
+        for state in STATES:
+            status = state['status']
+            subtype = state['subtype']
+            message = state['message']
+
+            ami_message = {
+                'Action': 'SetVar',
+                'Variable': 'PRESENCE_STATE(CustomPresence:Eggs)',
+                'Value': "{0},{1},{2}".format(status, subtype, message)
+            }
+            ami.sendMessage(ami_message)

Propchange: asterisk/trunk/tests/manager/presence_state_changed/ami_presence_state.py
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/manager/presence_state_changed/ami_presence_state.py
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/manager/presence_state_changed/ami_presence_state.py
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/manager/presence_state_changed/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/presence_state_changed/test-config.yaml?view=auto&rev=5000
==============================================================================
--- asterisk/trunk/tests/manager/presence_state_changed/test-config.yaml (added)
+++ asterisk/trunk/tests/manager/presence_state_changed/test-config.yaml Mon Apr 28 09:43:20 2014
@@ -1,0 +1,21 @@
+testinfo:
+    summary: 'Test that PresenceStateChange events fire when expected.'
+    description: |
+        "A script sets a presentity's state many times, and we ensure that the corresponding expected
+        manager events fire in proper order."
+
+properties:
+    minversion: '13.0.0'
+    dependencies:
+        - python: 'twisted'
+        - python: 'starpy'
+        - asterisk: 'res_manager_presencestate'
+    tags:
+        - AMI
+
+test-modules:
+    add-test-to-search-path: 'True'
+    test-object:
+        config-section: object-config
+        typename: 'ami_presence_state.AMIPresenceState'
+

Propchange: asterisk/trunk/tests/manager/presence_state_changed/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/manager/presence_state_changed/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/manager/presence_state_changed/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/trunk/tests/manager/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/manager/tests.yaml?view=diff&rev=5000&r1=4999&r2=5000
==============================================================================
--- asterisk/trunk/tests/manager/tests.yaml (original)
+++ asterisk/trunk/tests/manager/tests.yaml Mon Apr 28 09:43:20 2014
@@ -8,5 +8,7 @@
     - test: 'bridge_actions'
     - dir:  'danger'
     - test: 'originate'
+    - test: 'device_state_changed'
+    - test: 'presence_state_changed'
     # Temporarily disabled while failures are debugged
     #- test: 'response-time'




More information about the asterisk-commits mailing list