[Python-modules-commits] [python-restless] 01/04: fix test fail

Wolfgang Borgert debacle at moszumanska.debian.org
Fri Jan 1 15:03:05 UTC 2016


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository python-restless.

commit d3c1ef683003b1fb6a49cc88a4f31971102232da
Author: mission-liao <missionaryliao at gmail.com>
Date:   Fri Nov 27 16:56:03 2015 +0800

    fix test fail
    
    after tornado 4.0, we need to provide a connection when faking a request
    - and a context object for 4.0.1/4.0.2
---
 tests/test_tnd.py | 42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/tests/test_tnd.py b/tests/test_tnd.py
index 6d8d0a7..4011fc1 100644
--- a/tests/test_tnd.py
+++ b/tests/test_tnd.py
@@ -1,10 +1,33 @@
 import unittest
+import socket
+import six
 
 from restless.tnd import TornadoResource, _BridgeMixin
 from restless.utils import json
-from tornado import testing, web, httpserver, gen
+from tornado import testing, web, httpserver, gen, version_info
+from tornado.iostream import IOStream
 from restless.constants import UNAUTHORIZED
 
+def _newer_or_equal_(v):
+    for i in six.moves.xrange(min(len(v), len(version_info))):
+        expected, tnd = v[i], version_info[i]
+        if tnd > expected:
+            return True
+        elif tnd == expected:
+            continue
+        else:
+            return False
+    return True
+
+def _equal_(v):
+    for i in six.moves.xrange(min(len(v), len(version_info))):
+        if v[i] != version_info[i]:
+            return False
+    return True
+
+
+if _newer_or_equal_((4, 0, 0, 0)):
+    from tornado.http1connection import HTTP1Connection
 
 class TndBaseTestResource(TornadoResource):
     """
@@ -127,7 +150,7 @@ class TndResourceTestCase(BaseHTTPTestCase):
 
 class BaseTestCase(unittest.TestCase):
     """
-    test case that export the wrapped tornado.web.RequestHandler
+    test case that export the wrapped tornado.web.RequestHandler.
     """
     def init_request_handler(self, rh_cls, view_type):
         global app
@@ -136,7 +159,20 @@ class BaseTestCase(unittest.TestCase):
         elif view_type == 'detail':
             rq = rh_cls.as_detail()
 
-        fake_request = httpserver.HTTPRequest('GET', '/fake', body='test123')
+        # compose a fake incoming request
+        fake_connection = None
+
+        # after tornado 4.1, it's not allowed to build a RequestHandler without a connection.
+        if _newer_or_equal_((4, 0, 0, 0)):
+            ios = IOStream(socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0))
+            context = None
+
+            # there is a bug in these 2 version that would fail when
+            # context is None
+            if _equal_((4, 0, 1)) or _equal_((4, 0, 2)):
+                context = httpserver._HTTPRequestContext(ios, None, None)
+            fake_connection = HTTP1Connection(ios, False, context=context)
+        fake_request = httpserver.HTTPRequest('GET', '/fake', body='test123', connection=fake_connection)
         self.new_handler = rq(app, fake_request)
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-restless.git



More information about the Python-modules-commits mailing list