a
    !fp                     @   sR   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ZdS )
    Nc                   @   s  e Zd ZdZdZdZdZdZdd Zdd	 Z	dfd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dgd$d%Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&dFdG Z'dHdI Z(dJdK Z)dLdM Z*dNdO Z+dPdQ Z,dRdS Z-dTdU Z.dVdW Z/dXdY Z0dZd[ Z1d\d] Z2d^d_ Z3d`da Z4dbdc Z5ddde Z6dS )h
TestClientPROJECTinstance-iddisplay-nameP   zyou-sir-age-intc                 C   s   ddl m} |S )Nr   Client)gcloud.bigtable.clientr   )selfr    r   \/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/bigtable/test_client.py_getTargetClass   s    zTestClient._getTargetClassc                 O   s   |   |i |S Nr   r
   argskwargsr   r   r   _makeOne   s    zTestClient._makeOneFNc           
      C   s   ddl m} |p|j}|p|j}| j| j|||||d}	|p>|}| |	j|u  |d urh| |	jj	| | |	j
| j | |	j| | |	j| | |	jd  | |	jd  | |	jd  | |	jd  d S )Nr   client)projectcredentials	read_onlyadmin
user_agenttimeout_seconds)gcloud.bigtabler   DEFAULT_USER_AGENTZDEFAULT_TIMEOUT_SECONDSr   r   
assertTrue_credentialsassertEqualscopesr   r   r   _data_stub_internal_instance_stub_internal_operations_stub_internal_table_stub_internal)
r
   expected_scopescredsr   r   r   r   expected_credsMUTr   r   r   r   _constructor_test_helper"   s&    


z#TestClient._constructor_test_helperc                 C   s*   ddl m} |jg}t }| || d S )Nr   r   r   r   
DATA_SCOPE_Credentialsr*   r
   r)   r&   r'   r   r   r   test_constructor_default_scopes=   s    z*TestClient.test_constructor_default_scopesc                 C   s8   ddl m} d}d}|jg}t }| j||||d d S )Nr   r   i9  zcustom-application)r   r   r+   )r
   r)   ZCUSTOM_TIMEOUT_SECONDSZCUSTOM_USER_AGENTr&   r'   r   r   r   .test_constructor_custom_user_agent_and_timeoutD   s    z9TestClient.test_constructor_custom_user_agent_and_timeoutc                 C   s2   ddl m} |j|jg}t }| j||dd d S )Nr   r   Tr   )r   r   r,   ZADMIN_SCOPEr-   r*   r.   r   r   r   test_constructor_with_adminO   s    z&TestClient.test_constructor_with_adminc                 C   s.   ddl m} |jg}t }| j||dd d S )Nr   r   Tr   )r   r   ZREAD_ONLY_SCOPEr-   r*   r.   r   r   r   test_constructor_with_read_onlyV   s    z*TestClient.test_constructor_with_read_onlyc                 C   sF   t  }| t" | jg |ddd W d    n1 s80    Y  d S )NT)r   r   )r-   assertRaises
ValueErrorr*   )r
   r'   r   r   r   )test_constructor_both_admin_and_read_only]   s
    
z4TestClient.test_constructor_both_admin_and_read_onlyc                    sr   ddl m} ddlm} t  |jg} fdd}|||d  | j|d  d W d    n1 sd0    Y  d S )Nr   _Monkeyr   c                      s    S r   r   r   r'   r   r   mock_get_credentialsj   s    zNTestClient.test_constructor_implicit_credentials.<locals>.mock_get_credentials)Zget_credentials)r(   )gcloud._testingr9   r   r   r-   r,   r*   )r
   r9   r)   r&   r;   r   r:   r   %test_constructor_implicit_credentialsc   s    z0TestClient.test_constructor_implicit_credentialsc                 C   s   t  }d }| || d S r   )objectr*   )r
   r'   r&   r   r   r   -test_constructor_credentials_wo_create_scopedq   s    z8TestClient.test_constructor_credentials_wo_create_scopedc                    s>   t  }| j| j|d  fdd}| _ fdd}| _ S )Nr   r   c                      s   t   _d S r   )r>   r"   r   r   r   r   
mock_startz   s    z6TestClient._context_manager_helper.<locals>.mock_startc                      s
   d  _ d S r   )r"   r   r   r   r   	mock_stop~   s    z5TestClient._context_manager_helper.<locals>.mock_stop)r-   r   r   startstop)r
   r   rA   rB   r   r   r   _context_manager_helperv   s    z"TestClient._context_manager_helperc                 C   sZ   |   }| |  | | |  W d    n1 s>0    Y  | |  d S r   )rE   assertFalse
is_startedr   r
   r   r   r   r   test_context_manager   s
    ,zTestClient.test_context_managerc                 C   s6   |   }| | W d    n1 s(0    Y  d S r   )rE   ZassertIsNotNonerH   r   r   r   test_context_manager_as_keyword   s    
z*TestClient.test_context_manager_as_keywordc                 C   s   |   }| |  G dd dt}z<|$ | |  | W d    n1 sV0    Y  W n |yt   Y n0 | |  d S )Nc                   @   s   e Zd ZdS )zFTestClient.test_context_manager_with_exception.<locals>.DummyExceptionN)__name__
__module____qualname__r   r   r   r   DummyException   s   rN   )rE   rF   rG   	Exceptionr   )r
   r   rN   r   r   r   #test_context_manager_with_exception   s    (z.TestClient.test_context_manager_with_exceptionc                 C   s   t d}| j| j|||| j| jd}t |_t |_t |_t |_	|
 }| |j|j | |j|j | |j|j | |j|j | |j|j | |jd  | |jd  | |jd  | |j	d  d S )Nvalue)r   r   r   r   r   r   )r-   r   r   TIMEOUT_SECONDS
USER_AGENTr>   r"   r#   r$   r%   copyr    Z_adminr   r   r   r   )r
   r   r   r   r   Z
new_clientr   r   r   _copy_test_helper   s.    	zTestClient._copy_test_helperc                 C   s   |    d S r   rU   r
   r   r   r   	test_copy   s    zTestClient.test_copyc                 C   s   | j dd d S NTr1   rV   rW   r   r   r   test_copy_admin   s    zTestClient.test_copy_adminc                 C   s   | j dd d S )NTr3   rV   rW   r   r   r   test_copy_read_only   s    zTestClient.test_copy_read_onlyc                 C   s,   t  }d}| j||d}| |j|u  d S Nr   r@   )r-   r   r   r   r
   r   r   r   r   r   r   test_credentials_getter   s    z"TestClient.test_credentials_getterc                 C   s2   t  }d}| j||d}d| }| |j| d S )Nr   r@   	projects/)r-   r   r    project_name)r
   r   r   r   r`   r   r   r   test_project_name_property   s
    z%TestClient.test_project_name_propertyc                 C   s6   t  }d}| j||d}t |_| |j|ju  d S r\   )r-   r   r>   r"   r   
_data_stubr]   r   r   r   test_data_stub_getter   s
    z TestClient.test_data_stub_getterc                 C   sP   t  }d}| j||d}| t t|d W d    n1 sB0    Y  d S )Nr   r@   rb   r-   r   r5   r6   getattrr]   r   r   r   test_data_stub_failure   s
    z!TestClient.test_data_stub_failurec                 C   s8   t  }d}| j||dd}t |_| |j|ju  d S Nr   Tr   r   r   )r-   r   r>   r#   r   _instance_stubr]   r   r   r   test_instance_stub_getter   s    
z$TestClient.test_instance_stub_getterc                 C   sR   t  }d}| j||dd}| t t|d W d    n1 sD0    Y  d S )Nr   Frh   ri   rd   r]   r   r   r   $test_instance_stub_non_admin_failure   s    z/TestClient.test_instance_stub_non_admin_failurec                 C   sR   t  }d}| j||dd}| t t|d W d    n1 sD0    Y  d S )Nr   Trh   ri   rd   r]   r   r   r    test_instance_stub_unset_failure   s    z+TestClient.test_instance_stub_unset_failurec                 C   s8   t  }d}| j||dd}t |_| |j|ju  d S rg   )r-   r   r>   r$   r   _operations_stubr]   r   r   r   test_operations_stub_getter   s    z&TestClient.test_operations_stub_getterc                 C   sR   t  }d}| j||dd}| t t|d W d    n1 sD0    Y  d S )Nr   Frh   rm   rd   r]   r   r   r   &test_operations_stub_non_admin_failure   s    z1TestClient.test_operations_stub_non_admin_failurec                 C   sR   t  }d}| j||dd}| t t|d W d    n1 sD0    Y  d S )Nr   Trh   rm   rd   r]   r   r   r   "test_operations_stub_unset_failure  s    z-TestClient.test_operations_stub_unset_failurec                 C   s8   t  }d}| j||dd}t |_| |j|ju  d S rg   )r-   r   r>   r%   r   _table_stubr]   r   r   r   test_table_stub_getter  s    z!TestClient.test_table_stub_getterc                 C   sR   t  }d}| j||dd}| t t|d W d    n1 sD0    Y  d S )Nr   Frh   rq   rd   r]   r   r   r   !test_table_stub_non_admin_failure  s    z,TestClient.test_table_stub_non_admin_failurec                 C   sR   t  }d}| j||dd}| t t|d W d    n1 sD0    Y  d S )Nr   Trh   rq   rd   r]   r   r   r   test_table_stub_unset_failure  s    z(TestClient.test_table_stub_unset_failurec                    s   ddl m} ddlm} ddlm} ddlm} ddlm} t }d}| j	||d}t
  g  fd	d
}	|||	d | }
W d    n1 s0    Y  | |
 u  | ||||fg d S )Nr   r8   r   )DATA_API_HOST_V2)DATA_API_PORT_V2)DATA_STUB_FACTORY_V2r   r@   c                     s    |   S r   appendr   Z	fake_stubmake_stub_argsr   r   mock_make_stub4  s    
z7TestClient.test__make_data_stub.<locals>.mock_make_stub
_make_stub)r<   r9   r   r   r	   ru   rv   rw   r-   r   r>   Z_make_data_stubr   r    )r
   r9   r)   ru   rv   rw   r   r   r   r}   resultr   r{   r   test__make_data_stub&  s*    &zTestClient.test__make_data_stubc                    s   ddl m} ddlm} ddlm} ddlm} ddlm} t }d}| j	||d}t
  g  fd	d
}	|||	d | }
W d    n1 s0    Y  | |
 u  | ||||fg d S )Nr   r8   r   )INSTANCE_ADMIN_HOST_V2)INSTANCE_ADMIN_PORT_V2)INSTANCE_STUB_FACTORY_V2r   r@   c                     s    |   S r   rx   rz   r{   r   r   r}   S  s    
z;TestClient.test__make_instance_stub.<locals>.mock_make_stubr~   )r<   r9   r   r   r	   r   r   r   r-   r   r>   Z_make_instance_stubr   r    )r
   r9   r)   r   r   r   r   r   r   r}   r   r   r{   r   test__make_instance_stubE  s*    &z#TestClient.test__make_instance_stubc                    s   ddl m} ddlm} ddlm} ddlm} ddlm} t }d}| j	||d}t
  g  fd	d
}	|||	d | }
W d    n1 s0    Y  | |
 u  | ||||fg d S )Nr   r8   r   )OPERATIONS_API_HOST_V2)OPERATIONS_API_PORT_V2)OPERATIONS_STUB_FACTORY_V2r   r@   c                     s    |   S r   rx   rz   r{   r   r   r}   r  s    
z=TestClient.test__make_operations_stub.<locals>.mock_make_stubr~   )r<   r9   r   r   r	   r   r   r   r-   r   r>   Z_make_operations_stubr   r    )r
   r9   r)   r   r   r   r   r   r   r}   r   r   r{   r   test__make_operations_stubd  s*    &z%TestClient.test__make_operations_stubc                    s   ddl m} ddlm} ddlm} ddlm} ddlm} t }d}| j	||d}t
  g  fd	d
}	|||	d | }
W d    n1 s0    Y  | |
 u  | ||||fg d S )Nr   r8   r   )TABLE_ADMIN_HOST_V2)TABLE_ADMIN_PORT_V2)TABLE_STUB_FACTORY_V2r   r@   c                     s    |   S r   rx   rz   r{   r   r   r}     s    
z8TestClient.test__make_table_stub.<locals>.mock_make_stubr~   )r<   r9   r   r   r	   r   r   r   r-   r   r>   Z_make_table_stubr   r    )r
   r9   r)   r   r   r   r   r   r   r}   r   r   r{   r   test__make_table_stub  s*    &z TestClient.test__make_table_stubc                 C   sT   t  }d}| j||d}| |  t |_| |  d |_| |  d S r\   )r-   r   rF   rG   r>   r"   r   r]   r   r   r   test_is_started  s    zTestClient.test_is_startedc           	         sN  ddl m} ddlm} ddlm} t }d}| j|||d}| g   fdd}|||d	 |  W d    n1 s0    Y  | 	|j
u  |r| 	|ju  | 	|ju  | 	|ju  | jd
 | t d
 nN| 	|jd u  | 	|jd u  | 	|jd u  | jd | t d | jg  d S )Nr   r8   	_FakeStubr   r   rh   c                     s     |  S r   rx   rz   r|   stubr   r   r}     s    
z7TestClient._start_method_helper.<locals>.mock_make_stubr~         )r<   r9   gcloud.bigtable._testingr   r   r   r-   r   rC   r   r"   r#   r$   r%   r    _enteredlen_exited)	r
   r   r9   r   r)   r   r   r   r}   r   r   r   _start_method_helper  s4    &zTestClient._start_method_helperc                 C   s   | j dd d S NFr1   r   rW   r   r   r   test_start_non_admin  s    zTestClient.test_start_non_adminc                 C   s   | j dd d S rY   r   rW   r   r   r   test_start_with_admin  s    z TestClient.test_start_with_adminc                 C   sL   t  }d}| j||d}t  |_}| |  |  | |j| d S r\   )r-   r   r>   r"   r   rG   rC   r    )r
   r   r   r   Z	data_stubr   r   r   test_start_while_started  s    z#TestClient.test_start_while_startedc           	      C   s   ddl m} t }d}| j|||d}| }| }||_||_||_||_|  | 	|jd u  | 	|jd u  | 	|jd u  | 	|jd u  | 
|jd | 
|jd d}| 
|j|g |r| 
|j|gd  n| 
|jg  d S )Nr   r   r   rh   NNN   )r   r   r-   r   r"   r#   r$   r%   rD   r   r    r   r   )	r
   r   r   r   r   r   Zstub1Zstub2Zexc_none_tripler   r   r   _stop_method_helper  s0    zTestClient._stop_method_helperc                 C   s   | j dd d S r   r   rW   r   r   r   test_stop_non_admin  s    zTestClient.test_stop_non_adminc                 C   s   | j dd d S rY   r   rW   r   r   r   test_stop_with_admin   s    zTestClient.test_stop_with_adminc                 C   sL   t  }d}| j||d}| |  t  |_}|  | |j| d S r\   )r-   r   rF   rG   r>   r#   rD   r    )r
   r   r   r   Zinstance_stubr   r   r   test_stop_while_stopped  s    z"TestClient.test_stop_while_stoppedc           
      C   s   ddl m} ddlm} ddlm} d}d}d}t }| j||d}|j||d	}	| t	|	| | 
|	j| | 
|	j| | 
|	j| | 
|	j| | |	j|u  d S )
Nr   )DEFAULT_SERVE_NODESInstance)_EXISTING_INSTANCE_LOCATION_IDr   r   r   r@   )display_name)Zgcloud.bigtable.clusterr   gcloud.bigtable.instancer   r   r-   r   instancer   
isinstancer    instance_idr   _cluster_location_id_cluster_serve_nodes_client)
r
   r   r   r   r   INSTANCE_IDDISPLAY_NAMEr   r   r   r   r   r   test_instance_factory_defaults  s"    z)TestClient.test_instance_factory_defaultsc           
      C   s   ddl m} d}d}d}d}d}t }| j||d}|j||||d	}	| t|	| | |	j| | |	j	| | |	j
| | |	j| | |	j|u  d S )
Nr   r   r   r   r   Zlocname   r@   )r   locationZserve_nodes)r   r   r-   r   r   r   r   r    r   r   r   r   r   )
r
   r   r   r   r   ZLOCATION_IDZSERVE_NODESr   r   r   r   r   r   ,test_instance_factory_w_explicit_serve_nodes&  s$    z7TestClient.test_instance_factory_w_explicit_serve_nodesc                 C   s   ddl m} ddl m} ddlm} d| j d }d}d}d	}d| j d
 | }d| j d
 | }	t }
| j| j|
d| jd}|j	d| j d}|j
|g|j||d|j|	|	dgd}|| |_}|g}||||||g}||f}| }| || | |jd|| jfi fg d S )Nr   )instance_pb2)bigtable_instance_admin_pb2r   r_   z/locations/locnameZFAILEDzinstance-id1zinstance-id2z/instances/T)r   r   r   r   )parent)namer   )failed_locations	instancesZListInstances)Zgcloud.bigtable._generatedr   r   r   r   r   r-   r   rR   ZListInstancesRequestZListInstancesResponser   r#   r   Zlist_instancesr    Zmethod_calls)r
   Zdata_v2_pb2Zmessages_v2_pb2r   ZLOCATIONZFAILED_LOCATIONZINSTANCE_ID1ZINSTANCE_ID2ZINSTANCE_NAME1ZINSTANCE_NAME2r   r   Z
request_pbZresponse_pbr   r   r   Zexpected_resultr   r   r   r   test_list_instances<  s^    

zTestClient.test_list_instances)FFNNN)FF)7rK   rL   rM   r   r   r   rR   rS   r   r   r*   r/   r0   r2   r4   r7   r=   r?   rE   rI   rJ   rP   rU   rX   rZ   r[   r^   ra   rc   rf   rj   rk   rl   rn   ro   rp   rr   rs   rt   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      sn      

		#r   c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
Test_MetadataPluginc                 C   s   ddl m} |S )Nr   )_MetadataPlugin)r	   r   )r
   r   r   r   r   r     s    z#Test_MetadataPlugin._getTargetClassc                 O   s   |   |i |S r   r   r   r   r   r   r     s    zTest_MetadataPlugin._makeOnec                 C   sp   ddl m} ddl m} d}d}t }||||d}| |}| |j|u  | |j| | |j	|g d S )Nr   r   r,   r   rS   )r   r   r   )
r	   r   r,   r-   r   r   r   r    Z_user_agentr!   )r
   r   r,   r   rS   r   r   transformerr   r   r   test_constructor  s    
z$Test_MetadataPlugin.test_constructorc                    s   ddl m} ddl m} ddl m} d}t|d}d}|||d}g   fd	d
}| |}	|	d |}
dd| fd|fg}| |
d  |  |d fg | |j|g | t|j	d d S )Nr   r   r   )r   Z	FOOBARBAZ)access_tokenr   r@   c                     s     |  d S r   rx   rz   callback_argsr   r   callback  s    z3Test_MetadataPlugin.test___call__.<locals>.callbackAuthorizationzBearer z
User-agentr   )
r	   r   r,   r   r-   r   r    r!   r   _tokens)r
   r   r,   r   Zaccess_token_expectedr   r   r   r   r   r   Z
cb_headersr   r   r   test___call__  s$    



z!Test_MetadataPlugin.test___call__N)rK   rL   rM   r   r   r   r   r   r   r   r   r     s   r   c                   @   s   e Zd Zdd Zdd ZdS )Test__make_stubc                 O   s   ddl m} ||i |S )Nr   r~   )r	   r   )r
   r   r   r   r   r   r   _callFUT  s    zTest__make_stub._callFUTc                    sF  ddl m} ddlm} t g t t t t  G  fdddt}| }fdd}t g fdd	}d
}d}t }	||||d  | |	|||}
W d    n1 s0    Y  | |
u  |  g | |	g | |jd | |j	fddif | |j
f | |j||f d S )Nr   r8   r   c                       sD   e Zd Zdd ZfddZfddZfddZ fd	d
ZdS )z7Test__make_stub.test_it.<locals>._ImplementationsModulec                 S   s   d | _ d | _d | _d | _d S r   )ssl_channel_credentials_argsmetadata_call_credentials_args"composite_channel_credentials_argssecure_channel_argsrW   r   r   r   __init__  s    z@Test__make_stub.test_it.<locals>._ImplementationsModule.__init__c                    s
   || _  S r   )r   r
   r   )	SSL_CREDSr   r   ssl_channel_credentials  s    zOTest__make_stub.test_it.<locals>._ImplementationsModule.ssl_channel_credentialsc                    s   ||f| _  S r   )r   r   )METADATA_CREDSr   r   metadata_call_credentials  s    
zQTest__make_stub.test_it.<locals>._ImplementationsModule.metadata_call_credentialsc                    s
   || _  S r   )r   r   )COMPOSITE_CREDSr   r   composite_channel_credentials  s    zUTest__make_stub.test_it.<locals>._ImplementationsModule.composite_channel_credentialsc                    s
   || _  S r   )r   r   )CHANNELr   r   secure_channel  s    zFTest__make_stub.test_it.<locals>._ImplementationsModule.secure_channelN)rK   rL   rM   r   r   r   r   r   r   )r   r   r   r   r   r   _ImplementationsModule  s
   r   c                    s    |   S r   rx   )Zchannel)mock_resultstub_inputsr   r   mock_stub_factory  s    
z2Test__make_stub.test_it.<locals>.mock_stub_factoryc                    s     |  S r   rx   r   )clientsmetadata_pluginr   r   mock_plugin  s    
z,Test__make_stub.test_it.<locals>.mock_pluginZHOSTi  )Zimplementationsr   r   r   Zgoogle_creds)r<   r9   r   r   r>   r   r   r    r   r   r   r   )r
   r9   r)   r   Zimplementations_modr   r   hostportr   r   r   )r   r   r   r   r   r   r   r   r   test_it  sJ    .zTest__make_stub.test_itN)rK   rL   rM   r   r   r   r   r   r   r     s   r   c                   @   s2   e Zd ZdZd
ddZdd Zdd Zdd	 ZdS )r-   Nc                 C   s   || _ g | _d S r   )_access_tokenr   )r
   r   r   r   r   r      s    z_Credentials.__init__c                 C   s*   ddl m} || jd d}| j| |S )Nr   )AccessTokenInfo)r   Z
expires_in)Zoauth2client.clientr   r   r   ry   )r
   r   tokenr   r   r   get_access_token  s    z_Credentials.get_access_tokenc                 C   s
   || _ | S r   )r!   )r
   scoper   r   r   create_scoped  s    z_Credentials.create_scopedc                 C   s   | j |j kS r   )r   )r
   otherr   r   r   __eq__  s    z_Credentials.__eq__)N)rK   rL   rM   r!   r   r   r   r   r   r   r   r   r-     s
   
r-   )Z	unittest2ZTestCaser   r   r   r>   r-   r   r   r   r   <module>   s       p1L