a
    |f#                     @   s   d dl 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ZG dd deZ	G dd deZ
dS )    Nc                   @   s   e Zd Zdd Zdd ZdS )Test_get_credentialsc                 C   s   ddl m} | S )Nr   credentials)gcloudr   Zget_credentials)selfr    r   QD:\Projects\storyit_web\backend\venv\Lib\site-packages\gcloud/test_credentials.py_callFUT   s    zTest_get_credentials._callFUTc                 C   s   ddl m} ddlm} t }|||d |  }W d    n1 sH0    Y  | t|t | ||j	u  | |j
 d S )Nr   _Monkeyr   )client)gcloud._testingr   r   r   _Clientr	   Z
assertTrue
isinstance_Credentials_signed_get_app_default_called)r   r   MUTr   foundr   r   r   test_it   s    &zTest_get_credentials.test_itN__name__
__module____qualname__r	   r   r   r   r   r   r      s   r   c                   @   s.   e Zd Zdd Zd
ddZdd Zdd	 ZdS )Test_generate_signed_urlc                 O   s   ddl m} ||i |S )Nr   generate_signed_url)gcloud.credentialsr   )r   argskwargsr   r   r   r   r	   &   s    z!Test_generate_signed_url._callFUTNc              
      s  dd l }ddlm} ddlm} ddlm} ddlm} d}	d}
|d t	 } fd	d
}|||d( | j
||
d|	|||d}W d    n1 s0    Y  ||\}}}}}| |d | |d | ||
 ||}| |d dg | |ddg | |d|jg |d ur@| |d|g |d ur^| |d|g |d ur|| |d|g | t|d | |d d S )Nr   )parse_qs)urlsplitr
   r   zhttp://api.example.com
/name/path   DEADBEEFc                     s"   | d d \}}|j t| dS )N   GoogleAccessIdExpires	Signature)service_account_emailstr)r   r   
expirationZSIGNEDr   r   _get_signed_query_params7   s
    zKTest_generate_signed_url._generate_helper.<locals>._get_signed_query_paramsr-   i  )Zapi_access_endpointresponse_typeresponse_disposition
generationhttpzapi.example.comr(   asciir'   Z1000r&   zresponse-content-typezresponse-content-dispositionr1    )base64Zsix.moves.urllib.parser    r!   r   r   r   r   	b64encoder   r	   assertEqualpopdecoder)   len)r   r/   r0   r1   r5   r    r!   r   r   ZENDPOINTRESOURCECREDENTIALSr-   urlschemenetlocpathqsfragparamsr   r,   r   _generate_helper*   sN    

$


z)Test_generate_signed_url._generate_helperc                 C   s   |    d S NrD   r   r   r   r   test_w_expiration_int\   s    z.Test_generate_signed_url.test_w_expiration_intc                 C   s    d}d}d}| j |||d d S )Nz
text/plainzattachment; filename=blob.pngZ123)r/   r0   r1   rF   )r   r/   r0   r1   r   r   r   test_w_custom_fields_   s    z-Test_generate_signed_url.test_w_custom_fields)NNN)r   r   r   r	   rD   rH   rI   r   r   r   r   r   $   s     
2r   c                   @   s   e Zd Zdd ZdS )"Test_generate_signed_url_exceptionc                 C   sF   dd l }ddlm} d}t }t|  d }| jt||||d d S )Nr   r   r"      )resourcer+   )timer   r   _GoogleCredentialsintassertRaisesAttributeError)r   rM   r   r;   r   r+   r   r   r   test_with_google_credentialsi   s    
z?Test_generate_signed_url_exception.test_with_google_credentialsN)r   r   r   rR   r   r   r   r   rJ   h   s   rJ   c                   @   s   e Zd Zdd Zdd ZdS )Test__get_signed_query_paramsc                 C   s   ddl m} ||||S )Nr   r.   )r   r-   )r   r   r+   Zstring_to_signr-   r   r   r   r	   v   s    z&Test__get_signed_query_params._callFUTc                 C   sf   dd l }d}t }t||d}d}d}| |||}| ||t||dd | |j|g d S )Nr   r#   )sign_resultr)   d   Zdummy_signaturer%   )r5   objectr   r	   r7   r*   r6   r   )r   r5   Z	SIG_BYTESZACCOUNT_NAMEr<   Z
EXPIRATIONZSTRING_TO_SIGNresultr   r   r   r   {   s"    z%Test__get_signed_query_params.test_itNr   r   r   r   r   rS   t   s   rS   c                   @   s\   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d ZdS )Test__get_expiration_secondsc                 C   s   ddl m} ||S )Nr   )_get_expiration_seconds)r   rY   )r   r+   rY   r   r   r   r	      s    z%Test__get_expiration_seconds._callFUTc                 C   s   dd l }t|| S )Nr   )calendarrO   timegm	timetuple)r   whenrZ   r   r   r   _utc_seconds   s    z)Test__get_expiration_seconds._utc_secondsc                 C   s&   |  t| jt  |  t| jd  d S rE   )rP   	TypeErrorr	   rV   rG   r   r   r   test_w_invalid   s    z+Test__get_expiration_seconds.test_w_invalidc                 C   s   |  | dd d S N{   )r7   r	   rG   r   r   r   
test_w_int   s    z'Test__get_expiration_seconds.test_w_intc                 C   s6   zt  W n ty   Y n0 | | t dd d S ra   )long	NameErrorr7   r	   rG   r   r   r   test_w_long   s
    z(Test__get_expiration_seconds.test_w_longc              	   C   s>   dd l }| ddddddd}| |}| | || d S )Nr           )datetimer^   r7   r	   )r   rj   Zexpiration_no_tzutc_secondsr   r   r   test_w_naive_datetime   s    
z2Test__get_expiration_seconds.test_w_naive_datetimec              
   C   sL   dd l }ddlm} | ddddddd|}| |}| | || d S )Nr   )UTCrg   rh   ri   )rj   gcloud._helpersrm   r^   r7   r	   )r   rj   rm   Zexpiration_utcrk   r   r   r   test_w_utc_datetime   s
    
z0Test__get_expiration_seconds.test_w_utc_datetimec              
      sn   dd l  ddlm} G  fddd|}| }  ddddddd|}| |}|d }| | || d S )	Nr   )_UTCc                       s   e Zd ZdZ jddZdS )zDTest__get_expiration_seconds.test_w_other_zone_datetime.<locals>.CETCET   )hoursN)r   r   r   Z_tzname	timedeltaZ
_utcoffsetr   rj   r   r   rq      s   rq   rg   rh   ri   i  )rj   rn   rp   r^   r7   r	   )r   rp   rq   zoneZexpiration_otherrk   Zcet_secondsr   ru   r   test_w_other_zone_datetime   s    
z7Test__get_expiration_seconds.test_w_other_zone_datetimec              	      s   dd l }ddlm} ddlm} | ddddddd |  }|jdd}|| fd	d
d | |}W d    n1 s0    Y  | ||d  d S )Nr   r
   r   rg   rh   ri   
   )secondsc                      s    S rE   r   r   Zdummy_utcnowr   r   <lambda>       zGTest__get_expiration_seconds.test_w_timedelta_seconds.<locals>.<lambda>Z_NOW	rj   r   r   r   r   r^   rt   r	   r7   r   rj   r   r   rk   Zexpiration_as_deltarW   r   rz   r   test_w_timedelta_seconds   s    
(z5Test__get_expiration_seconds.test_w_timedelta_secondsc              	      s   dd l }ddlm} ddlm} | ddddddd |  }|jdd}|| fd	d
d | |}W d    n1 s0    Y  | ||d  d S )Nr   r
   r   rg   rh   ri   rr   )daysc                      s    S rE   r   r   rz   r   r   r{      r|   zDTest__get_expiration_seconds.test_w_timedelta_days.<locals>.<lambda>r}   iQ r~   r   r   rz   r   test_w_timedelta_days   s    
(z2Test__get_expiration_seconds.test_w_timedelta_daysN)r   r   r   r	   r^   r`   rc   rf   rl   ro   rw   r   r   r   r   r   r   rX      s   rX   c                   @   s   e Zd ZdddZdd ZdS )	r   testing@example.comr4   c                 C   s   || _ || _g | _d S rE   )r)   _sign_resultr   )r   r)   rT   r   r   r   __init__   s    z_Credentials.__init__c                 C   s   | j | d | jfS rE   )r   appendr   )r   Zbytes_to_signr   r   r   	sign_blob   s    z_Credentials.sign_blobN)r   r4   )r   r   r   r   r   r   r   r   r   r      s     
r   c                   @   s   e Zd ZdddZdS )rN   r   c                 C   s
   || _ d S rE   )r)   )r   r)   r   r   r   r      s    z_GoogleCredentials.__init__N)r   r   r   r   r   r   r   r   r   rN      s   rN   c                   @   s   e Zd Zdd ZdS )r   c                    s&   t   _G  fdddt}| _d S )Nc                       s   e Zd Ze fddZdS )z+_Client.__init__.<locals>.GoogleCredentialsc                      s   d _  jS )NT)r   r   r   rG   r   r   get_application_default   s    zC_Client.__init__.<locals>.GoogleCredentials.get_application_defaultN)r   r   r   staticmethodr   r   rG   r   r   GoogleCredentials   s   r   )r   r   rV   r   )r   r   r   rG   r   r      s    z_Client.__init__Nr   r   r   r   r   r      s   r   )Z	unittest2ZTestCaser   r   rJ   rS   rX   rV   r   rN   r   r   r   r   r   <module>   s   DS