<s> from __future__ import unicode_literals <EOL> from django . utils import six <EOL> from channels import Channel <EOL> from channels . tests import ChannelTestCase <EOL> from channels . handler import AsgiRequest <EOL> from channels . exceptions import RequestTimeout , RequestAborted <EOL> class RequestTests ( ChannelTestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_basic ( self ) : <EOL> """<STR_LIT>""" <EOL> Channel ( "<STR_LIT:test>" ) . send ( { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:GET>" , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> } ) <EOL> request = AsgiRequest ( self . get_next_message ( "<STR_LIT:test>" ) ) <EOL> self . assertEqual ( request . path , "<STR_LIT>" ) <EOL> self . assertEqual ( request . method , "<STR_LIT:GET>" ) <EOL> self . assertFalse ( request . body ) <EOL> self . assertNotIn ( "<STR_LIT>" , request . META ) <EOL> self . assertNotIn ( "<STR_LIT>" , request . META ) <EOL> self . assertNotIn ( "<STR_LIT>" , request . META ) <EOL> self . assertNotIn ( "<STR_LIT>" , request . META ) <EOL> self . assertNotIn ( "<STR_LIT>" , request . META ) <EOL> self . assertNotIn ( "<STR_LIT>" , request . META ) <EOL> self . assertFalse ( request . GET ) <EOL> self . assertFalse ( request . POST ) <EOL> self . assertFalse ( request . COOKIES ) <EOL> def test_extended ( self ) : <EOL> """<STR_LIT>""" <EOL> Channel ( "<STR_LIT:test>" ) . send ( { <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:GET>" , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:host>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , <NUM_LIT> ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" , <NUM_LIT> ] , <EOL> } ) <EOL> request = AsgiRequest ( self . get_next_message ( "<STR_LIT:test>" ) ) <EOL> self . assertEqual ( request . path , "<STR_LIT>" ) <EOL> self . assertEqual ( request . method , "<STR_LIT:GET>" ) <EOL> self . assertFalse ( request . body ) <EOL> self . assertEqual ( request . META [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . META [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . META [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . META [ "<STR_LIT>" ] , <NUM_LIT> ) <EOL> self . assertEqual ( request . META [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . META [ "<STR_LIT>" ] , <NUM_LIT> ) <EOL> self . assertEqual ( request . GET [ "<STR_LIT:x>" ] , "<STR_LIT:1>" ) <EOL> self . assertEqual ( request . GET [ "<STR_LIT:y>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . COOKIES [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . COOKIES [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertFalse ( request . POST ) <EOL> def test_post_single ( self ) : <EOL> """<STR_LIT>""" <EOL> Channel ( "<STR_LIT:test>" ) . send ( { <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:POST>" , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:body>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:host>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> } , <EOL> } ) <EOL> request = AsgiRequest ( self . get_next_message ( "<STR_LIT:test>" ) ) <EOL> self . assertEqual ( request . path , "<STR_LIT>" ) <EOL> self . assertEqual ( request . method , "<STR_LIT:POST>" ) <EOL> self . assertEqual ( request . body , b"<STR_LIT>" ) <EOL> self . assertEqual ( request . META [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . META [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . GET [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . POST [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> with self . assertRaises ( KeyError ) : <EOL> request . POST [ "<STR_LIT>" ] <EOL> with self . assertRaises ( KeyError ) : <EOL> request . GET [ "<STR_LIT>" ] <EOL> def test_post_multiple ( self ) : <EOL> """<STR_LIT>""" <EOL> Channel ( "<STR_LIT:test>" ) . send ( { <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:POST>" , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT:body>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:host>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> } , <EOL> } ) <EOL> Channel ( "<STR_LIT>" ) . send ( { <EOL> "<STR_LIT:content>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> Channel ( "<STR_LIT>" ) . send ( { <EOL> "<STR_LIT:content>" : b"<STR_LIT>" , <EOL> } ) <EOL> request = AsgiRequest ( self . get_next_message ( "<STR_LIT:test>" ) ) <EOL> self . assertEqual ( request . method , "<STR_LIT:POST>" ) <EOL> self . assertEqual ( request . body , b"<STR_LIT>" ) <EOL> self . assertEqual ( request . META [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . POST [ "<STR_LIT>" ] , "<STR_LIT>" ) <EOL> def test_post_files ( self ) : <EOL> """<STR_LIT>""" <EOL> body = ( <EOL> b'<STR_LIT>' + <EOL> b'<STR_LIT>' + <EOL> b'<STR_LIT>' + <EOL> b'<STR_LIT>' + <EOL> b'<STR_LIT>' + <EOL> b'<STR_LIT>' + <EOL> b'<STR_LIT>' <EOL> ) <EOL> Channel ( "<STR_LIT:test>" ) . send ( { <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:POST>" , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : six . text_type ( len ( body ) ) . encode ( "<STR_LIT:ascii>" ) , <EOL> } , <EOL> } ) <EOL> Channel ( "<STR_LIT>" ) . send ( { <EOL> "<STR_LIT:content>" : body [ : <NUM_LIT:20> ] , <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> Channel ( "<STR_LIT>" ) . send ( { <EOL> "<STR_LIT:content>" : body [ <NUM_LIT:20> : ] , <EOL> } ) <EOL> request = AsgiRequest ( self . get_next_message ( "<STR_LIT:test>" ) ) <EOL> self . assertEqual ( request . method , "<STR_LIT:POST>" ) <EOL> self . assertEqual ( len ( request . body ) , len ( body ) ) <EOL> self . assertTrue ( request . META [ "<STR_LIT>" ] . startswith ( "<STR_LIT>" ) ) <EOL> self . assertFalse ( request . _post_parse_error ) <EOL> self . assertEqual ( request . POST [ "<STR_LIT:title>" ] , "<STR_LIT>" ) <EOL> self . assertEqual ( request . FILES [ "<STR_LIT>" ] . read ( ) , b"<STR_LIT>" ) <EOL> def test_stream ( self ) : <EOL> """<STR_LIT>""" <EOL> Channel ( "<STR_LIT:test>" ) . send ( { <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:path>" : "<STR_LIT:/>" , <EOL> "<STR_LIT:body>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:host>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> } , <EOL> } ) <EOL> request = AsgiRequest ( self . get_next_message ( "<STR_LIT:test>" , require = True ) ) <EOL> self . assertEqual ( request . method , "<STR_LIT>" ) <EOL> self . assertEqual ( request . read ( <NUM_LIT:3> ) , b"<STR_LIT>" ) <EOL> self . assertEqual ( request . read ( ) , b"<STR_LIT>" ) <EOL> def test_request_timeout ( self ) : <EOL> """<STR_LIT>""" <EOL> Channel ( "<STR_LIT:test>" ) . send ( { <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:POST>" , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT:body>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:host>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> } , <EOL> } ) <EOL> Channel ( "<STR_LIT>" ) . send ( { <EOL> "<STR_LIT:content>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> class VeryImpatientRequest ( AsgiRequest ) : <EOL> body_receive_timeout = <NUM_LIT:0> <EOL> with self . assertRaises ( RequestTimeout ) : <EOL> VeryImpatientRequest ( self . get_next_message ( "<STR_LIT:test>" ) ) <EOL> def test_request_abort ( self ) : <EOL> """<STR_LIT>""" <EOL> Channel ( "<STR_LIT:test>" ) . send ( { <EOL> "<STR_LIT>" : "<STR_LIT:test>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:POST>" , <EOL> "<STR_LIT:path>" : "<STR_LIT>" , <EOL> "<STR_LIT:body>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:host>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> "<STR_LIT>" : b"<STR_LIT>" , <EOL> } , <EOL> } ) <EOL> Channel ( "<STR_LIT>" ) . send ( { <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> with self . assertRaises ( RequestAborted ) : <EOL> AsgiRequest ( self . get_next_message ( "<STR_LIT:test>" ) ) </s>
