U
    [ee                     @   s   d dl Z d dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ e jd  dkZG dd dejZG dd dejZG d	d
 d
ejZG dd dejZG dd dejZG dd dejZdS )    N)Mock)sanitize_redirectuser_is_authenticateduser_is_activeslugifybuild_absolute_uripartial_pipeline_data   c                   @   sT   e 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S )SanitizeRedirectTestc                 C   s   |  tdgd d  d S N	myapp.comassertEqualr   self r   Y/var/www/html/services/stratfitenv/lib/python3.8/site-packages/social/tests/test_utils.pytest_none_redirect   s    z'SanitizeRedirectTest.test_none_redirectc                 C   s   |  tdgdd  d S )Nr    r   r   r   r   r   test_empty_redirect   s    z(SanitizeRedirectTest.test_empty_redirectc                 C   s   |  tdgi d  d S r   r   r   r   r   r   test_dict_redirect   s    z'SanitizeRedirectTest.test_dict_redirectc                 C   s   |  tdgddid  d S )Nr   foobarr   r   r   r   r   test_invalid_redirect   s    z*SanitizeRedirectTest.test_invalid_redirectc                 C   s   |  tdgdd  d S )Nr   http://notmyapp.com/path/r   r   r   r   r   test_wrong_path_redirect   s    
z-SanitizeRedirectTest.test_wrong_path_redirectc                 C   s   |  tdgdd d S )Nr   zhttp://myapp.com/path/r   r   r   r   r   test_valid_absolute_redirect!   s    
z1SanitizeRedirectTest.test_valid_absolute_redirectc                 C   s   |  tdgdd d S )Nr   z/path/r   r   r   r   r   test_valid_relative_redirect'   s    z1SanitizeRedirectTest.test_valid_relative_redirectc                 C   s2   ddg}|D ] }d |}| t||| qd S )N
myapp1.com
myapp2.comzhttp://{}/path/)formatr   r   )r   Zallowed_hostshosturlr   r   r   test_multiple_hosts*   s    
z(SanitizeRedirectTest.test_multiple_hostsc                 C   s   |  tddgdd  d S )Nr   r   r   r   r   r   r   r   test_multiple_hosts_wrong_host0   s     z3SanitizeRedirectTest.test_multiple_hosts_wrong_hostN)__name__
__module____qualname__r   r   r   r   r   r   r   r#   r$   r   r   r   r   r
      s   r
   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
UserIsAuthenticatedTestc                 C   s   |  td d d S NF)r   r   r   r   r   r   test_user_is_none6   s    z)UserIsAuthenticatedTest.test_user_is_nonec                 C   s   |  tt d d S NT)r   r   objectr   r   r   r   test_user_is_not_none9   s    z-UserIsAuthenticatedTest.test_user_is_not_nonec                 C   s&   G dd dt }| t| d d S )Nc                   @   s   e Zd ZdZdS )zDUserIsAuthenticatedTest.test_user_has_is_authenticated.<locals>.UserTNr%   r&   r'   is_authenticatedr   r   r   r   User=   s   r0   Tr,   r   r   r   r0   r   r   r   test_user_has_is_authenticated<   s    z6UserIsAuthenticatedTest.test_user_has_is_authenticatedc                 C   s&   G dd dt }| t| d d S )Nc                   @   s   e Zd Zdd ZdS )zMUserIsAuthenticatedTest.test_user_has_is_authenticated_callable.<locals>.Userc                 S   s   dS r+   r   r   r   r   r   r/   C   s    z^UserIsAuthenticatedTest.test_user_has_is_authenticated_callable.<locals>.User.is_authenticatedNr.   r   r   r   r   r0   B   s   r0   Tr1   r2   r   r   r   'test_user_has_is_authenticated_callableA   s    z?UserIsAuthenticatedTest.test_user_has_is_authenticated_callableN)r%   r&   r'   r*   r-   r3   r4   r   r   r   r   r(   5   s   r(   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
UserIsActiveTestc                 C   s   |  td d d S r)   )r   r   r   r   r   r   r*   I   s    z"UserIsActiveTest.test_user_is_nonec                 C   s   |  tt d d S r+   )r   r   r,   r   r   r   r   r-   L   s    z&UserIsActiveTest.test_user_is_not_nonec                 C   s&   G dd dt }| t| d d S )Nc                   @   s   e Zd ZdZdS )z6UserIsActiveTest.test_user_has_is_active.<locals>.UserTNr%   r&   r'   	is_activer   r   r   r   r0   P   s   r0   Tr,   r   r   r2   r   r   r   test_user_has_is_activeO   s    z(UserIsActiveTest.test_user_has_is_activec                 C   s&   G dd dt }| t| d d S )Nc                   @   s   e Zd Zdd ZdS )z?UserIsActiveTest.test_user_has_is_active_callable.<locals>.Userc                 S   s   dS r+   r   r   r   r   r   r7   V   s    zIUserIsActiveTest.test_user_has_is_active_callable.<locals>.User.is_activeNr6   r   r   r   r   r0   U   s   r0   Tr8   r2   r   r   r    test_user_has_is_active_callableT   s    z1UserIsActiveTest.test_user_has_is_active_callableN)r%   r&   r'   r*   r-   r9   r:   r   r   r   r   r5   H   s   r5   c                   @   s   e Zd Zdd ZdS )SlugifyTestc                 C   s|   t r6| tdd | tdd | tdd nB| tddd | tddd | tddd d S )NZFooBarZfoobarzFoo Barzfoo-barz	Foo (Bar)zutf-8)PY3r   r   decoder   r   r   r   test_slugify_formats\   s    z SlugifyTest.test_slugify_formatsN)r%   r&   r'   r>   r   r   r   r   r;   [   s   r;   c                   @   sL   e 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S )BuildAbsoluteURITestc                 C   s
   d| _ d S )Nzhttp://foobar.comr!   r   r   r   r   setUph   s    zBuildAbsoluteURITest.setUpc                 C   s
   d | _ d S Nr@   r   r   r   r   tearDownk   s    zBuildAbsoluteURITest.tearDownc                 C   s   |  t| j| j d S rB   r   r   r!   r   r   r   r   test_path_nonen   s    z#BuildAbsoluteURITest.test_path_nonec                 C   s   |  t| jd| j d S )Nr   rD   r   r   r   r   test_path_emptyq   s    z$BuildAbsoluteURITest.test_path_emptyc                 C   s   |  t| jdd d S )Nzhttp://barfoo.comrD   r   r   r   r   test_path_httpt   s    z#BuildAbsoluteURITest.test_path_httpc                 C   s   |  t| jdd d S )Nzhttps://barfoo.comrD   r   r   r   r   test_path_httpsx   s    z$BuildAbsoluteURITest.test_path_httpsc                 C   s   |  t| jd dd d S )N//foo/barhttp://foobar.com/foo/barrD   r   r   r   r   4test_host_ends_with_slash_and_path_starts_with_slash|   s    zIBuildAbsoluteURITest.test_host_ends_with_slash_and_path_starts_with_slashc                 C   s   |  t| jdd d S )NrJ   rK   rD   r   r   r   r   test_absolute_uri   s    z&BuildAbsoluteURITest.test_absolute_uriN)r%   r&   r'   rA   rC   rE   rF   rG   rH   rL   rM   r   r   r   r   r?   g   s   r?   c                   @   s6   e Zd Zdd Zdd Zdd Zdd Zdd
dZd	S )PartialPipelineDatac                 C   s~   d}|  d|i}|j|i|jj_d\}}t|d fdt||fg\}}| ||k | || | | |jj	j
d d S )Nfoo@example.comuidr   r   r   r   )_backendID_KEYstrategyrequest_datareturn_valuer   dict
assertTruer   clean_partial_pipeline
call_count)r   emailbackendkeyval_xkwargsr   r   r   0test_returns_partial_when_uid_and_email_do_match   s     
zDPartialPipelineData.test_returns_partial_when_uid_and_email_do_matchc                 C   sb   |  ddi}|jdi|jj_d\}}t|d fdt||fg}| | | |jj	j
d d S )NrP   rO   zbar@example.comrQ   r      )rR   rS   rT   rU   rV   r   rW   ZassertIsNoner   rY   rZ   )r   r\   r]   r^   retr   r   r   +test_clean_pipeline_when_uid_does_not_match   s     

z?PartialPipelineData.test_clean_pipeline_when_uid_does_not_matchc                 C   sd   |   }d\}}t|d fdt||fg\}}| ||k | || | | |jjjd d S )NrQ   r   r   )rR   r   rW   rX   r   rT   rY   rZ   )r   r\   r]   r^   r_   r`   r   r   r   test_kwargs_included_in_result   s    z2PartialPipelineData.test_kwargs_included_in_resultc                 C   sX   t  }| jdd id}t||\}}| d|k | |d | | |jjjd d S )Nuser)session_kwargsr   )r,   rR   r   rX   r   rT   rY   rZ   )r   rf   r\   r_   r`   r   r   r   test_update_user   s    z$PartialPipelineData.test_update_userNc                 C   sN   t  }d |_i |j_t |j_ddg |p*i f|j_t  }d|_d|_||_	|S )Nr   zmock-backendr[   )
r   requestrU   rV   r,   Zsession_getZpartial_from_sessionrS   namerT   )r   rg   rT   r\   r   r   r   rR      s    
zPartialPipelineData._backend)N)r%   r&   r'   ra   rd   re   rh   rR   r   r   r   r   rN      s
   	rN   )sysZ	unittest2ZunittestZmockr   Zsocial.utilsr   r   r   r   r   r   version_infor<   ZTestCaser
   r(   r5   r;   r?   rN   r   r   r   r   <module>   s    '