[asterisk-commits] dlee: testsuite/asterisk/trunk r4524 - in /asterisk/trunk/tests/rest_api: ./ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 24 10:39:24 CST 2013


Author: dlee
Date: Tue Dec 24 10:39:19 2013
New Revision: 4524

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4524
Log:
ari: Test for handling Content-Type with params

In fixing ASTERISK-22486, I noticed we weren't properly stripping off
parameters to Content-Type headers. It's easy enough to test, so here's
the test.

Added:
    asterisk/trunk/tests/rest_api/content-type/
    asterisk/trunk/tests/rest_api/content-type/run-test   (with props)
    asterisk/trunk/tests/rest_api/content-type/test-config.yaml   (with props)
Modified:
    asterisk/trunk/tests/rest_api/tests.yaml

Added: asterisk/trunk/tests/rest_api/content-type/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/content-type/run-test?view=auto&rev=4524
==============================================================================
--- asterisk/trunk/tests/rest_api/content-type/run-test (added)
+++ asterisk/trunk/tests/rest_api/content-type/run-test Tue Dec 24 10:39:19 2013
@@ -1,0 +1,62 @@
+#!/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
+
+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
+USERNAME='testsuite'
+PASSWORD='testsuite'
+
+def build_url(*args):
+    return "http://%s:%d/%s" %\
+           (HOST, PORT, '/'.join([str(arg) for arg in args]))
+
+class ARIContentTypeTest(TestCase):
+    def __init__(self):
+        TestCase.__init__(self)
+        self.passed = True
+        self.create_asterisk()
+
+    def run(self):
+        try:
+            # Post with a content type that has a parameter. Requests should
+            # succeed.
+            res = requests.post(
+                build_url('ari', 'asterisk', 'variable'),
+                params={ 'api_key': "%s:%s" % (USERNAME, PASSWORD) },
+                data='{ "variable": "foo", "value": "bar" }',
+                headers={ 'Content-Type': 'application/json; param=ignored'})
+            res.raise_for_status()
+        except:
+            logging.exception("Exception caught during test")
+            self.passed = False
+        finally:
+            self.stop_reactor()
+
+def main():
+    test = ARIContentTypeTest()
+    reactor.run()
+    if test.passed:
+        return 0
+    return 1
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)

Propchange: asterisk/trunk/tests/rest_api/content-type/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/content-type/run-test
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/trunk/tests/rest_api/content-type/run-test
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/rest_api/content-type/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/rest_api/content-type/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/content-type/test-config.yaml?view=auto&rev=4524
==============================================================================
--- asterisk/trunk/tests/rest_api/content-type/test-config.yaml (added)
+++ asterisk/trunk/tests/rest_api/content-type/test-config.yaml Tue Dec 24 10:39:19 2013
@@ -1,0 +1,16 @@
+testinfo:
+    summary: Test Content-Types with parameters.
+    description: |
+        The HTTP spec allows the Content-Type header to specify parameters
+        We can ignore the parameters, but we need to accept the specified
+        Content-Type value.
+
+properties:
+    minversion: '12.0.0'
+    dependencies:
+        - python : twisted
+        - python : starpy
+        - python : requests
+        - asterisk : res_ari_asterisk
+    tags:
+        - ARI

Propchange: asterisk/trunk/tests/rest_api/content-type/test-config.yaml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/content-type/test-config.yaml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

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

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=4524&r1=4523&r2=4524
==============================================================================
--- asterisk/trunk/tests/rest_api/tests.yaml (original)
+++ asterisk/trunk/tests/rest_api/tests.yaml Tue Dec 24 10:39:19 2013
@@ -10,3 +10,4 @@
     - dir:  'device_state'
     - test: 'request-bodies'
     - dir:  'danger'
+    - test: 'content-type'




More information about the asterisk-commits mailing list