[asterisk-commits] dlee: branch dlee/ari-req-bodies r4325 - in /asterisk/team/dlee/ari-req-bodie...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 4 14:36:53 CST 2013


Author: dlee
Date: Mon Nov  4 14:36:51 2013
New Revision: 4325

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4325
Log:
Test for form and JSON request bodies

Added:
    asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/
    asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/run-test   (with props)
    asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/test-config.yaml   (with props)
Modified:
    asterisk/team/dlee/ari-req-bodies/tests/rest_api/tests.yaml

Added: asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/run-test?view=auto&rev=4325
==============================================================================
--- asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/run-test (added)
+++ asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/run-test Mon Nov  4 14:36:51 2013
@@ -1,0 +1,90 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2013, Digium, Inc.
+David M. Lee, II <dlee at digium.com>
+
+This program is free software, distributed under the terms of
+the GNU General Public License Version 2.
+'''
+
+import logging
+import requests
+import sys
+import urllib
+
+from requests import codes
+from twisted.internet import reactor
+
+sys.path.append("lib/python")
+from asterisk.asterisk import Asterisk
+from asterisk.TestCase import TestCase
+
+LOGGER = logging.getLogger(__name__)
+
+HOST='localhost'
+PORT=8088
+
+def build_url(*args):
+    url = "http://%s:%d/%s" %\
+           (HOST, PORT, '/'.join([str(arg) for arg in args]))
+    params = urllib.urlencode({'api_key': 'testsuite:testsuite'})
+    return "%s?%s" % (url, params)
+
+
+class ARIRequestBodyTest(TestCase):
+    def __init__(self):
+        TestCase.__init__(self)
+        self.passed = True
+        self.create_asterisk()
+
+    def run(self):
+        try:
+            self.test_form_data()
+            self.test_json_data()
+            self.test_bad_json_data()
+        except:
+            logging.exception("Exception caught during test")
+            self.passed = False
+            raise
+        finally:
+            self.stop_reactor()
+
+    def test_form_data(self):
+        form = {"type": "holding"}
+        resp = requests.post(build_url('ari', 'bridges'), data=form)
+        resp.raise_for_status()
+        actual_bridge_type = resp.json()['bridge_type']
+        if 'holding' != actual_bridge_type:
+            LOGGER.error("Unexpected bridge type: %s" % actual_bridge_type)
+            self.passed = False
+
+    def test_json_data(self):
+        body = '{"type": "holding"}'
+        headers = {'Content-type': 'application/json'}
+        resp = requests.post(build_url('ari', 'bridges'), data=body,
+                             headers=headers)
+        resp.raise_for_status()
+        actual_bridge_type = resp.json()['bridge_type']
+        if 'holding' != actual_bridge_type:
+            LOGGER.error("Unexpected bridge type: %s" % actual_bridge_type)
+            self.passed = False
+
+    def test_bad_json_data(self):
+        body = '{"type": "holding", invalid json}'
+        headers = {'Content-type': 'application/json'}
+        resp = requests.post(build_url('ari', 'bridges'), data=body,
+                             headers=headers)
+        if 400 != resp.status_code:
+            LOGGER.error("Expected bad request error, got %d", resp.status_code)
+            self.passed = False
+
+
+def main():
+    test = ARIRequestBodyTest()
+    reactor.run()
+    if test.passed:
+        return 0
+    return 1
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)

Propchange: asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/run-test
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/run-test
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/test-config.yaml?view=auto&rev=4325
==============================================================================
--- asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/test-config.yaml (added)
+++ asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/test-config.yaml Mon Nov  4 14:36:51 2013
@@ -1,0 +1,16 @@
+testinfo:
+    summary: Test authentication for the RESTful API
+    description: |
+        This test attempts several accesses to the RESTful API via all of its
+        authentication mechanisms, making sure we don't accidentally leave the
+        door open for everyone.
+
+properties:
+    minversion: '12.0.0'
+    dependencies:
+        - python : twisted
+        - python : starpy
+        - python : requests
+        - asterisk : res_ari_channels
+    tags:
+        - ARI

Propchange: asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/team/dlee/ari-req-bodies/tests/rest_api/request-bodies/test-config.yaml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: asterisk/team/dlee/ari-req-bodies/tests/rest_api/tests.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/team/dlee/ari-req-bodies/tests/rest_api/tests.yaml?view=diff&rev=4325&r1=4324&r2=4325
==============================================================================
--- asterisk/team/dlee/ari-req-bodies/tests/rest_api/tests.yaml (original)
+++ asterisk/team/dlee/ari-req-bodies/tests/rest_api/tests.yaml Mon Nov  4 14:36:51 2013
@@ -6,3 +6,4 @@
     - dir:  'applications'
     - dir:  'bridges'
     - dir:  'recording'
+    - test: 'request-bodies'




More information about the asterisk-commits mailing list