U
    [eW!                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZ d dlmZmZmZmZmZ d dlmZ G dd	 d	ejZdS )
    N)	HTTPretty)parse_qsmodule_member)urlparse)do_authdo_complete)TestStorageUserTestUserSocialAuth	TestNonceTestAssociation)TestStrategyc                       s   e Zd ZdZdZdZedddZeddddd	d
ddddddddddddddddddddddddZ	 fd d!Z
d"d# Zd$d% Zd,d(d)Zd-d*d+Z  ZS ).BaseActionTestzhttps://api.github.com/userz/successfoobarZbearer)Zaccess_token
token_type   z0https://github.com/images/error/foobar_happy.gifZsomehexcodez#https://api.github.com/users/foobarzmonalisa foobarZGitHubzhttps://github.com/blogzSan Franciscozfoo@bar.comFzThere once was...      r   zhttps://github.com/foobarz2008-01-14T04:33:35Zr	   d   Q   i'     ZMediumi  
   )namespacecollaboratorsZprivate_repos)loginidZ
avatar_urlZgravatar_idurlr   ZcompanyZbloglocationemailZhireableZbioZpublic_reposZpublic_gistsZ	followersZ	followingZhtml_urlZ
created_attypeZtotal_private_reposZowned_private_reposZprivate_gists
disk_usager   Zplanc                    s   d | _ tt| j|| d S )N)strategysuperr   __init__)selfargskwargs	__class__ ^/var/www/html/services/stratfitenv/lib/python3.8/site-packages/social/tests/actions/actions.pyr$   9   s    zBaseActionTest.__init__c                 C   sZ   t   t  t  t  t  td}| jp<t	t
| _|| jdd| _d | _d S )N#social.backends.github.GithubOAuth2z/complete/github)Zredirect_uri)r   enabler	   reset_cacher
   r   r   r   r"   r   r   backenduser)r%   Backendr*   r*   r+   setUp=   s    zBaseActionTest.setUpc                 C   sH   d | _ d | _d | _t  td t  t  t  t	
  d S )NT)r/   r"   r0   r	   r.   Z
set_activer
   r   r   r   disable)r%   r*   r*   r+   tearDownH   s    
zBaseActionTest.tearDownTNc                 C   sf  | j dd| jdd t| jj}| j d}tt|j	}|d|krLdpNd d |d	  }tt|j	}t
jt
j|d
|d t
jt
j|ddd t|}	| |	j| | |	jd t
jt
j| jjd| jpddd | jr|p| jpd}t
jt
j| j|dd | j || j dd }
t| j| j|
d}|rb| | j d|pN| j | |j| j |S )Na-keya-secret-keyr,   )SOCIAL_AUTH_GITHUB_KEYSOCIAL_AUTH_GITHUB_SECRETSOCIAL_AUTH_LOGIN_REDIRECT_URL#SOCIAL_AUTH_AUTHENTICATION_BACKENDS/complete/github/?code=foobar?&state=state-  statusr      r   rC   body 	text/jsonurirC   rF   content_typerF   rK   c                 S   s   | j d|j d S Nusernamer"   session_setrN   r/   r0   Zsocial_userr*   r*   r+   _login}   s    z'BaseActionTest.do_login.<locals>._loginr0   r   rN   )r"   set_settingslogin_redirect_urlr   r/   r   build_absolute_urir   r   queryr   register_uriGETrequestsgetassertEqualtextPOSTACCESS_TOKEN_URLaccess_token_bodyuser_data_urluser_data_bodyset_request_datar   r0   session_getexpected_username)r%   Zafter_complete_checksrb   re   	start_url
target_urlstart_querylocation_urllocation_queryresponserR   redirectr*   r*   r+   do_loginS   s^    

zBaseActionTest.do_loginc                 C   s  | j dd| jddd t| jj}| j d}tt|j	}|d|krNdpPd d	 |d
  }tt|j	}t
jt
j|d|d t
jt
j|ddd t|}| |j| | |jd t
jt
j| jjd| jpddd | jrt
jt
j| j| jpddd | j || j dd }t| j| j|d}	| j d}
| |	j|
 t
jt
j|	jddd t
jt
j|	jdd d}t|
 tj|
d|id tt
jj}| |d | | j d|d  |r|  t| j| j|d}	| | j d| j | |	j| j d S )Nr5   r6   r7   )z*social.pipeline.social_auth.social_detailsz&social.pipeline.social_auth.social_uidz(social.pipeline.social_auth.auth_allowedz.social.pipeline.partial.save_status_to_sessionz&social.tests.pipeline.ask_for_passwordz'social.pipeline.social_auth.social_userz!social.pipeline.user.get_usernamez social.pipeline.user.create_userz*social.pipeline.social_auth.associate_userz+social.pipeline.social_auth.load_extra_dataz"social.tests.pipeline.set_passwordz!social.pipeline.user.user_details)r8   r9   r:   r;   ZSOCIAL_AUTH_PIPELINEr<   r=   r>   r?   r@   rA   rB   rD   r   rE   rG   rH   rI   rL   c                 S   s   | j d|j d S rM   rO   rQ   r*   r*   r+   rR      s    z=BaseActionTest.do_login_with_partial_pipeline.<locals>._loginrS   z	/password)rC   password)datarN   )r"   rT   rU   r   r/   r   rV   r   r   rW   r   rX   rY   rZ   r[   r\   r]   r_   r`   ra   rb   rc   r   r0   r^   postZlast_requestrF   rP   rd   re   )r%   Zbefore_completerf   rg   rh   ri   rj   rk   rR   rl   r   rn   ro   r*   r*   r+   do_login_with_partial_pipeline   sx    

z-BaseActionTest.do_login_with_partial_pipeline)TNN)N)__name__
__module____qualname__ra   rU   re   jsondumpsr`   rb   r$   r2   r4   rm   rq   __classcell__r*   r*   r(   r+   r      sZ   !  
5r   )ru   rZ   Z	unittest2ZunittestZ	httprettyr   Zsocial.utilsr   r   Z	social.p3r   Zsocial.actionsr   r   Zsocial.tests.modelsr   r	   r
   r   r   Zsocial.tests.strategyr   ZTestCaser   r*   r*   r*   r+   <module>   s   