#NEWLINE# def do_login_with_partial_pipeline( self , before_complete = None ) : #NEWLINE# #INDENT# self . strategy . set_settings ( { #NEWLINE# #INDENT# 'SOCIAL_AUTH_GITHUB_KEY' : 'a-key' , #NEWLINE# 'SOCIAL_AUTH_GITHUB_SECRET' : 'a-secret-key' , #NEWLINE# 'SOCIAL_AUTH_LOGIN_REDIRECT_URL' : self . login_redirect_url , #NEWLINE# 'SOCIAL_AUTH_AUTHENTICATION_BACKENDS' : ( 'social.backends.github.GithubOAuth2' , ) , #NEWLINE# 'SOCIAL_AUTH_PIPELINE' : ( 'social.pipeline.social_auth.social_details' , 'social.pipeline.social_auth.social_uid' , 'social.pipeline.social_auth.auth_allowed' , 'social.pipeline.partial.save_status_to_session' , 'social.tests.pipeline.ask_for_password' , 'social.pipeline.social_auth.social_user' , 'social.pipeline.user.get_username' , 'social.pipeline.user.create_user' , 'social.pipeline.social_auth.associate_user' , 'social.pipeline.social_auth.load_extra_data' , 'social.tests.pipeline.set_password' , 'social.pipeline.user.user_details' ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# start_url = do_auth ( self . backend ) . url #NEWLINE# target_url = self . strategy . build_absolute_uri ( '/complete/github/?code=foobar' ) #NEWLINE# start_query = parse_qs ( urlparse ( start_url ) . query ) #NEWLINE# location_url = ( ( ( target_url + ( ( ( '?' in url ) and '&' ) or '?' ) ) + 'state=' ) + start_query [ 'state' ] ) #NEWLINE# location_query = parse_qs ( urlparse ( location_url ) . query ) #NEWLINE# HTTPretty . register_uri ( HTTPretty . GET , start_url , status = 301 , location = location_url ) #NEWLINE# HTTPretty . register_uri ( HTTPretty . GET , location_url , status = 200 , body = 'foobar' ) #NEWLINE# response = requests . get ( start_url ) #NEWLINE# self . assertEqual ( response . url , location_url ) #NEWLINE# self . assertEqual ( response . text , 'foobar' ) #NEWLINE# HTTPretty . register_uri ( HTTPretty . GET , uri = self . backend . ACCESS_TOKEN_URL , status = 200 , body = ( self . access_token_body or '' ) , content_type = 'text/json' ) #NEWLINE# if self . user_data_url : #NEWLINE# #INDENT# HTTPretty . register_uri ( HTTPretty . GET , self . user_data_url , body = ( self . user_data_body or '' ) , content_type = 'text/json' ) #NEWLINE# #UNINDENT# self . strategy . set_request_data ( location_query , self . backend ) #NEWLINE# def _login( backend , user , social_user ) : #NEWLINE# #INDENT# backend . strategy . session_set ( 'username' , user . username ) #NEWLINE# #UNINDENT# redirect = do_complete ( self . backend , user = self . user , login = _login ) #NEWLINE# url = self . strategy . build_absolute_uri ( '/password' ) #NEWLINE# self . assertEqual ( redirect . url , url ) #NEWLINE# HTTPretty . register_uri ( HTTPretty . GET , redirect . url , status = 200 , body = 'foobar' ) #NEWLINE# HTTPretty . register_uri ( HTTPretty . POST , redirect . url , status = 200 ) #NEWLINE# password = 'foobar' #NEWLINE# requests . get ( url ) #NEWLINE# requests . post ( url , data = { #NEWLINE# #INDENT# 'password' : password , #NEWLINE# #UNINDENT# } ) #NEWLINE# data = parse_qs ( HTTPretty . last_request . body ) #NEWLINE# self . assertEqual ( data [ 'password' ] , password ) #NEWLINE# self . strategy . session_set ( 'password' , data [ 'password' ] ) #NEWLINE# if before_complete : #NEWLINE# #INDENT# before_complete ( ) #NEWLINE# #UNINDENT# redirect = do_complete ( self . backend , user = self . user , login = _login ) #NEWLINE# self . assertEqual ( self . strategy . session_get ( 'username' ) , self . expected_username ) #NEWLINE# self . assertEqual ( redirect . url , self . login_redirect_url )