a
    !f=V                     @   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dd Zdd Zdd Z	dd Z
G dd deZG dd deZdS )    Nc                   @   sv   e Zd Zdd Zdd Zd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d ZdS )TestOperationc                 C   s   ddl m} |S )Nr   )	Operation)gcloud.bigtable.clusterr   )selfr    r   ]/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/bigtable/test_cluster.py_getTargetClass   s    zTestOperation._getTargetClassc                 O   s   |   |i |S Nr   r   argskwargsr   r   r   _makeOne   s    zTestOperation._makeOneNc                 C   sR   d}d}| j |||d}| |j| | |j| | |j| | |j d S Nfake-opi"  cluster)r   assertEqualop_typeop_idZ_clusterassertFalse	_complete)r   r   r   r   	operationr   r   r   _constructor_test_helper   s    z&TestOperation._constructor_test_helperc                 C   s   |    d S r	   )r   r   r   r   r   test_constructor_defaults&   s    z'TestOperation.test_constructor_defaultsc                 C   s   t  }| j|d d S )Nr   )objectr   )r   r   r   r   r   !test_constructor_explicit_cluster)   s    z/TestOperation.test_constructor_explicit_clusterc                 C   s>   d}d}t  }| j|||d}| j|||d}| || d S r   )r   r   r   )r   r   r   r   
operation1
operation2r   r   r   test___eq__-   s    zTestOperation.test___eq__c                 C   s$   |  ddd }t }| || d S )Nfoo{   )r   r   assertNotEqualr   r   r   r   r   r   test___eq__type_differ5   s    z$TestOperation.test___eq__type_differc                 C   sD   d}d}t  }| j|||d}| j|||d}||k}| | d S r   )r   r   r   )r   r   r   r   r   r   comparison_valr   r   r   test___ne__same_value:   s    z#TestOperation.test___ne__same_valuec                 C   s,   |  ddd }|  ddd }| || d S )Nr!   r"   bari  )r   r#   r$   r   r   r   test___ne__C   s    zTestOperation.test___ne__c                 C   sJ   |  d d d }d|_| t |  W d    n1 s<0    Y  d S )NT)r   r   assertRaises
ValueErrorfinished)r   r   r   r   r   test_finished_without_operationH   s    z-TestOperation.test_finished_without_operationc                 C   s  ddl m} ddlm} ddlm} d}d}d}d}d	}	d
}
t||
d}t||}|||}| j||	|d}d| d | d | d|	f  }|j	|d}|j
|d}|| |_}|}| }| || | |jd||
fi fg |r| |j n| |j d S )Nr   operations_pb2	_FakeStubClusterPROJECTinstance-id
cluster-idr   i     timeout_secondsr   zoperations/projects//instances/
/clusters/z/operations/%dnamedoneZGetOperation)google.longrunningr/   gcloud.bigtable._testingr1   r   r3   _Client	_Instancer   ZGetOperationRequestr   Z_operations_stubr,   r   method_calls
assertTruer   r   )r   r?   r/   r1   r3   r4   INSTANCE_ID
CLUSTER_IDZOP_TYPEOP_IDr9   clientinstancer   r   Zop_name
request_pbresponse_pbstubexpected_resultresultr   r   r   _finished_helperN   sL    

zTestOperation._finished_helperc                 C   s   | j dd d S )NTr>   rP   r   r   r   r   test_finished~   s    zTestOperation.test_finishedc                 C   s   | j dd d S )NFr>   rQ   r   r   r   r   test_finished_not_done   s    z$TestOperation.test_finished_not_done)N)__name__
__module____qualname__r   r   r   r   r   r    r%   r'   r)   r-   rP   rR   rS   r   r   r   r   r      s   

	0r   c                   @   s   e Zd ZdZdZdZde d e d 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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d0S )1TestClusterprojectr5   r6   	projects/r:   r;   r"   c                 C   s   ddl m} |S )Nr   r2   )r   r3   )r   r3   r   r   r   r      s    zTestCluster._getTargetClassc                 O   s   |   |i |S r	   r
   r   r   r   r   r      s    zTestCluster._makeOnec                 C   sb   ddl m} t| j}t| j|}| | j|}| |j	| j | 
|j|u  | |j| d S Nr   DEFAULT_SERVE_NODES)r   r\   rB   r4   rC   rF   r   rG   r   
cluster_idrE   	_instanceserve_nodes)r   r\   rI   rJ   r   r   r   r   r      s    
z%TestCluster.test_constructor_defaultsc                 C   s^   d}t | j}t| j|}| j| j||d}| |j| j | |j	|u  | |j
| d S N   r_   )rB   r4   rC   rF   r   rG   r   r]   rE   r^   r_   )r   SERVE_NODESrI   rJ   r   r   r   r   test_constructor_non_default   s    

z(TestCluster.test_constructor_non_defaultc                 C   sp   d}t | j}t| j|}| j| j||d}| }| |j|u  | 	|j
| | ||u  | 	|| d S r`   )rB   r4   rC   rF   r   rG   copyr   r^   r   r_   )r   rc   rI   rJ   r   Znew_clusterr   r   r   	test_copy   s    

zTestCluster.test_copyc                 C   sh   ddl m} d}t|d}t| j}t| j|}| | j|}| 	|j
| || | 	|j
| d S )Nr   r[   ra   rb   )r   r\   
_ClusterPBrB   r4   rC   rF   r   rG   r   r_   _update_from_pb)r   r\   rc   
cluster_pbrI   rJ   r   r   r   r   test__update_from_pb_success   s    

z(TestCluster.test__update_from_pb_successc                 C   s   ddl m} t }t| j}t| j|}| | j|}| 	|j
| | t || W d    n1 sn0    Y  | 	|j
| d S rZ   )r   r\   rg   rB   r4   rC   rF   r   rG   r   r_   r*   r+   rh   )r   r\   ri   rI   rJ   r   r   r   r   #test__update_from_pb_no_serve_nodes   s    
(z/TestCluster.test__update_from_pb_no_serve_nodesc                 C   s~   d}t | j}t| j|}t| j|d}|  }|||}| t	|| | |j
|u  | |j| j | |j| d S )NiK  r=   r_   )rB   r4   rC   rF   rg   CLUSTER_NAMEr   from_pbrE   
isinstancer^   r   r]   rG   r_   )r   rc   rI   rJ   ri   klassr   r   r   r   test_from_pb_success   s    
z TestCluster.test_from_pb_successc                 C   sf   d}t | j}t| j|}t|d}|  }| t ||| W d    n1 sX0    Y  d S )NZINCORRECT_FORMATr<   )	rB   r4   rC   rF   rg   r   r*   r+   rn   )r   ZBAD_CLUSTER_NAMErI   rJ   ri   rp   r   r   r   test_from_pb_bad_cluster_name   s    

z)TestCluster.test_from_pb_bad_cluster_namec                 C   st   d}t |}t| j|}| | j| t| jd}|  }| t	 |
|| W d    n1 sf0    Y  d S )NALT_PROJECTr<   )rB   rC   rF   r#   r4   rg   rm   r   r*   r+   rn   )r   rs   rI   rJ   ri   rp   r   r   r   test_from_pb_project_mistmatch   s    z*TestCluster.test_from_pb_project_mistmatchc                 C   st   d}t | j}t||}| | j| t| jd}|  }| t	 |
|| W d    n1 sf0    Y  d S )NALT_INSTANCE_IDr<   )rB   r4   rC   r#   rF   rg   rm   r   r*   r+   rn   )r   ru   rI   rJ   ri   rp   r   r   r   test_from_pb_instance_mistmatch   s    

z+TestCluster.test_from_pb_instance_mistmatchc                 C   s8   t | j}t| j|}| | j|}| |j| j d S r	   )	rB   r4   rC   rF   r   rG   r   r=   rm   )r   rI   rJ   r   r   r   r   test_name_property  s    
zTestCluster.test_name_propertyc                 C   sB   t | j}t| j|}| | j|}| | j|}| || d S r	   )rB   r4   rC   rF   r   rG   r   r   rI   rJ   cluster1cluster2r   r   r   r      s
    
zTestCluster.test___eq__c                 C   s:   t | j}t| j|}| | j|}t }| || d S r	   )rB   r4   rC   rF   r   rG   r   r#   rx   r   r   r   r%     s
    
z"TestCluster.test___eq__type_differc                 C   sH   t | j}t| j|}| | j|}| | j|}||k}| | d S r	   )rB   r4   rC   rF   r   rG   r   )r   rI   rJ   ry   rz   r&   r   r   r   r'   !  s    
z!TestCluster.test___ne__same_valuec                 C   s>   t | j}t| j|}| d|}| d|}| || d S )NZcluster_id1Zcluster_id2)rB   r4   rC   rF   r   r#   rx   r   r   r   r)   )  s
    
zTestCluster.test___ne__c                 C   s   ddl m} ddlm} d}d}t| j| jd}t| j|}| 	| j
|}t| jd}t||d}	||	 |_}
d }| |j| | }| || | |
jd	|| jfi fg | |j| | |j| d S )
Nr   r0   r[      LOCATIONr8   r<   )r_   locationZ
GetCluster)rA   r1   r   r\   rB   r4   TIMEOUT_SECONDSrC   rF   r   rG   _GetClusterRequestPBrm   rg   _instance_stubr   r_   reloadrD   r}   )r   r1   r\   rc   r|   rI   rJ   r   rK   rL   rM   rN   rO   r   r   r   test_reload0  s0    zTestCluster.test_reloadc                    sF  ddl m} ddlm} ddlm} ddlm} t| j	| j
d}t| j|}| | j|}t d d| j	| j| j f }|j|d	}	||	 |_}
|jd
 |d}g fdd}g  fdd}||||d | }W d    n1 s0    Y  | || | |
jd| j
fi fg | |g | |	g d S )Nr   r.   _Monkeyr0   r   r8   .  =operations/projects/%s/instances/%s/clusters/%s/operations/%dr<   createc                    s     |  S r	   appendr   )prep_create_calledrK   r   r   mock_prep_create_reqw  s    
z5TestCluster.test_create.<locals>.mock_prep_create_reqc                    s    |   S r	   r   operation_pbrH   process_operation_calledr   r   mock_process_operation}  s    
z7TestCluster.test_create.<locals>.mock_process_operation)_prepare_create_request_process_operationZCreateCluster)r@   r/   gcloud._testingr   rA   r1   gcloud.bigtabler   rB   r4   r~   rC   rF   r   rG   r   r   r   r   r   rD   )r   r/   r   r1   MUTrI   rJ   r   ZOP_NAMErL   rM   rN   r   r   rO   r   )rH   r   r   rK   r   test_createY  s@    &zTestCluster.test_createc                    s  ddl m} ddlm} ddlm} ddlm} d}t| j	| j
d}t| j|}| j| j||d}t| j|d	}	| }
||
 |_}d
 |jd |d}g  fdd}|||d | }W d    n1 s0    Y  | || | |jd|	| j
fi fg | |
g d S )Nr   r.   r   r0   r   Q   r8   rb   rl   r   updatec                    s    |   S r	   r   r   r   r   r   r     s    
z7TestCluster.test_update.<locals>.mock_process_operationr   ZUpdateCluster)r@   r/   r   r   rA   r1   r   r   rB   r4   r~   rC   rF   r   rG   rg   rm   r   r   r   r   rD   )r   r/   r   r1   r   rc   rI   rJ   r   rK   rL   rM   rN   r   rO   r   r   r   test_update  s:    
&zTestCluster.test_updatec                 C   s   ddl m} ddlm} t| j| jd}t| j|}| 	| j
|}t| jd}| }|| |_}d }	| }
| |
|	 | |jd|| jfi fg d S )Nr   )	empty_pb2r0   r8   r<   ZDeleteCluster)google.protobufr   rA   r1   rB   r4   r~   rC   rF   r   rG   _DeleteClusterRequestPBrm   Emptyr   deleter   rD   )r   r   r1   rI   rJ   r   rK   rL   rM   rN   rO   r   r   r   test_delete  s     zTestCluster.test_deleteN)rT   rU   rV   r4   rF   rG   rm   r~   r   r   r   rd   rf   rj   rk   rq   rr   rt   rv   rw   r    r%   r'   r)   r   r   r   r   r   r   r   r   rW      sB   

)60rW   c                   @   s   e Zd Zdd Zdd ZdS )Test__prepare_create_requestc                 C   s   ddl m} ||S )Nr   )r   )r   r   )r   r   r   r   r   r   _callFUT  s    z%Test__prepare_create_request._callFUTc           
      C   sx   ddl m} d}d}d}d}t|}t||}||||d}| |}	| |	j| | |	j|j | |	j	j
| d S )Nr   r2   r4   r5   r6   ra   rb   )r   r3   rB   rC   r   r   r]   parentr=   r   r_   )
r   r3   r4   rF   rG   rc   rI   rJ   r   rK   r   r   r   test_it  s    

z$Test__prepare_create_request.test_itN)rT   rU   rV   r   r   r   r   r   r   r     s   r   c                   @   s.   e Zd Zd
ddZdd Zdd Zdd	 ZdS )Test__parse_pb_any_to_nativeNc                 C   s   ddl m} |||dS )Nr   )_parse_pb_any_to_nativeexpected_type)r   r   )r   any_valr   r   r   r   r   r     s    z%Test__parse_pb_any_to_native._callFUTc           	      C   s   ddl m} ddlm} ddlm} tddd}d|jj }||j	i}|j
|| d}|||d	 | |}W d    n1 s0    Y  | || d S )
Nr   any_pb2r   r   s   foobar)Ztimestamp_microsvalueztype.googleapis.com/)type_urlr   Z_TYPE_URL_MAP)r   r   r   r   r   r   _CellPBZ
DESCRIPTORZ	full_name	__class__AnyZSerializeToStringr   r   )	r   r   r   r   cellr   fake_type_url_mapr   rO   r   r   r   test_with_known_type_url  s     
(z5Test__parse_pb_any_to_native.test_with_known_type_urlc              	   C   s   ddl m} ddlm} ddlm} i }| }|||dD | t | 	| W d    n1 sh0    Y  W d    n1 s0    Y  d S )Nr   r   r   r   r   )
r   r   r   r   r   r   r   r*   KeyErrorr   )r   r   r   r   r   r   r   r   r   test_unknown_type_url  s    z2Test__parse_pb_any_to_native.test_unknown_type_urlc              	   C   s   ddl m} ddlm} ddlm} d}d}|d i}|j|d}|||dH | t | j	||d	 W d    n1 s|0    Y  W d    n1 s0    Y  d S )
Nr   r   r   r   r!   r(   )r   r   r   )
r   r   r   r   r   r   r   r*   r+   r   )r   r   r   r   Z	type_url1Z	type_url2r   r   r   r   r   test_disagreeing_type_url  s    z6Test__parse_pb_any_to_native.test_disagreeing_type_url)N)rT   rU   rV   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S )Test__process_operationc                 C   s   ddl m} ||S )Nr   r   )r   r   )r   r   r   r   r   r   r   /  s    z Test__process_operation._callFUTc           	      C   sR   ddl m} d}d}d}d}d||||f }|j|d}| |}| || d S )	Nr   r.   rX   r5   r6      r   r<   )r@   r/   r   r   r   )	r   r/   r4   rF   rG   ZEXPECTED_OPERATION_IDZOPERATION_NAMEr   Zoperation_idr   r   r   r   3  s    

zTest__process_operation.test_itc                 C   sP   ddl m} |jdd}| t | | W d    n1 sB0    Y  d S )Nr   r.   invalidr<   )r@   r/   r   r*   r+   r   )r   r/   r   r   r   r   test_op_name_parsing_failureF  s    z4Test__process_operation.test_op_name_parsing_failureN)rT   rU   rV   r   r   r   r   r   r   r   r   -  s   r   c                  O   s   ddl m} |j| i |S )Nr   )data_pb2)gcloud.bigtable._generatedr   ZCell)r   kwZdata_v2_pb2r   r   r   r   N  s    r   c                  O   s   ddl m} |j| i |S )Nr   )instance_pb2)r   r   r3   )r   r   Zinstance_v2_pb2r   r   r   rg   T  s    rg   c                  O   s   ddl m} |j| i |S Nr   )bigtable_instance_admin_pb2)r   r   ZDeleteClusterRequestr   r   Zmessages_v2_pb2r   r   r   r   Z  s    r   c                  O   s   ddl m} |j| i |S r   )r   r   ZGetClusterRequestr   r   r   r   r   `  s    r   c                   @   s0   e Zd Zdd Zedd Zdd Zdd Zd	S )
rC   c                 C   s   || _ || _d S r	   instance_id_client)r   r   rI   r   r   r   __init__h  s    z_Instance.__init__c                 C   s   d| j j| jf S )Nzprojects/%s/instances/%s)r   rX   r   r   r   r   r   r=   l  s    
z_Instance.namec                 C   s   |  | j| jS r	   )r   r   r   r   r   r   r   re   q  s    z_Instance.copyc                 C   s   |j | j ko|j| jkS r	   r   r   otherr   r   r   __eq__t  s    
z_Instance.__eq__N)rT   rU   rV   r   propertyr=   re   r   r   r   r   r   rC   f  s
   
rC   c                   @   s   e Zd ZdddZdd ZdS )rB   Nc                 C   s   || _ d| j  | _|| _d S )NrY   rX   project_namer9   )r   rX   r9   r   r   r   r   {  s    z_Client.__init__c                 C   s$   |j | j ko"|j| jko"|j| jkS r	   r   r   r   r   r   r     s
    

z_Client.__eq__)N)rT   rU   rV   r   r   r   r   r   r   rB   y  s   
rB   )Z	unittest2ZTestCaser   rW   r   r   r   r   rg   r   r   r   rC   rB   r   r   r   r   <module>   s   r  [5!