2
2
import socket
3
3
import six
4
4
5
- from restless .tnd import TornadoResource , _BridgeMixin
6
5
from restless .utils import json
7
- from tornado import testing , web , httpserver , gen , version_info
8
- from tornado .iostream import IOStream
9
6
from restless .constants import UNAUTHORIZED
10
7
8
+
11
9
def _newer_or_equal_ (v ):
12
10
for i in six .moves .xrange (min (len (v ), len (version_info ))):
13
11
expected , tnd = v [i ], version_info [i ]
@@ -19,15 +17,38 @@ def _newer_or_equal_(v):
19
17
return False
20
18
return True
21
19
20
+
22
21
def _equal_ (v ):
23
22
for i in six .moves .xrange (min (len (v ), len (version_info ))):
24
23
if v [i ] != version_info [i ]:
25
24
return False
26
25
return True
27
26
27
+ try :
28
+ from restless .tnd import TornadoResource , _BridgeMixin
29
+ from tornado import testing , web , httpserver , gen , version_info
30
+ from tornado .iostream import IOStream
31
+ if _newer_or_equal_ ((4 , 0 , 0 , 0 )):
32
+ from tornado .http1connection import HTTP1Connection
33
+ except ImportError :
34
+ class testing :
35
+ AsyncHTTPTestCase = object
36
+
37
+ class web :
38
+ @staticmethod
39
+ def Application (* args , ** kw ): return False
40
+
41
+ class gen :
42
+ @staticmethod
43
+ def coroutine (fn ): return fn
44
+
45
+ class TornadoResource :
46
+ @staticmethod
47
+ def as_list (): pass
48
+
49
+ @staticmethod
50
+ def as_detail (): pass
28
51
29
- if _newer_or_equal_ ((4 , 0 , 0 , 0 )):
30
- from tornado .http1connection import HTTP1Connection
31
52
32
53
class TndBaseTestResource (TornadoResource ):
33
54
"""
@@ -89,6 +110,7 @@ def create(self):
89
110
], debug = True )
90
111
91
112
113
+ @unittest .skipIf (not app , 'Tornado is not available' )
92
114
class BaseHTTPTestCase (testing .AsyncHTTPTestCase ):
93
115
"""
94
116
base of test case
@@ -97,6 +119,7 @@ def get_app(self):
97
119
return app
98
120
99
121
122
+ @unittest .skipIf (not app , 'Tornado is not available' )
100
123
class TndResourceTestCase (BaseHTTPTestCase ):
101
124
"""
102
125
"""
@@ -148,6 +171,7 @@ def test_not_authenticated(self):
148
171
self .assertEqual (resp .code , UNAUTHORIZED )
149
172
150
173
174
+ @unittest .skipIf (not app , 'Tornado is not available' )
151
175
class BaseTestCase (unittest .TestCase ):
152
176
"""
153
177
test case that export the wrapped tornado.web.RequestHandler.
@@ -176,6 +200,7 @@ def init_request_handler(self, rh_cls, view_type):
176
200
self .new_handler = rq (app , fake_request )
177
201
178
202
203
+ @unittest .skipIf (not app , 'Tornado is not available' )
179
204
class InternalTestCase (BaseTestCase ):
180
205
"""
181
206
test-cases that check internal structure of the wrapped
@@ -213,6 +238,7 @@ def test_var(self):
213
238
self .assertTrue (hasattr (self .new_handler .resource_handler , 'application' ))
214
239
215
240
241
+ @unittest .skipIf (not app , 'Tornado is not available' )
216
242
class TndDeleteTestResource (TndBasicTestResource ):
217
243
"""
218
244
testing inherited resource
@@ -224,6 +250,7 @@ def delete_list(self):
224
250
self .fake_db = {}
225
251
226
252
253
+ @unittest .skipIf (not app , 'Tornado is not available' )
227
254
class FuncTrimTestCase (BaseTestCase ):
228
255
"""
229
256
test-cases that make sure we removed unnecessary handler functions
@@ -258,6 +285,7 @@ def test_inheritance_resource_detail(self):
258
285
self .assertNotIn ('put' , self .new_handler .__class__ .__dict__ )
259
286
260
287
288
+ @unittest .skipIf (not app , 'Tornado is not available' )
261
289
class TndAsyncResourceTestCase (BaseHTTPTestCase ):
262
290
"""
263
291
test asynchronous view_method
0 commit comments