<s> """<STR_LIT>""" <EOL> from urllib . parse import urlencode , urlparse <EOL> import requests <EOL> from . . utils import url_path_join as ujoin <EOL> from . . import orm <EOL> import mock <EOL> from . mocking import FormSpawner , public_url , public_host , user_url <EOL> from . test_api import api_request <EOL> def get_page ( path , app , ** kw ) : <EOL> base_url = ujoin ( public_url ( app ) , app . hub . server . base_url ) <EOL> print ( base_url ) <EOL> return requests . get ( ujoin ( base_url , path ) , ** kw ) <EOL> def test_root_no_auth ( app , io_loop ) : <EOL> print ( app . hub . server . is_up ( ) ) <EOL> routes = io_loop . run_sync ( app . proxy . get_routes ) <EOL> print ( routes ) <EOL> print ( app . hub . server ) <EOL> url = public_url ( app ) <EOL> print ( url ) <EOL> r = requests . get ( url ) <EOL> r . raise_for_status ( ) <EOL> assert r . url == ujoin ( url , app . hub . server . base_url , '<STR_LIT>' ) <EOL> def test_root_auth ( app ) : <EOL> cookies = app . login_user ( '<STR_LIT>' ) <EOL> r = requests . get ( public_url ( app ) , cookies = cookies ) <EOL> r . raise_for_status ( ) <EOL> assert r . url == user_url ( app . users [ '<STR_LIT>' ] , app ) <EOL> def test_home_no_auth ( app ) : <EOL> r = get_page ( '<STR_LIT>' , app , allow_redirects = False ) <EOL> r . raise_for_status ( ) <EOL> assert r . status_code == <NUM_LIT> <EOL> assert '<STR_LIT>' in r . headers [ '<STR_LIT>' ] <EOL> def test_home_auth ( app ) : <EOL> cookies = app . login_user ( '<STR_LIT>' ) <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies ) <EOL> r . raise_for_status ( ) <EOL> assert r . url . endswith ( '<STR_LIT>' ) <EOL> def test_admin_no_auth ( app ) : <EOL> r = get_page ( '<STR_LIT>' , app ) <EOL> assert r . status_code == <NUM_LIT> <EOL> def test_admin_not_admin ( app ) : <EOL> cookies = app . login_user ( '<STR_LIT>' ) <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies ) <EOL> assert r . status_code == <NUM_LIT> <EOL> def test_admin ( app ) : <EOL> cookies = app . login_user ( '<STR_LIT>' ) <EOL> u = orm . User . find ( app . db , '<STR_LIT>' ) <EOL> u . admin = True <EOL> app . db . commit ( ) <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies ) <EOL> r . raise_for_status ( ) <EOL> assert r . url . endswith ( '<STR_LIT>' ) <EOL> def test_spawn_redirect ( app , io_loop ) : <EOL> name = '<STR_LIT>' <EOL> cookies = app . login_user ( name ) <EOL> u = app . users [ orm . User . find ( app . db , name ) ] <EOL> r = api_request ( app , '<STR_LIT>' , name , '<STR_LIT>' , method = '<STR_LIT>' , cookies = cookies ) <EOL> r . raise_for_status ( ) <EOL> status = io_loop . run_sync ( u . spawner . poll ) <EOL> assert status is not None <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies ) <EOL> r . raise_for_status ( ) <EOL> print ( urlparse ( r . url ) ) <EOL> path = urlparse ( r . url ) . path <EOL> assert path == '<STR_LIT>' % name <EOL> status = io_loop . run_sync ( u . spawner . poll ) <EOL> assert status is None <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies ) <EOL> r . raise_for_status ( ) <EOL> print ( urlparse ( r . url ) ) <EOL> path = urlparse ( r . url ) . path <EOL> assert path == '<STR_LIT>' % name <EOL> def test_spawn_page ( app ) : <EOL> with mock . patch . dict ( app . users . settings , { '<STR_LIT>' : FormSpawner } ) : <EOL> cookies = app . login_user ( '<STR_LIT>' ) <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies ) <EOL> assert r . url . endswith ( '<STR_LIT>' ) <EOL> assert FormSpawner . options_form in r . text <EOL> def test_spawn_form ( app , io_loop ) : <EOL> with mock . patch . dict ( app . users . settings , { '<STR_LIT>' : FormSpawner } ) : <EOL> base_url = ujoin ( public_url ( app ) , app . hub . server . base_url ) <EOL> cookies = app . login_user ( '<STR_LIT>' ) <EOL> orm_u = orm . User . find ( app . db , '<STR_LIT>' ) <EOL> u = app . users [ orm_u ] <EOL> io_loop . run_sync ( u . stop ) <EOL> r = requests . post ( ujoin ( base_url , '<STR_LIT>' ) , cookies = cookies , data = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT:1>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> r . raise_for_status ( ) <EOL> print ( u . spawner ) <EOL> print ( u . spawner . user_options ) <EOL> assert u . spawner . user_options == { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ - <NUM_LIT:1> , <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } <EOL> def test_spawn_form_with_file ( app , io_loop ) : <EOL> with mock . patch . dict ( app . users . settings , { '<STR_LIT>' : FormSpawner } ) : <EOL> base_url = ujoin ( public_url ( app ) , app . hub . server . base_url ) <EOL> cookies = app . login_user ( '<STR_LIT>' ) <EOL> orm_u = orm . User . find ( app . db , '<STR_LIT>' ) <EOL> u = app . users [ orm_u ] <EOL> io_loop . run_sync ( u . stop ) <EOL> r = requests . post ( ujoin ( base_url , '<STR_LIT>' ) , <EOL> cookies = cookies , <EOL> data = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT:1>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> files = { '<STR_LIT:hello>' : ( '<STR_LIT>' , b'<STR_LIT>' ) } <EOL> ) <EOL> r . raise_for_status ( ) <EOL> print ( u . spawner ) <EOL> print ( u . spawner . user_options ) <EOL> assert u . spawner . user_options == { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ - <NUM_LIT:1> , <NUM_LIT:1> ] , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT:hello>' : { '<STR_LIT:filename>' : '<STR_LIT>' , <EOL> '<STR_LIT:body>' : b'<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } , <EOL> } <EOL> def test_user_redirect ( app ) : <EOL> name = '<STR_LIT>' <EOL> cookies = app . login_user ( name ) <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies ) <EOL> r . raise_for_status ( ) <EOL> print ( urlparse ( r . url ) ) <EOL> path = urlparse ( r . url ) . path <EOL> assert path == '<STR_LIT>' % name <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies ) <EOL> r . raise_for_status ( ) <EOL> print ( urlparse ( r . url ) ) <EOL> path = urlparse ( r . url ) . path <EOL> assert path == '<STR_LIT>' % name <EOL> r = get_page ( '<STR_LIT>' , app ) <EOL> r . raise_for_status ( ) <EOL> print ( urlparse ( r . url ) ) <EOL> path = urlparse ( r . url ) . path <EOL> assert path == '<STR_LIT>' <EOL> query = urlparse ( r . url ) . query <EOL> assert query == urlencode ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> def test_login_fail ( app ) : <EOL> name = '<STR_LIT>' <EOL> base_url = public_url ( app ) <EOL> r = requests . post ( base_url + '<STR_LIT>' , <EOL> data = { <EOL> '<STR_LIT:username>' : name , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> } , <EOL> allow_redirects = False , <EOL> ) <EOL> assert not r . cookies <EOL> def test_login_redirect ( app , io_loop ) : <EOL> cookies = app . login_user ( '<STR_LIT>' ) <EOL> user = app . users [ '<STR_LIT>' ] <EOL> io_loop . run_sync ( user . spawn ) <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies , allow_redirects = False ) <EOL> r . raise_for_status ( ) <EOL> assert r . status_code == <NUM_LIT> <EOL> assert '<STR_LIT>' in r . headers [ '<STR_LIT>' ] <EOL> io_loop . run_sync ( user . stop ) <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies , allow_redirects = False ) <EOL> r . raise_for_status ( ) <EOL> assert r . status_code == <NUM_LIT> <EOL> assert '<STR_LIT>' in r . headers [ '<STR_LIT>' ] <EOL> r = get_page ( '<STR_LIT>' , app , cookies = cookies , allow_redirects = False ) <EOL> r . raise_for_status ( ) <EOL> assert r . status_code == <NUM_LIT> <EOL> assert r . headers [ '<STR_LIT>' ] . endswith ( '<STR_LIT>' ) <EOL> def test_logout ( app ) : <EOL> name = '<STR_LIT>' <EOL> cookies = app . login_user ( name ) <EOL> r = requests . get ( public_host ( app ) + app . tornado_settings [ '<STR_LIT>' ] , cookies = cookies ) <EOL> r . raise_for_status ( ) <EOL> login_url = public_host ( app ) + app . tornado_settings [ '<STR_LIT>' ] <EOL> assert r . url == login_url <EOL> assert r . cookies == { } <EOL> def test_login_no_whitelist_adds_user ( app ) : <EOL> auth = app . authenticator <EOL> mock_add_user = mock . Mock ( ) <EOL> with mock . patch . object ( auth , '<STR_LIT>' , mock_add_user ) : <EOL> cookies = app . login_user ( '<STR_LIT>' ) <EOL> user = app . users [ '<STR_LIT>' ] <EOL> assert mock_add_user . mock_calls == [ mock . call ( user ) ] <EOL> def test_static_files ( app ) : <EOL> base_url = ujoin ( public_url ( app ) , app . hub . server . base_url ) <EOL> print ( base_url ) <EOL> r = requests . get ( ujoin ( base_url , '<STR_LIT>' ) ) <EOL> r . raise_for_status ( ) <EOL> assert r . headers [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> r = requests . get ( ujoin ( base_url , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> r . raise_for_status ( ) <EOL> assert r . headers [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> r = requests . get ( ujoin ( base_url , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> r . raise_for_status ( ) <EOL> assert r . headers [ '<STR_LIT>' ] == '<STR_LIT>' </s>
