<s> from unittest import TestCase <EOL> from tortik . page import RequestHandler <EOL> fake_real_ip = '<STR_LIT>' <EOL> fake_request_id = '<STR_LIT>' <EOL> class FakeRequest ( object ) : <EOL> headers = { } <EOL> _base_make_request = RequestHandler . make_request <EOL> _make_request = _base_make_request . im_func if hasattr ( _base_make_request , '<STR_LIT>' ) else _base_make_request <EOL> class FakeHandler ( object ) : <EOL> def __init__ ( self ) : <EOL> self . request = FakeRequest ( ) <EOL> self . request_id = fake_request_id <EOL> self . request . headers = { <EOL> "<STR_LIT>" : fake_real_ip <EOL> } <EOL> make_request = _make_request <EOL> class MakeRequestTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . fake_handler = FakeHandler ( ) <EOL> self . fake_real_ip = fake_real_ip <EOL> def test_full_url ( self ) : <EOL> full_url = '<STR_LIT>' <EOL> request = self . fake_handler . make_request ( name = '<STR_LIT:abc>' , method = '<STR_LIT:GET>' , full_url = full_url ) <EOL> self . assertEqual ( request . url , full_url ) <EOL> def test_full_url_add_query ( self ) : <EOL> full_url = '<STR_LIT>' <EOL> request = self . fake_handler . make_request ( name = '<STR_LIT:abc>' , method = '<STR_LIT:GET>' , full_url = full_url , <EOL> data = { '<STR_LIT:foo>' : <NUM_LIT:1> } ) <EOL> self . assertEqual ( request . url , full_url + '<STR_LIT>' ) <EOL> def test_full_url_update_query ( self ) : <EOL> full_url = '<STR_LIT>' <EOL> request = self . fake_handler . make_request ( name = '<STR_LIT:abc>' , method = '<STR_LIT:GET>' , full_url = full_url , <EOL> data = { '<STR_LIT:foo>' : <NUM_LIT:1> } ) <EOL> self . assertEqual ( <EOL> sorted ( '<STR_LIT>' . split ( '<STR_LIT:&>' ) ) , <EOL> sorted ( request . url . split ( '<STR_LIT:?>' ) [ <NUM_LIT:1> ] . split ( '<STR_LIT:&>' ) ) <EOL> ) <EOL> def test_full_url_update_same_query ( self ) : <EOL> full_url = '<STR_LIT>' <EOL> request = self . fake_handler . make_request ( name = '<STR_LIT:abc>' , method = '<STR_LIT:GET>' , full_url = full_url , <EOL> data = { '<STR_LIT:bar>' : [ <NUM_LIT:4> , <NUM_LIT:5> ] } ) <EOL> self . assertEqual ( <EOL> sorted ( '<STR_LIT>' . split ( '<STR_LIT:&>' ) ) , <EOL> sorted ( request . url . split ( '<STR_LIT:?>' ) [ <NUM_LIT:1> ] . split ( '<STR_LIT:&>' ) ) <EOL> ) <EOL> def test_full_url_query ( self ) : <EOL> full_url = '<STR_LIT>' <EOL> request = self . fake_handler . make_request ( name = '<STR_LIT:abc>' , method = '<STR_LIT:GET>' , full_url = full_url ) <EOL> self . assertEqual ( request . url , full_url ) <EOL> def test_url_prefix_and_path ( self ) : <EOL> url_prefix = '<STR_LIT>' <EOL> path = '<STR_LIT>' <EOL> request = self . fake_handler . make_request ( <EOL> name = '<STR_LIT:abc>' , <EOL> method = '<STR_LIT:GET>' , <EOL> url_prefix = url_prefix , <EOL> path = path ) <EOL> self . assertEqual ( request . url , '<STR_LIT>' . format ( url_prefix , path ) ) <EOL> def test_url_prefix_without_path ( self ) : <EOL> url_prefix = '<STR_LIT>' <EOL> request = self . fake_handler . make_request ( <EOL> name = '<STR_LIT:abc>' , <EOL> method = '<STR_LIT:GET>' , <EOL> url_prefix = url_prefix ) <EOL> self . assertEqual ( request . url , '<STR_LIT>' . format ( url_prefix ) ) <EOL> def test_url_args_conflict ( self ) : <EOL> with self . assertRaises ( TypeError ) : <EOL> self . fake_handler . make_request ( <EOL> name = '<STR_LIT:abc>' , <EOL> method = '<STR_LIT:GET>' , <EOL> url_prefix = '<STR_LIT>' , <EOL> full_url = '<STR_LIT>' ) <EOL> def test_empty_kwargs ( self ) : <EOL> with self . assertRaises ( TypeError ) : <EOL> self . fake_handler . make_request ( '<STR_LIT:abc>' , '<STR_LIT:GET>' ) <EOL> def test_unused_path_argument ( self ) : <EOL> with self . assertRaises ( TypeError ) : <EOL> self . fake_handler . make_request ( <EOL> name = '<STR_LIT:abc>' , <EOL> method = '<STR_LIT:GET>' , <EOL> path = '<STR_LIT>' , <EOL> full_url = '<STR_LIT>' ) <EOL> def test_post_full_query ( self ) : <EOL> full_url = '<STR_LIT>' <EOL> request = self . fake_handler . make_request ( name = '<STR_LIT:abc>' , method = '<STR_LIT:POST>' , full_url = full_url , data = { '<STR_LIT:bar>' : <NUM_LIT:2> } ) <EOL> self . assertEqual ( request . url , full_url ) <EOL> self . assertEqual ( request . body , b'<STR_LIT>' ) <EOL> def test_post_full_query_raw ( self ) : <EOL> full_url = '<STR_LIT>' <EOL> data = b'<STR_LIT>' <EOL> request = self . fake_handler . make_request ( name = '<STR_LIT:abc>' , method = '<STR_LIT:POST>' , full_url = full_url , data = data ) <EOL> self . assertEqual ( request . url , full_url ) <EOL> self . assertEqual ( request . body , data ) <EOL> def test_post_query ( self ) : <EOL> url_prefix = '<STR_LIT>' <EOL> path = '<STR_LIT>' <EOL> request = self . fake_handler . make_request ( <EOL> name = '<STR_LIT:abc>' , <EOL> method = '<STR_LIT:POST>' , <EOL> url_prefix = url_prefix , <EOL> path = path , <EOL> data = { '<STR_LIT:bar>' : <NUM_LIT:2> } <EOL> ) <EOL> self . assertEqual ( request . url , '<STR_LIT>' + url_prefix + path ) <EOL> self . assertEqual ( request . body , b'<STR_LIT>' ) </s>
