U
    ¶[Öe  ã                   @   s~   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	m
Z
 d dlmZ d dlmZmZmZmZmZmZ G dd„ dejƒZdS )	é    N)Ú	HTTPretty)Úmodule_memberÚparse_qs)Úuser_backends_dataÚload_backends)ÚTestStrategy)ÚUserÚTestUserSocialAuthÚ	TestNonceÚTestAssociationÚTestCodeÚTestStoragec                   @   sp   e Zd ZdZdZdZdZdZdd„ Zdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚBaseBackendTestNÚ z/complete/{0}c                 C   sÀ   t  ¡  t| jƒ}ttƒ| _|| j| jd| _| jj	 
¡  dd¡| _	| j | j | jj	¡¡| _| jdf}| j d|i¡ | j |  ¡ ¡ t|dd t ¡  t ¡  t ¡  t ¡  t ¡  d S )N)Zredirect_uriú-Ú_z3social.tests.backends.test_broken.BrokenBackendAuthÚ#SOCIAL_AUTH_AUTHENTICATION_BACKENDST)Z
force_load)r   Úenabler   Úbackend_pathr   r   ÚstrategyÚcomplete_urlÚbackendÚnameÚupperÚreplaceÚbuild_absolute_uriÚraw_complete_urlÚformatÚset_settingsÚextra_settingsr   r   Úreset_cacher	   r
   r   r   )ÚselfÚBackendÚbackends© r$   ú\/var/www/html/services/stratfitenv/lib/python3.8/site-packages/social/tests/backends/base.pyÚsetUp   s,    

ÿÿ ÿzBaseBackendTest.setUpc                 C   sL   t  ¡  d | _d | _d | _d | _t ¡  t ¡  t	 ¡  t
 ¡  t ¡  d S ©N)r   Údisabler   r   r   r   r   r    r	   r
   r   r   ©r!   r$   r$   r%   ÚtearDown+   s    zBaseBackendTest.tearDownc                 C   s   i S r'   r$   r)   r$   r$   r%   r   7   s    zBaseBackendTest.extra_settingsc                 C   s   t dƒ‚d S )NzImplement in subclass)ÚNotImplementedErrorr)   r$   r$   r%   Údo_start:   s    zBaseBackendTest.do_startc                 C   sü   |   ¡ }| j}|  |j|¡ |  | j d¡|¡ |  | j |j¡|¡ |  | j |j¡|¡ t	|| j 
d¡| jjƒ}|  tt| ¡ ƒƒd¡ |  d|kd¡ |  d|kd¡ |  d|kd¡ |  t|d ƒd¡ |  t|d ƒd¡ |  t|d ƒd	¡ |S )
NÚusernamer   é   Z
associatedTZnot_associatedr#   é   é   )r,   Úexpected_usernameÚassertEqualr-   r   Zsession_getZget_userÚidr   r   Zget_settingZstorageÚlenÚlistÚkeys)r!   Úuserr-   Zuser_backendsr$   r$   r%   Údo_login=   s&    
ýzBaseBackendTest.do_loginc                 C   s   | j  ddi¡ d S )NZSOCIAL_AUTH_PIPELINE)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.tests.pipeline.ask_for_slugz'social.pipeline.social_auth.social_userz!social.pipeline.user.get_usernamez.social.pipeline.social_auth.associate_by_emailz social.pipeline.user.create_userz*social.pipeline.social_auth.associate_userz+social.pipeline.social_auth.load_extra_dataz"social.tests.pipeline.set_passwordzsocial.tests.pipeline.set_slugz!social.pipeline.user.user_details)r   r   r)   r$   r$   r%   Úpipeline_settingsR   s     ÿz!BaseBackendTest.pipeline_settingsc                 C   s*   t jt j|ddd t jt j|dd d S )NéÈ   Úfoobar)ÚstatusÚbody)r<   )r   Zregister_uriÚGETÚPOST)r!   Úurlr$   r$   r%   Úpipeline_handlersg   s    z!BaseBackendTest.pipeline_handlersc                 C   sR   d}t  |¡ t j|d|id ttjjƒ}|  |d |¡ | j 	d|d ¡ |S )Nr;   Úpassword©Údata©
ÚrequestsÚgetÚpostr   r   Zlast_requestr=   r2   r   Zsession_set)r!   r@   rB   rD   r$   r$   r%   Úpipeline_password_handlingk   s    
z*BaseBackendTest.pipeline_password_handlingc                 C   sR   d}t  |¡ t j|d|id ttjjƒ}|  |d |¡ | j 	d|d ¡ |S )Nzfoo-barÚslugrC   rE   )r!   r@   rJ   rD   r$   r$   r%   Úpipeline_slug_handlingu   s    
z&BaseBackendTest.pipeline_slug_handlingc                 C   s(  | j  d¡}|  ¡  |  ¡ }|  |j|¡ |  |¡ |  |¡}| j  d¡}| j  	|¡\}}}}|  || j
j¡ | j
j|d|i|—Ž}| j  d¡}|  |j|¡ |  |¡ |  |¡}	| j  d¡}| j  	|¡\}}}}|  || j
j¡ | j
j|d|i|—Ž}
|  |
j| j¡ |  |
j|	¡ |  |
j|¡ |
S )Nz	/passwordZpartial_pipelineZpipeline_indexz/slug)r   r   r9   r,   r2   r@   rA   rI   Zsession_popZpartial_from_sessionr   r   Zcontinue_pipelinerK   r-   r1   rJ   rB   )r!   r@   ÚredirectrB   rD   Úidxr   ZxargsZxkwargsrJ   r7   r$   r$   r%   Údo_partial_pipeline   s<    

ÿÿ

ÿÿz#BaseBackendTest.do_partial_pipeline)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r&   r*   r   r,   r8   r9   rA   rI   rK   rN   r$   r$   r$   r%   r      s   

r   )Z	unittest2ZunittestrF   Z	httprettyr   Zsocial.utilsr   r   Zsocial.backends.utilsr   r   Zsocial.tests.strategyr   Zsocial.tests.modelsr   r	   r
   r   r   r   ZTestCaser   r$   r$   r$   r%   Ú<module>   s    