[asterisk-commits] dlee: branch dlee/ari-bridge-tests r4019 - in /asterisk/team/dlee/ari-bridge-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 14 13:38:50 CDT 2013


Author: dlee
Date: Wed Aug 14 13:38:48 2013
New Revision: 4019

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4019
Log:
More happiness

Modified:
    asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py
    asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/happy/bridge_happy.py
    asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml

Modified: asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py?view=diff&rev=4019&r1=4018&r2=4019
==============================================================================
--- asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py (original)
+++ asterisk/team/dlee/ari-bridge-tests/lib/python/asterisk/ari.py Wed Aug 14 13:38:48 2013
@@ -312,6 +312,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.
@@ -335,7 +336,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):
@@ -348,7 +349,7 @@
         '''
         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):
@@ -361,18 +362,30 @@
         '''
         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(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):

Modified: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/happy/bridge_happy.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/happy/bridge_happy.py?view=diff&rev=4019&r1=4018&r2=4019
==============================================================================
--- asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/happy/bridge_happy.py (original)
+++ asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/happy/bridge_happy.py Wed Aug 14 13:38:48 2013
@@ -10,7 +10,7 @@
 
 LOGGER = logging.getLogger(__name__)
 
-class BridgeSimple(object):
+class BridgeHappy(object):
     def on_start(self, ari, event):
         LOGGER.debug("on_start(%r)" % event)
         self.channel_id = event['channel']['id']
@@ -35,7 +35,7 @@
         ari.delete('channels', channel_id)
         return True
 
-TEST = BridgeSimple()
+TEST = BridgeHappy()
 
 def on_start(ari, event):
     return TEST.on_start(ari, event)

Modified: asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml?view=diff&rev=4019&r1=4018&r2=4019
==============================================================================
--- asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml (original)
+++ asterisk/team/dlee/ari-bridge-tests/tests/rest_api/bridges/tests.yaml Wed Aug 14 13:38:48 2013
@@ -1,4 +1,5 @@
 tests:
     - test: 'happy'
+    - test: 'sad'
     - test: 'hangup'
     - test: 'move'




More information about the asterisk-commits mailing list