File: 0001-fix-test-fail.patch

package info (click to toggle)
python-restless 2.0.1-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 484 kB
  • ctags: 445
  • sloc: python: 1,887; makefile: 149
file content (81 lines) | stat: -rw-r--r-- 2,862 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From d3c1ef683003b1fb6a49cc88a4f31971102232da Mon Sep 17 00:00:00 2001
From: mission-liao <missionaryliao@gmail.com>
Date: Fri, 27 Nov 2015 16:56:03 +0800
Subject: 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)