[asterisk-commits] dlee: testsuite/asterisk/trunk r4179 - in /asterisk/trunk: lib/python/asteris...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 13 09:24:38 CDT 2013


Author: dlee
Date: Fri Sep 13 09:24:35 2013
New Revision: 4179

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4179
Log:
TestSuite: ARI Bridge Tests

TestSuite tests that test the expected behavior for adding/removing
channel to/from bridges using ARI.

(issue ASTERISK-22036)
Review: https://reviewboard.asterisk.org/r/2770/

Added:
    asterisk/trunk/tests/rest_api/bridges/
      - copied from r4178, asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/
    asterisk/trunk/tests/rest_api/continue/configs/ast1/ari.conf
      - copied unchanged from r4178, asterisk/team/dlee/ari-bridge-tests/tests/rest_api/continue/configs/ast1/ari.conf
Modified:
    asterisk/trunk/lib/python/asterisk/TestCase.py
    asterisk/trunk/lib/python/asterisk/TestConfig.py
    asterisk/trunk/lib/python/asterisk/ari.py
    asterisk/trunk/tests/rest_api/continue/test-config.yaml
    asterisk/trunk/tests/rest_api/tests.yaml

Modified: asterisk/trunk/lib/python/asterisk/TestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/TestCase.py?view=diff&rev=4179&r1=4178&r2=4179
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestCase.py (original)
+++ asterisk/trunk/lib/python/asterisk/TestCase.py Fri Sep 13 09:24:35 2013
@@ -384,7 +384,14 @@
         has occurred.
         """
         logger.warning("Reactor timeout: '%s' seconds" % self.reactor_timeout)
+        self.on_reactor_timeout()
         self.stop_reactor()
+
+    def on_reactor_timeout(self):
+        """
+        Override to run when reactor times out
+        """
+        pass
 
     def __run(self):
         """

Modified: asterisk/trunk/lib/python/asterisk/TestConfig.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/lib/python/asterisk/TestConfig.py?view=diff&rev=4179&r1=4178&r2=4179
==============================================================================
--- asterisk/trunk/lib/python/asterisk/TestConfig.py (original)
+++ asterisk/trunk/lib/python/asterisk/TestConfig.py Fri Sep 13 09:24:35 2013
@@ -406,6 +406,9 @@
         if not self.config:
             return False
 
+        if not "properties" in self.config:
+            raise ValueError("%s: Missing properties section" % self.test_name)
+
         self.deps = [
             Dependency(d)
                 for d in self.config["properties"].get("dependencies") or []

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=4179&r1=4178&r2=4179
==============================================================================
--- asterisk/trunk/lib/python/asterisk/ari.py (original)
+++ asterisk/trunk/lib/python/asterisk/ari.py Fri Sep 13 09:24:35 2013
@@ -69,6 +69,7 @@
         self.test_iteration = 0
         self.channels = []
         self._ws_event_handlers = []
+        self.timed_out = False
 
         if self.iterations is None:
             self.iterations = [{'channel': 'Local/s at default',
@@ -92,11 +93,21 @@
         '''
         self._ws_event_handlers.append(callback)
 
+    def on_reactor_timeout(self):
+        self.timed_out = True
+        # Fail the tests if we have timed out
+        self.set_passed(False)
+
     def on_ws_event(self, message):
         ''' Handler for WebSocket events
 
         :param message The WS event payload
         '''
+        if self.timed_out:
+            # Ignore messages received after timeout
+            LOGGER.debug("Ignoring message received after timeout")
+            return
+
         for handler in self._ws_event_handlers:
             handler(message)
 
@@ -300,6 +311,7 @@
         '''
         self.base_url = "http://%s:%d/ari" % (host, port)
         self.userpass = userpass
+        self.allow_errors = False
 
     def build_url(self, *args):
         '''Build a URL from the given path.
@@ -323,7 +335,7 @@
         '''
         url = self.build_url(*args)
         LOGGER.info("GET %s %r" % (url, kwargs))
-        return raise_on_err(requests.get(url, params=kwargs,
+        return self.raise_on_err(requests.get(url, params=kwargs,
                                          auth=self.userpass))
 
     def post(self, *args, **kwargs):
@@ -334,9 +346,9 @@
         :returns: requests.models.Response
         :throws: requests.exceptions.HTTPError
         '''
-        url = self.build_url(*args, **kwargs)
+        url = self.build_url(*args)
         LOGGER.info("POST %s %r" % (url, kwargs))
-        return raise_on_err(requests.post(url, params=kwargs,
+        return self.raise_on_err(requests.post(url, params=kwargs,
                                           auth=self.userpass))
 
     def delete(self, *args, **kwargs):
@@ -347,20 +359,32 @@
         :returns: requests.models.Response
         :throws: requests.exceptions.HTTPError
         '''
-        url = self.build_url(*args, **kwargs)
+        url = self.build_url(*args)
         LOGGER.info("DELETE %s %r" % (url, kwargs))
-        return raise_on_err(requests.delete(url, params=kwargs,
+        return self.raise_on_err(requests.delete(url, params=kwargs,
                                             auth=self.userpass))
 
-
-def raise_on_err(resp):
-    '''Helper to raise an exception when a response is a 4xx or 5xx error.
-
-    :param resp: requests.models.Response object
-    :returns: resp
-    '''
-    resp.raise_for_status()
-    return resp
+    def set_allow_errors(self, v):
+        '''Sets whether error responses returns exceptions.
+
+        If True, then error responses are returned. Otherwise, methods throw
+        an exception on error.
+
+        :param v True/False value for allow_errors.
+        '''
+        self.allow_errors = v
+
+    def raise_on_err(self, resp):
+        '''Helper to raise an exception when a response is a 4xx or 5xx error.
+
+        If allow_errors is True, then an exception is not raised.
+
+        :param resp: requests.models.Response object
+        :returns: resp
+        '''
+        if not self.allow_errors:
+            resp.raise_for_status()
+        return resp
 
 
 class EventMatcher(object):
@@ -380,7 +404,7 @@
             self.callback = getattr(module, callback['method'])
         else:
             # No callback; just use a no-op
-            self.callback = lambda **kwargs: None
+            self.callback = lambda *args, **kwargs: True
 
         test_object.register_stop_observer(self.on_stop)
 

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=4179&r1=4178&r2=4179
==============================================================================
--- asterisk/trunk/tests/rest_api/continue/test-config.yaml (original)
+++ asterisk/trunk/tests/rest_api/continue/test-config.yaml Fri Sep 13 09:24:35 2013
@@ -52,7 +52,7 @@
         - python : requests
         - python : twisted
         - python : starpy
-        - asterisk : res_ari_channels
+        - asterisk : res_stasis_http_channels
         - asterisk : app_echo
     tags:
         - ARI

Modified: asterisk/trunk/tests/rest_api/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/tests.yaml?view=diff&rev=4179&r1=4178&r2=4179
==============================================================================
--- asterisk/trunk/tests/rest_api/tests.yaml (original)
+++ asterisk/trunk/tests/rest_api/tests.yaml Fri Sep 13 09:24:35 2013
@@ -3,3 +3,4 @@
     - test: 'continue'
     - test: 'authentication'
     - test: 'CORS'
+    - dir:  'bridges'




More information about the asterisk-commits mailing list