o
    wOi                     @   sj   d dl Z d dlZd dlZd dlZd dlZzd dlZW n ey)   d dl mZ Y nw G dd de jZ	dS )    N)mockc                   @   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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/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9S ):
TestClientc                 C   s   t  }|dus
J dS )z client can be instantiatedN)etcdClientselfclient r	   O/home/ubuntu/.local/lib/python3.10/site-packages/etcd/tests/unit/test_client.pytest_instantiate   s   zTestClient.test_instantiatec                 C      t  }|jdksJ dS )z default host is 127.0.0.1z	127.0.0.1Nr   r   hostr   r	   r	   r
   test_default_host      zTestClient.test_default_hostc                 C   r   )z default port is 4001  Nr   r   portr   r	   r	   r
   test_default_port   r   zTestClient.test_default_portc                 C   s   t  }|jdksJ d S )Nz/v2r   r   version_prefixr   r	   r	   r
   test_default_prefix   s   zTestClient.test_default_prefixc                 C   r   )z default protocol is httphttpNr   r   protocolr   r	   r	   r
   test_default_protocol!   r   z TestClient.test_default_protocolc                 C   r   )z default read_timeout is 60<   Nr   r   read_timeoutr   r	   r	   r
   test_default_read_timeout&   r   z$TestClient.test_default_read_timeoutc                 C   s   t  }|js	J dS )z default allow_redirect is TrueNr   r   allow_redirectr   r	   r	   r
   test_default_allow_redirect+   s   z&TestClient.test_default_allow_redirectc                 C      t  }|jdu sJ dS z default username is NoneNr   r   usernamer   r	   r	   r
   test_default_username0   r   z TestClient.test_default_usernamec                 C   r#   r$   r   r   passwordr   r	   r	   r
   test_default_password5   r   z TestClient.test_default_passwordc                 C      t jdd}|jdksJ dS )z can change host 192.168.1.1r   Nr   r   r	   r	   r
   test_set_host:      zTestClient.test_set_hostc                 C   r+   )z can change port   )r   Nr   r   r	   r	   r
   test_set_port?   r/   zTestClient.test_set_portc                 C   s   t jdd}|jdksJ d S )Nz/etcd)r   r   r   r	   r	   r
   test_set_prefixD      zTestClient.test_set_prefixc                 C   r+   )z can change protocol https)r   Nr   r   r	   r	   r
   test_set_protocolH   r/   zTestClient.test_set_protocolc                 C   r+   )z can set read_timeout -   )r   Nr   r   r	   r	   r
   test_set_read_timeoutM   r/   z TestClient.test_set_read_timeoutc                 C   s   t jdd}|jrJ dS )z can change allow_redirect F)r!   Nr    r   r	   r	   r
   test_set_allow_redirectR      z"TestClient.test_set_allow_redirectc                 C   r   )z& default uri is http://127.0.0.1:4001 zhttp://127.0.0.1:4001Nr   r   base_urir   r	   r	   r
   test_default_base_uriW   r   z TestClient.test_default_base_uric                 C   s"   t jdddd}|jdksJ dS )z can change base uri r,   i  r4   )r   r   r   zhttps://192.168.1.1:4003Nr:   r   r	   r	   r
   test_set_base_uri\   s   zTestClient.test_set_base_uric                 C   s   t jdd}|jsJ dS )z can set the use_proxies flag T)use_proxiesN)r   r   _use_proxiesr   r	   r	   r
   test_set_use_proxiesd   r9   zTestClient.test_set_use_proxiesc                 C      t jdd}|jd u sJ d S )Nr&   )r&   r%   r   r	   r	   r
   test_set_username_onlyi   r3   z!TestClient.test_set_username_onlyc                 C   rA   )Nr)   )r)   r(   r   r	   r	   r
   test_set_password_onlym   r3   z!TestClient.test_set_password_onlyc                 C   s.   t jddd}|jdksJ |jdksJ d S )Nr&   r)   r&   r)   )r   r   r&   r)   r   r	   r	   r
   test_set_username_passwordq   s   z%TestClient.test_set_username_passwordc                 C   s&   t jddd}| ddiksJ d S )Nr&   r)   rD   authorizationzBasic dXNlcm5hbWU6cGFzc3dvcmQ=r   r   _get_headersr   r	   r	   r
   test_get_headers_with_authv   s   z%TestClient.test_get_headers_with_authc                 C   s   t d;}| j}t jdd|_t }|  |j|j	|j
d t jt jt jd | d|j | d|j W d   dS 1 sCw   Y  dS )	z<Verify _set_version_info makes the proper call to the serverurllib3.PoolManager/   {"etcdserver": "2.2.3", "etcdcluster": "2.3.0"}dataz/version)headersredirecttimeout2.2.32.3.0N)r   patchrequest	MagicMockreturn_valuer   r   _set_version_infoassert_called_once_with_MGET	_base_uriANYassertEqualsversioncluster_versionr   _pm_requestr   r	   r	   r
   test__set_version_info|   s"   "z!TestClient.test__set_version_infoc                 C   \   t d}| j}t jdd|_t }| d|j W d   dS 1 s'w   Y  dS )z3Ensure the version property is set on first access.rJ   rK   rL   rQ   N)	r   rS   rT   rU   rV   r   r   r\   r]   r_   r	   r	   r
   test_version_property      "z TestClient.test_version_propertyc                 C   rc   )z;Ensure the cluster version property is set on first access.rJ   rK   rL   rR   N)	r   rS   rT   rU   rV   r   r   r\   r^   r_   r	   r	   r
   test_cluster_version_property   re   z(TestClient.test_cluster_version_propertyc                 C   s   t  }| i ksJ d S )NrG   r   r	   r	   r
   test_get_headers_without_auth   s   z(TestClient.test_get_headers_without_authc                 C   sL   |  tj tjdd W d   n1 sw   Y  tjdddd}dS )z? Fails if allow_reconnect is false and a list of hosts is given))	localhostr   )rh   r0   r-   NT)r   allow_reconnectr>   )assertRaisesr   EtcdExceptionr   r   r	   r	   r
   test_allow_reconnect   s   
zTestClient.test_allow_reconnectc              	   C   s   g }t ddD ]/}ttjjjj}d|_ztjj	}W n t
y(   tjj}Y nw |d||_|| qtjtjj|dtj_tjj| _tjtjjdgdtj_tjddd	d
}| jtj_| |jd | |jd | |jdg dS )zTests discovery.      iK	  zetcd{}.example.com)rV   zhttps://etcd2.example.com:2379zexample.comTr4   )
srv_domainri   r   zetcd1.example.comN)ranger   create_autospecdnsrdtypesINSRVr   namefrom_unicodeAttributeError	from_textformattargetappendresolverqueryr   r   machinesr\   r   _machines_cache)r   answersirmethodcr	   r	   r
   test_discover   s*   

zTestClient.test_discoverN)__name__
__module____qualname__r   r   r   r   r   r   r"   r'   r*   r.   r1   r2   r5   r7   r8   r<   r=   r@   rB   rC   rE   rI   rb   rd   rf   rg   rl   r   r	   r	   r	   r
   r      s:    r   )
unittestr   dns.namerr   dns.rdtypes.IN.SRVdns.resolverr   ImportErrorTestCaser   r	   r	   r	   r
   <module>   s    