Your IP : 216.73.216.172


Current Path : /lib/python3/dist-packages/certbot/plugins/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/certbot/plugins/__pycache__/storage_test.cpython-38.pyc

U

�]��@s~dZddlZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZ
Gdd	�d	e
j�Zed
krze��dS)z/Tests for certbot.plugins.storage.PluginStorage�N)�errors)�os)�
filesystem)�common)�utilcs`eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Z�Z
S)�PluginStorageTestz.Test for certbot.plugins.storage.PluginStoragec	sPtt|���tj|_t�|jj	�t
�d��|j|jdd�|_W5QRXdS)N�certbot.reverter.util�
mockplugin)�config�name)
�superr�setUprZ	Installer�
plugin_clsr�mkdirr
�
config_dir�mock�patch�plugin��self��	__class__��>/usr/lib/python3/dist-packages/certbot/plugins/storage_test.pyr
s
zPluginStorageTest.setUpcCs�ttj�|jjd�d��}|�d�W5QRXt��}t	|_
tj�|jjd�|jj_
t�d|��Jtjddd��0t�d��|�tj|jjj�W5QRXW5QRXW5QRXdS)	N�.pluginstorage.json�wZdummyzsix.moves.builtins.openzcertbot.compat.os.path.isfileT)Zreturn_valuer)�openr�path�joinr
r�writer�	mock_open�IOError�side_effectr�storage�storagepathr�assertRaisesr�PluginStorageError�_load)r�fhr rrr�test_load_errors_cant_reads$���
�z,PluginStorageTest.test_load_errors_cant_readc
Cs�ttj�|jjd�d��}|�d�W5QRXt�d��`}t�d��|�	|jd�}W5QRX|�
t|jj
d�|�|j�|�d|jd	d	k�W5QRXdS)
Nrr�z$certbot.plugins.storage.logger.debugrr	�valuezno values loadedr)rrrrr
rrrrrr%�KeyErrorr#�fetch�
assertTrueZcalled�	call_args)rr(�mock_logZ	nocontentrrr�test_load_errors_empty's�z(PluginStorageTest.test_load_errors_emptyc
Cs�ttj�|jjd�d��}|�d�W5QRXt�d��V}t�d��|�	|jd�}W5QRX|�
tj|j
jd�|�d|jd	d	k�W5QRXdS)
Nrrzinvalid json�$certbot.plugins.storage.logger.errorrr	r+zis corruptedr)rrrrr
rrrrrr%rZPluginErrorr#r-r.r/)rr(r0Z	corruptedrrr�test_load_errors_corrupted3s���z,PluginStorageTest.test_load_errors_corruptedc	Csft�d��R}d|jj_d|jj_|j|jj_|�t	j
|jjj�|�d|j
ddk�W5QRXdS)Nr2Tz
/tmp/whateverzCould not serializer)rrrr#�_initializedr$r�_datar%rr&�saver.r/)rr0rrr�test_save_errors_cant_serialize?s

�z1PluginStorageTest.test_save_errors_cant_serializec
Cs�t��}t|_t�d|��`t�d��J}ddi|jj_d|jj_|�	t
j|jjj�|�
d|jddk�W5QRXW5QRXdS)Nzcertbot.compat.filesystem.openr2Zvalid�dataTzCould not writer)rr r!r"rrr#r5r4r%rr&r6r.r/)rr r0rrr�%test_save_errors_unable_to_write_fileIs
�z7PluginStorageTest.test_save_errors_unable_to_write_filec	Cs6t�d��"|�tj|�|jd�jj�W5QRXdS)Nr�x)	rrr%rr&rr
r#r6rrrr�test_save_uninitializedTs�z)PluginStorageTest.test_save_uninitializedc	Cs|t�d��"|�|jd�}|�|jd�}W5QRX|j�dd�|�t|jjd�|�t|jjd�|�	|j�d�d�dS)Nr�first�secondZ	first_keyZfirst_value)
rrrr
r#�putr%r,r-�assertEqual)rZplugin1Zplugin2rrr�test_namespace_isolationYs��z*PluginStorageTest.test_namespace_isolationc	Cs�|jj�dd�|jj��t�d��|�|jd�}W5QRX|�|j�	d�d�t
tj�
|jjd�d��}|��}W5QRXt�|�}|�d|��k�|�t|�d�|�|ddd�dS)NZtestkeyZ	testvaluerr	r�r�)rr#r>r6rrrr
r?r-rrrrr�read�json�loadsr.�keys�len)rZanotherr(ZpsdataZpsjsonrrr�test_saved_statees ��
z"PluginStorageTest.test_saved_state)�__name__�
__module__�__qualname__�__doc__r
r)r1r3r7r9r;r@rH�
__classcell__rrrrrs
r�__main__)rLrDZunittestrZcertbotrZcertbot.compatrrZcertbot.pluginsrZ
certbot.testsrZ	test_utilZConfigTestCaserrI�mainrrrr�<module>sh