Skip to content

Commit 8b81b17

Browse files
committed
Framework tests skipped when they're not present
1 parent 372e00a commit 8b81b17

File tree

4 files changed

+61
-16
lines changed

4 files changed

+61
-16
lines changed

Diff for: tests/test_dj.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import unittest
22

3-
from django.http import Http404
4-
from django.core.exceptions import ObjectDoesNotExist
3+
try:
4+
from django.http import Http404
5+
from django.core.exceptions import ObjectDoesNotExist
56

6-
# Ugh. Settings for Django.
7-
from django.conf import settings
8-
settings.configure(DEBUG=True)
7+
# Ugh. Settings for Django.
8+
from django.conf import settings
9+
settings.configure(DEBUG=True)
10+
11+
from restless.dj import DjangoResource
12+
except ImportError:
13+
settings = None
14+
DjangoResource = object
915

10-
from restless.dj import DjangoResource
1116
from restless.exceptions import Unauthorized
1217
from restless.preparers import FieldsPreparer
1318
from restless.resources import skip_prepare
@@ -125,6 +130,7 @@ def detail(self, pk):
125130
raise Http404("Model with pk {0} not found.".format(pk))
126131

127132

133+
@unittest.skipIf(not settings, "Django is not available")
128134
class DjangoResourceTestCase(unittest.TestCase):
129135
def setUp(self):
130136
super(DjangoResourceTestCase, self).setUp()

Diff for: tests/test_fl.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import unittest
22

3-
# Ugh. Globals for Flask.
4-
import flask
3+
try:
4+
# Ugh. Globals for Flask.
5+
import flask
6+
from restless.fl import FlaskResource
7+
except ImportError:
8+
flask = None
9+
FlaskResource = object
510

6-
from restless.fl import FlaskResource
711
from restless.utils import json
812

913
from .fakes import FakeHttpRequest
@@ -32,6 +36,7 @@ def create(self):
3236
self.fake_db.append(self.data)
3337

3438

39+
@unittest.skipIf(not flask, 'Flask is not available')
3540
class FlaskResourceTestCase(unittest.TestCase):
3641
def setUp(self):
3742
super(FlaskResourceTestCase, self).setUp()

Diff for: tests/test_pyr.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import unittest
22

3-
from pyramid import testing
3+
try:
4+
from pyramid import testing
5+
from restless.pyr import PyramidResource
6+
except ImportError:
7+
testing = None
8+
PyramidResource = object
49

5-
from restless.pyr import PyramidResource
610
from restless.utils import json
711

812
from .fakes import FakeHttpRequest, FakeHttpResponse
@@ -36,6 +40,8 @@ def is_authenticated(self):
3640

3741
return True
3842

43+
44+
@unittest.skipIf(not testing, 'Pyramid is not available')
3945
class PyramidResourceTestCase(unittest.TestCase):
4046
def setUp(self):
4147
self.config = testing.setUp()

Diff for: tests/test_tnd.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
import socket
33
import six
44

5-
from restless.tnd import TornadoResource, _BridgeMixin
65
from restless.utils import json
7-
from tornado import testing, web, httpserver, gen, version_info
8-
from tornado.iostream import IOStream
96
from restless.constants import UNAUTHORIZED
107

8+
119
def _newer_or_equal_(v):
1210
for i in six.moves.xrange(min(len(v), len(version_info))):
1311
expected, tnd = v[i], version_info[i]
@@ -19,15 +17,38 @@ def _newer_or_equal_(v):
1917
return False
2018
return True
2119

20+
2221
def _equal_(v):
2322
for i in six.moves.xrange(min(len(v), len(version_info))):
2423
if v[i] != version_info[i]:
2524
return False
2625
return True
2726

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
2851

29-
if _newer_or_equal_((4, 0, 0, 0)):
30-
from tornado.http1connection import HTTP1Connection
3152

3253
class TndBaseTestResource(TornadoResource):
3354
"""
@@ -89,6 +110,7 @@ def create(self):
89110
], debug=True)
90111

91112

113+
@unittest.skipIf(not app, 'Tornado is not available')
92114
class BaseHTTPTestCase(testing.AsyncHTTPTestCase):
93115
"""
94116
base of test case
@@ -97,6 +119,7 @@ def get_app(self):
97119
return app
98120

99121

122+
@unittest.skipIf(not app, 'Tornado is not available')
100123
class TndResourceTestCase(BaseHTTPTestCase):
101124
"""
102125
"""
@@ -148,6 +171,7 @@ def test_not_authenticated(self):
148171
self.assertEqual(resp.code, UNAUTHORIZED)
149172

150173

174+
@unittest.skipIf(not app, 'Tornado is not available')
151175
class BaseTestCase(unittest.TestCase):
152176
"""
153177
test case that export the wrapped tornado.web.RequestHandler.
@@ -176,6 +200,7 @@ def init_request_handler(self, rh_cls, view_type):
176200
self.new_handler = rq(app, fake_request)
177201

178202

203+
@unittest.skipIf(not app, 'Tornado is not available')
179204
class InternalTestCase(BaseTestCase):
180205
"""
181206
test-cases that check internal structure of the wrapped
@@ -213,6 +238,7 @@ def test_var(self):
213238
self.assertTrue(hasattr(self.new_handler.resource_handler, 'application'))
214239

215240

241+
@unittest.skipIf(not app, 'Tornado is not available')
216242
class TndDeleteTestResource(TndBasicTestResource):
217243
"""
218244
testing inherited resource
@@ -224,6 +250,7 @@ def delete_list(self):
224250
self.fake_db = {}
225251

226252

253+
@unittest.skipIf(not app, 'Tornado is not available')
227254
class FuncTrimTestCase(BaseTestCase):
228255
"""
229256
test-cases that make sure we removed unnecessary handler functions
@@ -258,6 +285,7 @@ def test_inheritance_resource_detail(self):
258285
self.assertNotIn('put', self.new_handler.__class__.__dict__)
259286

260287

288+
@unittest.skipIf(not app, 'Tornado is not available')
261289
class TndAsyncResourceTestCase(BaseHTTPTestCase):
262290
"""
263291
test asynchronous view_method

0 commit comments

Comments
 (0)