<s> import mock <EOL> import testify as T <EOL> import tornado . httpserver <EOL> from pushmanager . core . requesthandler import RequestHandler <EOL> from pushmanager . core . requesthandler import get_base_url <EOL> from pushmanager . core . settings import Settings <EOL> from pushmanager . testing . mocksettings import MockedSettings <EOL> class RequestHandlerTest ( T . TestCase ) : <EOL> def test_get_api_page ( self ) : <EOL> MockedSettings [ '<STR_LIT>' ] = { '<STR_LIT:port>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } <EOL> with mock . patch . dict ( Settings , MockedSettings ) : <EOL> T . assert_equal ( <EOL> RequestHandler . get_api_page ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_get_base_url_empty_headers ( self ) : <EOL> MockedSettings [ '<STR_LIT>' ] = { '<STR_LIT:port>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } <EOL> request = tornado . httpserver . HTTPRequest ( '<STR_LIT:GET>' , '<STR_LIT>' ) <EOL> request . protocol = '<STR_LIT>' <EOL> with mock . patch . dict ( Settings , MockedSettings ) : <EOL> T . assert_equal ( <EOL> get_base_url ( request ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> Settings [ '<STR_LIT>' ] [ '<STR_LIT:port>' ] = <NUM_LIT> <EOL> T . assert_equal ( <EOL> get_base_url ( request ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_get_base_url_proto_header ( self ) : <EOL> MockedSettings [ '<STR_LIT>' ] = { '<STR_LIT:port>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } <EOL> request = tornado . httpserver . HTTPRequest ( '<STR_LIT:GET>' , '<STR_LIT>' ) <EOL> request . protocol = '<STR_LIT>' <EOL> request . headers [ '<STR_LIT>' ] = '<STR_LIT:http>' <EOL> with mock . patch . dict ( Settings , MockedSettings ) : <EOL> T . assert_equal ( <EOL> get_base_url ( request ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> Settings [ '<STR_LIT>' ] [ '<STR_LIT:port>' ] = <NUM_LIT> <EOL> T . assert_equal ( <EOL> get_base_url ( request ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_get_base_url_port_header ( self ) : <EOL> MockedSettings [ '<STR_LIT>' ] = { '<STR_LIT:port>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } <EOL> request = tornado . httpserver . HTTPRequest ( '<STR_LIT:GET>' , '<STR_LIT>' ) <EOL> request . protocol = '<STR_LIT>' <EOL> request . headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> with mock . patch . dict ( Settings , MockedSettings ) : <EOL> T . assert_equal ( <EOL> get_base_url ( request ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> request . headers [ '<STR_LIT>' ] = <NUM_LIT> <EOL> T . assert_equal ( <EOL> get_base_url ( request ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_RequestHandler_get_base_url ( self ) : <EOL> MockedSettings [ '<STR_LIT>' ] = { '<STR_LIT:port>' : <NUM_LIT> , '<STR_LIT>' : '<STR_LIT>' } <EOL> request = tornado . httpserver . HTTPRequest ( '<STR_LIT:GET>' , '<STR_LIT>' ) <EOL> request . protocol = '<STR_LIT>' <EOL> class FakeRequest ( object ) : <EOL> def __init__ ( self ) : <EOL> self . request = request <EOL> with mock . patch . dict ( Settings , MockedSettings ) : <EOL> fake_requesthandler = FakeRequest ( ) <EOL> T . assert_equal ( <EOL> RequestHandler . get_base_url . __func__ ( fake_requesthandler ) , <EOL> '<STR_LIT>' <EOL> ) </s>
