B
    /²ô`<  ã               @   s‚   d dl Z d dlZd dlmZ ddlmZ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ÚPARTIAL_TOKEN_SESSION_NAME)Ú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ú-Ú_z8social_core.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   )ÚselfZBackendÚbackends© r&   úN/home/dcms/DCMS/lib/python3.7/site-packages/social_core/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 )Nr&   )r$   r&   r&   r'   r"   7   s    zBaseBackendTest.extra_settingsc             C   s   t dƒ‚d S )NzImplement in subclass)ÚNotImplementedError)r$   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   r   Z
associatedTZnot_associatedr%   é   r	   )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_core.pipeline.social_auth.social_detailsz+social_core.pipeline.social_auth.social_uidz-social_core.pipeline.social_auth.auth_allowedz+social_core.tests.pipeline.ask_for_passwordz'social_core.tests.pipeline.ask_for_slugz,social_core.pipeline.social_auth.social_userz&social_core.pipeline.user.get_usernamez3social_core.pipeline.social_auth.associate_by_emailz%social_core.pipeline.user.create_userz/social_core.pipeline.social_auth.associate_userz0social_core.pipeline.social_auth.load_extra_dataz'social_core.tests.pipeline.set_passwordz#social_core.tests.pipeline.set_slugz&social_core.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_handlersf   s    z!BaseBackendTest.pipeline_handlersc             C   sR   d}t  |¡ t j|d|id ttjjƒ}|  |d |¡ | j 	d|d ¡ |S )Nr9   Úpassword)Údata)
ÚrequestsÚgetÚpostr   r   Úlast_requestr;   r0   r   Úsession_set)r$   r>   r@   rA   r&   r&   r'   Úpipeline_password_handlingj   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Úslug)rA   )
rB   rC   rD   r   r   rE   r;   r0   r   rF   )r$   r>   rH   rA   r&   r&   r'   Úpipeline_slug_handlingt   s    
z&BaseBackendTest.pipeline_slug_handlingc             C   s  | j  d¡}|  ¡  |  ¡ }|  |j|¡ |  |¡ |  |¡}| j  t	¡}| j  
|¡}|  |j| jj¡ | j |¡}| j  d¡}|  |j|¡ |  |¡ |  |¡}| j  t	¡}| j  
|¡}|  |j| jj¡ | j |¡}|  |j| j¡ |  |j|¡ |  |j|¡ |S )Nz	/passwordz/slug)r   r   r7   r,   r0   r>   r?   rG   Zsession_popr   Zpartial_loadr   r   Zcontinue_pipelinerI   r-   r/   rH   r@   )r$   r>   Úredirectr@   ÚtokenÚpartialrH   r5   r&   r&   r'   Údo_partial_pipeline~   s,    



z#BaseBackendTest.do_partial_pipeline)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r(   r*   r"   r,   r6   r7   r?   rG   rI   rM   r&   r&   r&   r'   r      s   

r   )ZunittestrB   Z	httprettyr   Úutilsr   r   r   Zbackends.utilsr   r   r   r
   Úmodelsr   r   r   r   r   r   ZTestCaser   r&   r&   r&   r'   Ú<module>   s    