[asterisk-commits] dlee: branch dlee/ASTERISK-22451-ari-subscribe-tests r4163 - /asterisk/team/d...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 11 14:15:18 CDT 2013
Author: dlee
Date: Wed Sep 11 14:15:17 2013
New Revision: 4163
URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4163
Log:
Changes from my bridge test patch
Modified:
asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestCase.py
asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestConfig.py
asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/ari.py
Modified: asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestCase.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestCase.py?view=diff&rev=4163&r1=4162&r2=4163
==============================================================================
--- asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestCase.py (original)
+++ asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestCase.py Wed Sep 11 14:15:17 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/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestConfig.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestConfig.py?view=diff&rev=4163&r1=4162&r2=4163
==============================================================================
--- asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestConfig.py (original)
+++ asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/TestConfig.py Wed Sep 11 14:15:17 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/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/ari.py
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/ari.py?view=diff&rev=4163&r1=4162&r2=4163
==============================================================================
--- asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/ari.py (original)
+++ asterisk/team/dlee/ASTERISK-22451-ari-subscribe-tests/lib/python/asterisk/ari.py Wed Sep 11 14:15:17 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)
@@ -304,6 +315,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.
@@ -327,7 +339,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):
@@ -340,7 +352,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):
@@ -353,18 +365,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(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):
More information about the asterisk-commits
mailing list