Skip to content

fix test fail #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions tests/test_tnd.py
Original file line number Diff line number Diff line change
@@ -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):
"""
Expand Down Expand Up @@ -127,7 +150,7 @@ def test_not_authenticated(self):

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
Expand All @@ -136,7 +159,20 @@ def init_request_handler(self, rh_cls, view_type):
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)


Expand Down