[asterisk-commits] sgriepentrog: testsuite/asterisk/trunk r4575 - in /asterisk/trunk/tests/rest_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 17 14:57:23 CST 2014


Author: sgriepentrog
Date: Fri Jan 17 14:57:15 2014
New Revision: 4575

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=4575
Log:
testsuite: check chunked Transfer-Encoding operation

Using the requests library with a generator, send several
chunked transfer requests via ARI with a JSON body to set
a variable, then read it back to insure no errors.

(issue ASTERISK-23068)
Reported by: Matt Jordan


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

Added: asterisk/trunk/tests/rest_api/chunked-transfer/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/chunked-transfer/run-test?view=auto&rev=4575
==============================================================================
--- asterisk/trunk/tests/rest_api/chunked-transfer/run-test (added)
+++ asterisk/trunk/tests/rest_api/chunked-transfer/run-test Fri Jan 17 14:57:15 2014
@@ -1,0 +1,113 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2014, Digium, Inc.
+Scott Griepentrog <sgriepentrog 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 json
+import sys
+
+from twisted.internet import reactor
+
+sys.path.append("lib/python")
+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]))
+
+
+def chunkizer(test):
+    for char in list(test):
+        yield char
+
+
+def large_chunkizer(test):
+    split = len(test) / 2
+    yield test[:split]
+    yield test[split:]
+
+
+class ARIChunkedTransferTest(TestCase):
+    def __init__(self):
+        TestCase.__init__(self)
+        self.passed = False
+        self.create_asterisk()
+
+    def run(self):
+        pass1 = False
+        pass2 = False
+        try:
+            ''' small chunks '''
+            res = requests.post(
+                build_url('ari', 'asterisk', 'variable'),
+                params={'api_key': "%s:%s" % (USERNAME, PASSWORD)},
+                data=chunkizer('{ "variable": "foo", "value": "bar" }'),
+                headers={'Content-Type': 'application/json', })
+            res.raise_for_status()
+
+            res = requests.get(
+                build_url('ari', 'asterisk', 'variable'),
+                params={'api_key': "%s:%s" % (USERNAME, PASSWORD)},
+                data='{ "variable": "foo"}',
+                headers={'Content-Type': 'application/json', })
+            res.raise_for_status()
+
+            result = json.loads(res.text)
+            if result['value'] == 'bar':
+                pass1 = True
+
+            ''' big chunks '''
+            value = 'all work and no play makes jack a dull boy.' * 5
+            res = requests.post(
+                build_url('ari', 'asterisk', 'variable'),
+                params={'api_key': "%s:%s" % (USERNAME, PASSWORD)},
+                data=large_chunkizer('{ "variable": "foo2", "value": "' +
+                                     value + '" }'),
+                headers={'Content-Type': 'application/json', })
+            res.raise_for_status()
+
+            res = requests.get(
+                build_url('ari', 'asterisk', 'variable'),
+                params={'api_key': "%s:%s" % (USERNAME, PASSWORD)},
+                data='{ "variable": "foo2"}',
+                headers={'Content-Type': 'application/json', })
+            res.raise_for_status()
+
+            result = json.loads(res.text)
+            if result['value'] == value:
+                pass2 = True
+
+        except:
+            logging.exception("Exception caught during test")
+
+        if pass1 and pass2:
+                self.passed = True
+
+        self.stop_reactor()
+
+
+def main():
+    test = ARIChunkedTransferTest()
+    reactor.run()
+    if test.passed:
+        return 0
+    return 1
+
+if __name__ == "__main__":
+    sys.exit(main() or 0)
+
+# vim: set ts=8 sw=4 sts=4 et ai tw=79:

Propchange: asterisk/trunk/tests/rest_api/chunked-transfer/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/rest_api/chunked-transfer/run-test
------------------------------------------------------------------------------
    svn:executable = *

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

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

Added: asterisk/trunk/tests/rest_api/chunked-transfer/test-config.yaml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/rest_api/chunked-transfer/test-config.yaml?view=auto&rev=4575
==============================================================================
--- asterisk/trunk/tests/rest_api/chunked-transfer/test-config.yaml (added)
+++ asterisk/trunk/tests/rest_api/chunked-transfer/test-config.yaml Fri Jan 17 14:57:15 2014
@@ -1,0 +1,15 @@
+testinfo:
+    summary: Test chunked Transfer-Encoding.
+    description: |
+        Check that the res_http supports chunked transfer encoding by
+        setting a variable and reading it back.
+
+properties:
+    minversion: '12.0.0'
+    dependencies:
+        - python : twisted
+        - python : starpy
+        - python : requests
+        - asterisk : res_ari_asterisk
+    tags:
+        - ARI

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

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

Propchange: asterisk/trunk/tests/rest_api/chunked-transfer/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=4575&r1=4574&r2=4575
==============================================================================
--- asterisk/trunk/tests/rest_api/tests.yaml (original)
+++ asterisk/trunk/tests/rest_api/tests.yaml Fri Jan 17 14:57:15 2014
@@ -11,3 +11,4 @@
     - test: 'request-bodies'
     - dir:  'danger'
     - test: 'content-type'
+    - test: 'chunked-transfer'




More information about the asterisk-commits mailing list