<s> """<STR_LIT>""" <EOL> from nose . tools import eq_ , ok_ , assert_is_instance <EOL> from six import BytesIO <EOL> from six . moves . urllib . parse import urlencode <EOL> from webob import Request <EOL> from tests import BaseDjangoTestCase , complete_environ <EOL> from django_wsgi . handler import APPLICATION <EOL> from django_wsgi . handler import DjangoApplication <EOL> from django_wsgi . handler import DjangoWSGIRequest <EOL> class TestRequest ( BaseDjangoTestCase ) : <EOL> @ staticmethod <EOL> def test_webob_request ( ) : <EOL> """<STR_LIT>""" <EOL> environ = complete_environ ( ) <EOL> request = DjangoWSGIRequest ( environ ) <EOL> ok_ ( hasattr ( request , '<STR_LIT>' ) ) <EOL> assert_is_instance ( request . webob , Request ) <EOL> eq_ ( request . environ , request . webob . environ ) <EOL> @ staticmethod <EOL> def test_request_body_read_by_django_first ( ) : <EOL> """<STR_LIT>""" <EOL> request = _make_stub_post_request ( ) <EOL> eq_ ( <NUM_LIT:2> , len ( request . POST ) ) <EOL> eq_ ( request . POST , request . webob . POST ) <EOL> @ staticmethod <EOL> def test_request_body_read_by_webob_first ( ) : <EOL> """<STR_LIT>""" <EOL> request = _make_stub_post_request ( ) <EOL> eq_ ( <NUM_LIT:2> , len ( request . webob . POST ) ) <EOL> eq_ ( request . webob . POST , request . POST ) <EOL> @ staticmethod <EOL> def test_unseekable_body_read_by_django ( ) : <EOL> request = _make_stub_post_request ( _UnseekableFile ) <EOL> eq_ ( <NUM_LIT:2> , len ( request . POST ) ) <EOL> @ staticmethod <EOL> def test_unseekable_body_read_by_webob ( ) : <EOL> request = _make_stub_post_request ( _UnseekableFile ) <EOL> eq_ ( <NUM_LIT:2> , len ( request . webob . POST ) ) <EOL> def _make_stub_post_request ( wsgi_input_class = BytesIO ) : <EOL> input_ = urlencode ( { '<STR_LIT:foo>' : "<STR_LIT:bar>" , '<STR_LIT:bar>' : "<STR_LIT:foo>" } ) . encode ( ) <EOL> input_length = str ( len ( input_ ) ) <EOL> environ = { <EOL> '<STR_LIT>' : "<STR_LIT:POST>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : input_length , <EOL> '<STR_LIT>' : wsgi_input_class ( input_ ) , <EOL> } <EOL> environ = complete_environ ( ** environ ) <EOL> request = DjangoWSGIRequest ( environ ) <EOL> return request <EOL> class TestWSGIHandler ( BaseDjangoTestCase ) : <EOL> """<STR_LIT>""" <EOL> def setup ( self ) : <EOL> super ( TestWSGIHandler , self ) . setup ( ) <EOL> self . handler = _TelltaleHandler ( ) <EOL> def test_right_request_class ( self ) : <EOL> """<STR_LIT>""" <EOL> environ = complete_environ ( REQUEST_METHOD = "<STR_LIT:GET>" , PATH_INFO = "<STR_LIT:/>" ) <EOL> def start_response ( status , response_headers ) : <EOL> pass <EOL> self . handler ( environ , start_response ) <EOL> ok_ ( isinstance ( self . handler . request , DjangoWSGIRequest ) ) <EOL> def test_handler_instance ( ) : <EOL> assert_is_instance ( APPLICATION , DjangoApplication ) <EOL> class _UnseekableFile ( object ) : <EOL> def __init__ ( self , text ) : <EOL> super ( _UnseekableFile , self ) . __init__ ( ) <EOL> self . _text = BytesIO ( text ) <EOL> def read ( self , * args , ** kwargs ) : <EOL> return self . _text . read ( * args , ** kwargs ) <EOL> class _TelltaleHandler ( DjangoApplication ) : <EOL> def get_response ( self , request ) : <EOL> self . request = request <EOL> return super ( _TelltaleHandler , self ) . get_response ( request ) </s>
