Your IP : 216.73.216.224


Current Path : /lib/python3/dist-packages/josepy/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/josepy/__pycache__/json_util_test.cpython-38.pyc

U

��]�7�@s�dZddlZddlZddlZddlZddlmZmZmZm	Z	e�
d�Ze�d�Z
Gdd�dej�ZGdd	�d	ej�ZGd
d�dej�ZGdd
�d
ej�ZGdd�dej�Zedkr�e��dS)zTests for josepy.json_util.�N)�errors�
interfaces�	test_util�utilzcert.pemzcsr.pemc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�	FieldTestz!Tests for josepy.json_util.Field.cCsPddlm}t�ddgddgddg�D]$\}}}|�|d||d��|��q&dS)Nr��FieldTF�foo)�default�	omitempty)�josepy.json_utilr�	itertools�productZassertFalseZomit)�selfrr
r�value�r�7/usr/lib/python3/dist-packages/josepy/json_util_test.py�test_no_omit_booleans��zFieldTest.test_no_omit_booleancCszt��}dd�}dd�}ddlm}|d�}|�|�}|�d|�|��|�|�}|�d|�|��|�d	|�|��dS)
NcSsdS)N�dr�Zunused_valuerrr�decodersz+FieldTest.test_descriptors.<locals>.decodercSsdS)N�errrrr�encoder sz+FieldTest.test_descriptors.<locals>.encoderrrr	rr)	�mock�	MagicMockrrr�assertEqual�encoder�decode)r�
mock_valuerrr�fieldrrr�test_descriptorss

zFieldTest.test_descriptorscCsNGdd�dtj�}|�}ddlm}|�|�|�|k�|�d|�|��dS)Nc@s eZdZdd�Zedd��ZdS)z<FieldTest.test_default_encoder_is_partial.<locals>.MockFieldcSsdS�Nr	r�rrrr�to_partial_json0szLFieldTest.test_default_encoder_is_partial.<locals>.MockField.to_partial_jsoncSsdS�Nr��clsZjobjrrr�	from_json3szFFieldTest.test_default_encoder_is_partial.<locals>.MockField.from_jsonN)�__name__�
__module__�__qualname__r#�classmethodr'rrrr�	MockField.sr,rrr	)rZJSONDeSerializablerr�
assertTrue�default_encoderZassertNotEqual)rr,Z
mock_fieldrrrr�test_default_encoder_is_partial-s
z)FieldTest.test_default_encoder_is_partialcCs,t��}ddlm}|�|�|�|k�dS�Nrr)rrrrr-r.�rrrrrr� test_default_encoder_passthrough=sz*FieldTest.test_default_encoder_passthroughcCs(ddlm}|�d|�dddg��dS)Nrr)���r3r4r5)rrr�default_decoder)rrrrr�"test_default_decoder_list_to_tupleBsz,FieldTest.test_default_decoder_list_to_tuplecCsDddlm}|�ddi�}|�t|tj��|�|tjdd��dS)Nrr�xr4�r8)rrr6r-�
isinstancerZ
frozendictr)rr�objrrr�'test_default_decoder_dict_to_frozendictFsz1FieldTest.test_default_decoder_dict_to_frozendictcCs,t��}ddlm}|�|�|�|k�dSr0)rrrrr-r6r1rrr� test_default_decoder_passthroughLsz*FieldTest.test_default_decoder_passthroughN)r(r)r*�__doc__rr r/r2r7r<r=rrrrrsrc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�JSONObjectWithFieldsMetaTestz4Tests for josepy.json_util.JSONObjectWithFieldsMeta.cs�ddlm}ddlm}|d��_|d��_t�|�G�fdd�dt��}Gdd	�d	|�}G�fd
d�d|�}|�_|�_	|�_
dS)Nrr)�JSONObjectWithFieldsMetaZBazZBaz2cseZdZdZ�jZdS)z-JSONObjectWithFieldsMetaTest.setUp.<locals>.A��barN)r(r)r*�	__slots__r�bazrr"rr�A]srEc@seZdZdS)z-JSONObjectWithFieldsMetaTest.setUp.<locals>.BN)r(r)r*rrrr�BbsrFcseZdZ�jZdS)z-JSONObjectWithFieldsMetaTest.setUp.<locals>.CN)r(r)r*�field2rDrr"rr�CesrH)rrr@rrG�sixZ
add_metaclass�object�a_cls�b_cls�c_cls)rrr@rErFrHrr"r�setUpUs

z"JSONObjectWithFieldsMetaTest.setUpcCs0|�d|ji|jj�|�d|ji|jj�dS�NrD)rrrK�_fieldsrLr"rrr�test_fieldslsz(JSONObjectWithFieldsMetaTest.test_fieldscCs|�d|ji|jj�dSrO)rrGrMrPr"rrr�test_fields_inheritanceqsz4JSONObjectWithFieldsMetaTest.test_fields_inheritancecCs$|�d|jj�|�d|jj�dS)N)rBrD)rD)rrKrCrLr"rrr�
test_slotsusz'JSONObjectWithFieldsMetaTest.test_slotscCs$|�d|jj�|�d|jj�dS)NrAr)rrKZ_orig_slotsrLr"rrr�test_orig_slotsysz,JSONObjectWithFieldsMetaTest.test_orig_slotsN)	r(r)r*r>rNrQrRrSrTrrrrr?Rsr?c@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�JSONObjectWithFieldsTestz0Tests for josepy.json_util.JSONObjectWithFields.csFddlm}ddlm�G�fdd�d|�}||_|dddd�|_dS)	Nr)�JSONObjectWithFieldsrcsPeZdZ�dddd�dd�d�Z�d�Z�d�Zejd	d
��Zejdd
��ZdS)
z@JSONObjectWithFieldsTest.setUp.<locals>.MockJSONObjectWithFieldsr8TcSs|dS�Nr4rr9rrr�<lambda>��zIJSONObjectWithFieldsTest.setUp.<locals>.MockJSONObjectWithFields.<lambda>cSs|dSrWrr9rrrrX�rY)rrr�y�ZcSs|dkrt���|S�N��)r�SerializationError�rrrrrZ�szBJSONObjectWithFieldsTest.setUp.<locals>.MockJSONObjectWithFields.ycSs|dkrt���|Sr\)r�DeserializationErrorr_rrrrZ�sN)r(r)r*r8rZ�zrrrrrr�MockJSONObjectWithFields�s�
rbr4r5�r8rZra)rrVrrbr)rrVrbrrrrN�s
zJSONObjectWithFieldsTest.setUpcCs|�|j|jddd��dS)Nr4r5�rZra)rrrbr"rrr�test_init_defaults�sz+JSONObjectWithFieldsTest.test_init_defaultscCs"|�d|jdddd��d��dS)N�
�rrcr8)rrbrr"rrr�test_encode�s
��z$JSONObjectWithFieldsTest.test_encodecCs|�tj|jjd�dSr!)�assertRaisesr�Errorrrr"rrr�test_encode_wrong_field�sz0JSONObjectWithFieldsTest.test_encode_wrong_fieldcCs |�tj|jddd�jd�dS)Nr]rdrZ)rirr^rbrr"rrr�+test_encode_serialization_error_passthrough�s
�zDJSONObjectWithFieldsTest.test_encode_serialization_error_passthroughcCs|�|j��ddd��dS)Nr4r5�rZr[)rr�fields_to_partial_jsonr"rrr�'test_fields_to_partial_json_omits_empty�sz@JSONObjectWithFieldsTest.test_fields_to_partial_json_omits_emptycCs&|�dddd�|j�ddd���dS)Nr4r5rcrm�rrb�fields_from_jsonr"rrr�-test_fields_from_json_fills_default_for_empty�s
�zFJSONObjectWithFieldsTest.test_fields_from_json_fills_default_for_emptycCsh|�tj|jjddi�|�tj|jjddi�|�tj|jjddd��|�tj|jjddd��dS)NrZrr[)r8rZ)r8r[)rirr`rbrqr"rrr�&test_fields_from_json_fails_on_missing�s(����z?JSONObjectWithFieldsTest.test_fields_from_json_fails_on_missingcCs(|�|jdddd���dddd��dS)Nr3r4r5rc�r8rZr[)rrbr#r"rrr�#test_fields_to_partial_json_encoder�s
�z<JSONObjectWithFieldsTest.test_fields_to_partial_json_encoderc	Cs(|�dddd�|j�dddd���dS)Nr4r5rc�rtrpr"rrr�test_fields_from_json_decoder�s

��z6JSONObjectWithFieldsTest.test_fields_from_json_decodercCs |�tj|jdddd�j�dS)Nr3r]r5rc)rirr^rbr#r"rrr�-test_fields_to_partial_json_error_passthrough�s��zFJSONObjectWithFieldsTest.test_fields_to_partial_json_error_passthroughcCs |�tj|jjdddd��dS)Nrvr]r5rt)rirr`rbr'r"rrr�'test_fields_from_json_error_passthrough�s

�z@JSONObjectWithFieldsTest.test_fields_from_json_error_passthroughN)r(r)r*r>rNrerhrkrlrorrrsrurwrxryrrrrrUsrUc@s|eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�DeEncodersTestcCsd|_d|_dS)Na�MIIB3jCCAYigAwIBAgICBTkwDQYJKoZIhvcNAQELBQAwdzELMAkGA1UEBhMCVVMxETAPBgNVBAgMCE1pY2hpZ2FuMRIwEAYDVQQHDAlBbm4gQXJib3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x�eA)rr}r-r:rI�string_typesr)rr}�encodedrrr�test_encode_b64jose�sz"DeEncodersTest.test_encode_b64josecCs6ddlm}|d�}|�t|tj��|�d|�dS)Nr��decode_b64joserr~)rr�r-r:rI�binary_typer)rr��decodedrrr�test_decode_b64jose�sz"DeEncodersTest.test_decode_b64josecCs ddlm}|�tj|d�dS)Nrr�r8)rr�rirr`�rr�rrr�!test_decode_b64jose_padding_errorsz0DeEncodersTest.test_decode_b64jose_padding_errorcCsLddlm}|�d|ddd��|jtj|ddd�|jtj|ddd�dS)	Nrr��foo�Zm9vr5)�sizer4rv�rr�rrirr`r�rrr�test_decode_b64jose_sizes��z'DeEncodersTest.test_decode_b64jose_sizecCsRddlm}|�d|dddd��|�d|dddd��|jtj|dd	dd�dS)
Nrr�r�r�r5T�r�Zminimumr4rvr�r�rrr� test_decode_b64jose_minimum_sizes
�z/DeEncodersTest.test_decode_b64jose_minimum_sizecCs6ddlm}|d�}|�d|�|�t|tj��dS)Nr)�encode_hex16r��666f6f)rr�rr-r:rIr�)rr�r�rrr�test_encode_hex16sz DeEncodersTest.test_encode_hex16cCs6ddlm}|d�}|�d|�|�t|tj��dS)Nr��decode_hex16r�r�)rr�rr-r:rIr�)rr�r�rrr�test_decode_hex16sz DeEncodersTest.test_decode_hex16cCsRddlm}|�d|dddd��|�d|dddd��|jtj|dd	dd�dS)
Nrr�r�r�r5Tr�r4rv)rr�rrirr`�rr�rrr�test_decode_hex16_minimum_size!s
�z-DeEncodersTest.test_decode_hex16_minimum_sizecCs ddlm}|�tj|d�dS)Nrr�r8)rr�rirr`r�rrr�test_decode_hex16_odd_length(sz+DeEncodersTest.test_decode_hex16_odd_lengthcCs"ddlm}|�|j|t��dS)Nr)�encode_cert)rr�rr{�CERT)rr�rrr�test_encode_cert,szDeEncodersTest.test_encode_certcCsHddlm}||j�}|�t|tj��|�|t�|�	t
j|d�dS)Nr)�decode_cert�)rr�r{r-r:r�ComparableX509rr�rirr`)rr�Zcertrrr�test_decode_cert0s

zDeEncodersTest.test_decode_certcCs"ddlm}|�|j|t��dS)Nr)�
encode_csr)rr�rr|�CSR)rr�rrr�test_encode_csr7szDeEncodersTest.test_encode_csrcCsHddlm}||j�}|�t|tj��|�|t�|�	t
j|d�dS)Nr)�
decode_csrr�)rr�r|r-r:rr�rr�rirr`)rr�Zcsrrrr�test_decode_csr;s

zDeEncodersTest.test_decode_csrN)r(r)r*rNr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrz�srzc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TypedJSONObjectWithFieldsTestcCsHddlm}Gdd�d|�}|jGdd�d|��}||_|dd�|_dS)	Nr)�TypedJSONObjectWithFieldsc@seZdZiZdZdS)zPTypedJSONObjectWithFieldsTest.setUp.<locals>.MockParentTypedJSONObjectWithFields�typeN)r(r)r*ZTYPESZtype_field_namerrrr�#MockParentTypedJSONObjectWithFieldsKsr�c@s(eZdZdZdZedd��Zdd�ZdS)zJTypedJSONObjectWithFieldsTest.setUp.<locals>.MockTypedJSONObjectWithFields�test�r	cSsd|diSr!rr%rrrrqUsz[TypedJSONObjectWithFieldsTest.setUp.<locals>.MockTypedJSONObjectWithFields.fields_from_jsoncSs
d|jiSr!r�r"rrrrnYszaTypedJSONObjectWithFieldsTest.setUp.<locals>.MockTypedJSONObjectWithFields.fields_to_partial_jsonN)r(r)r*�typrCr+rqrnrrrr�MockTypedJSONObjectWithFieldsOs

r�rBr�)rr��register�
parent_cls�msg)rr�r�r�rrrrNEs
�z#TypedJSONObjectWithFieldsTest.setUpcCs|�|j��ddd��dS)Nr�rB�r�r	)rr�r#r"rrr�test_to_partial_json_s�z2TypedJSONObjectWithFieldsTest.test_to_partial_jsoncCs*gdddfD]}|�tj|jj|�qdS)NrrgZasd�rirr`r�r')rrrrr�test_from_json_non_dict_failses�z;TypedJSONObjectWithFieldsTest.test_from_json_non_dict_failscCs|�tj|jji�dSr$r�r"rrr�!test_from_json_dict_no_type_failsjs
�z?TypedJSONObjectWithFieldsTest.test_from_json_dict_no_type_failscCs|�tj|jjddi�dS)Nr�rB)rirZUnrecognizedTypeErrorr�r'r"rrr�!test_from_json_unknown_type_failsns�z?TypedJSONObjectWithFieldsTest.test_from_json_unknown_type_failscCs"|�ddi|j�ddd���dS)Nr	rBr�r�)rr�r'r"rrr�test_from_json_returns_objrs�z8TypedJSONObjectWithFieldsTest.test_from_json_returns_objN)	r(r)r*rNr�r�r�r�r�rrrrr�Csr��__main__)r>r
ZunittestrrIZjosepyrrrrZload_comparable_certr�Zload_comparable_csrr�ZTestCaserr?rUrzr�r(�mainrrrr�<module>s

D-]g4