
ํยะZห  ใ               @   sธ   d  Z  d d l Z d d l Z d d l Z d d l m Z Gd d   d e j  Z Gd d   d e j  Z Gd d	   d	 e j  Z	 Gd
 d   d e j  Z
 e d k rด e j   d S)zTests for josepy.util.้    N)ฺ	test_utilc               @   sj   e  Z d  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 S)ฺComparableX509Testz%Tests for josepy.util.ComparableX509.c             C   sp   t  j d  |  _ t  j d  |  _ t  j d  |  _ t  j d  |  _ t  j d  |  _ t  j d  |  _ d  S)Nzcsr.pemzcsr-san.pemzcert.pemzcert-san.pem)	r   Zload_comparable_csrฺreq1ฺreq2ฺ	req_otherZload_comparable_certฺcert1ฺcert2ฺ
cert_other)ฺselfฉ r   ๚2/usr/lib/python3/dist-packages/josepy/util_test.pyฺsetUp   s    zComparableX509Test.setUpc             C   s   |  j  |  j j    d  S)N)ฺ
assertTruer   Zhas_expired)r
   r   r   r   ฺtest_getattr_proxy   s    z%ComparableX509Test.test_getattr_proxyc             C   s0   |  j  |  j |  j  |  j  |  j |  j  d  S)N)ฺassertEqualr   r   r   r   )r
   r   r   r   ฺtest_eq   s    zComparableX509Test.test_eqc             C   s0   |  j  |  j |  j  |  j  |  j |  j  d  S)N)ฺassertNotEqualr   r   r   r	   )r
   r   r   r   ฺtest_ne   s    zComparableX509Test.test_nec             C   s*   |  j  |  j d  |  j  |  j d  d  S)N้   )r   r   r   )r
   r   r   r   ฺtest_ne_wrong_types"   s    z&ComparableX509Test.test_ne_wrong_typesc             C   s   |  j  t |  j  t |  j   |  j t |  j  t |  j   |  j  t |  j  t |  j   |  j t |  j  t |  j   d  S)N)	r   ฺhashr   r   r   r   r   r   r	   )r
   r   r   r   ฺ	test_hash&   s    """zComparableX509Test.test_hashc             C   sC   x< |  j  |  j f D]( } |  j t |  d j | j   q Wd  S)Nz<ComparableX509({0!r})>)r   r   r   ฺreprฺformatฺwrapped)r
   Zx509r   r   r   ฺ	test_repr-   s    zComparableX509Test.test_reprN)ฺ__name__ฺ
__module__ฺ__qualname__ฺ__doc__r   r   r   r   r   r   r   r   r   r   r   r   
   s   
r   c               @   s   e  Z d  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 S)ฺComparableRSAKeyTestz'Tests for josepy.util.ComparableRSAKey.c             C   s:   t  j d  |  _ t  j d  |  _ t  j d  |  _ d  S)Nzrsa256_key.pemzrsa512_key.pem)r   Zload_rsa_private_keyฺkeyฺkey_sameฺkey2)r
   r   r   r   r   6   s    zComparableRSAKeyTest.setUpc             C   s   |  j  d |  j j  d  S)N้   )r   r!   Zkey_size)r
   r   r   r   r   <   s    z'ComparableRSAKeyTest.test_getattr_proxyc             C   s   |  j  |  j |  j  d  S)N)r   r!   r"   )r
   r   r   r   r   ?   s    zComparableRSAKeyTest.test_eqc             C   s   |  j  |  j |  j  d  S)N)r   r!   r#   )r
   r   r   r   r   B   s    zComparableRSAKeyTest.test_nec             C   s   |  j  |  j d  d  S)Nr   )r   r!   )r
   r   r   r   ฺtest_ne_different_typesE   s    z,ComparableRSAKeyTest.test_ne_different_typesc             C   s   |  j  |  j |  j j  d  S)N)r   r!   r"   Z_wrapped)r
   r   r   r   ฺtest_ne_not_wrappedH   s    z(ComparableRSAKeyTest.test_ne_not_wrappedc             C   s0   d d l  m } |  j | d  | d   d  S)Nr   )ฺComparableRSAKeyr   )ฺjosepy.utilr'   r   )r
   r'   r   r   r   ฺtest_ne_no_serializationL   s    z-ComparableRSAKeyTest.test_ne_no_serializationc             C   sg   |  j  t t |  j  t   |  j t |  j  t |  j   |  j t |  j  t |  j   d  S)N)	r   ฺ
isinstancer   r!   ฺintr   r"   r   r#   )r
   r   r   r   r   P   s    "zComparableRSAKeyTest.test_hashc             C   s#   |  j  t |  j  j d   d  S)Nz'<ComparableRSAKey(<cryptography.hazmat.)r   r   r!   ฺ
startswith)r
   r   r   r   r   U   s    zComparableRSAKeyTest.test_reprc             C   s3   d d l  m } |  j t |  j j   |   d  S)Nr   )r'   )r(   r'   r   r*   r!   Z
public_key)r
   r'   r   r   r   ฺtest_public_keyY   s    z$ComparableRSAKeyTest.test_public_keyN)r   r   r   r   r   r   r   r   r%   r&   r)   r   r   r-   r   r   r   r   r    3   s   r    c               @   sฆ   e  Z d  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 S)ฺImmutableMapTestz#Tests for josepy.util.ImmutableMap.c             C   sพ   d d l  m } Gd d   d |  } Gd d   d |  } | |  _ | |  _ |  j d d d	 d
  |  _ |  j d	 d
 d d  |  _ |  j d d d	 d  |  _ |  j d d d	 d
  |  _ d  S)Nr   )ฺImmutableMapc               @   s   e  Z d  Z d Z d S)z!ImmutableMapTest.setUp.<locals>.AฺxฺyN)r0   r1   )r   r   r   ฺ	__slots__r   r   r   r   ฺAf   s   r3   c               @   s   e  Z d  Z d Z d S)z!ImmutableMapTest.setUp.<locals>.Br0   r1   N)r0   r1   )r   r   r   r2   r   r   r   r   ฺBi   s   r4   r0   ้   r1   ้   ้   ้   )r(   r/   r3   r4   ฺa1ฺa1_swapฺa2ฺb)r
   r/   r3   r4   r   r   r   r   a   s    		zImmutableMapTest.setUpc             C   s]   |  j  |  j d d d d  |  j j d d   |  j  |  j |  j j d d d d   d  S)Nr0   r6   r1   r7   r8   )r   r3   r9   ฺupdater;   )r
   r   r   r   ฺtest_updatet   s    1zImmutableMapTest.test_updatec             C   s   |  j  t |  j j d  d  S)Nฺz)ฺassertRaisesฺKeyErrorr9   ฺ__getitem__)r
   r   r   r   ฺ&test_get_missing_item_raises_key_errorx   s    z7ImmutableMapTest.test_get_missing_item_raises_key_errorc             C   s   |  j  |  j |  j  d  S)N)r   r9   r:   )r
   r   r   r   ฺ"test_order_of_args_does_not_matter{   s    z3ImmutableMapTest.test_order_of_args_does_not_matterc             C   s6   |  j  t |  j d d |  j  t |  j d d d  S)Nr0   r5   r1   r6   )r@   ฺ	TypeErrorr3   )r
   r   r   r   ฺtest_type_error_on_missing~   s    z+ImmutableMapTest.test_type_error_on_missingc          	   C   sH   |  j  t |  j d d d d |  j  t |  j d d d d d d d  S)Nr0   r5   r?   r6   r1   r7   )r@   rE   r3   )r
   r   r   r   ฺtest_type_error_on_unrecognized   s    z0ImmutableMapTest.test_type_error_on_unrecognizedc             C   s\   |  j  d |  j j  |  j  d |  j j  |  j  d |  j j  |  j  d |  j j  d  S)Nr5   r6   )r   r9   r0   r1   r:   )r
   r   r   r   ฺtest_get_attr   s    zImmutableMapTest.test_get_attrc             C   s)   |  j  t t j |  j j d  d  d  S)Nr0   ้
   )r@   ฺAttributeErrorฺ	functoolsฺpartialr9   ฺ__setattr__)r
   r   r   r   ฺ$test_set_attr_raises_attribute_error   s    z5ImmutableMapTest.test_set_attr_raises_attribute_errorc             C   sF   |  j  |  j |  j  |  j  |  j |  j  |  j |  j |  j  d  S)N)r   r9   r;   r   )r
   r   r   r   ฺ
test_equal   s    zImmutableMapTest.test_equalc             C   s#   |  j  t d  t |  j   d  S)Nr5   r6   )r5   r6   )r   r   r9   )r
   r   r   r   r      s    zImmutableMapTest.test_hashc             C   s)   |  j  t |  j d d d i   j  d  S)Nr0   r5   r1   )r@   rE   r3   ฺ__hash__)r
   r   r   r   ฺtest_unhashable   s    z ImmutableMapTest.test_unhashablec             C   sw   |  j  d t |  j   |  j  d t |  j   |  j  d t |  j   |  j  d t |  j d d d d    d  S)NzA(x=1, y=2)zB(x=1, y=2)zB(x='foo', y='bar')r0   Zfoor1   Zbar)r   r   r9   r:   r<   r4   )r
   r   r   r   r      s    zImmutableMapTest.test_reprN)r   r   r   r   r   r>   rC   rD   rF   rG   rH   rN   rO   r   rQ   r   r   r   r   r   r.   ^   s   r.   c               @   s   e  Z d  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 S)ฺfrozendictTestz!Tests for josepy.util.frozendict.c             C   s,   d d l  m } | d d d d  |  _ d  S)Nr   )ฺ
frozendictr0   r5   r1   ฺ2)r(   rS   ฺfdict)r
   rS   r   r   r   r   ฅ   s    zfrozendictTest.setUpc             C   s9   d d l  m } |  j |  j | d d d d i   d  S)Nr   )rS   r0   r5   r1   rT   )r(   rS   r   rU   )r
   rS   r   r   r   ฺtest_init_dictฉ   s    zfrozendictTest.test_init_dictc             C   s6   d d l  m } |  j t | t j d d i   d  S)Nr   )rS   ฺar<   )r(   rS   r@   rE   ฺsixZ	iteritems)r
   rS   r   r   r   ฺ!test_init_other_raises_type_errorญ   s    z0frozendictTest.test_init_other_raises_type_errorc             C   s   |  j  d t |  j   d  S)Nr6   )r   ฺlenrU   )r
   r   r   r   ฺtest_lenฒ   s    zfrozendictTest.test_lenc             C   s#   |  j  t t |  j  t   d  S)N)r   r*   r   rU   r+   )r
   r   r   r   r   ต   s    zfrozendictTest.test_hashc             C   s0   |  j  d |  j j  |  j  d |  j j  d  S)Nr5   rT   )r   rU   r0   r1   )r
   r   r   r   r   ธ   s    z!frozendictTest.test_getattr_proxyc             C   s   |  j  t |  j j d  d  S)Nr?   )r@   rJ   rU   ฺ__getattr__)r
   r   r   r   ฺ#test_getattr_raises_attribute_errorผ   s    z2frozendictTest.test_getattr_raises_attribute_errorc             C   s    |  j  t |  j j d d  d  S)Nr?   r7   )r@   rJ   rU   rM   )r
   r   r   r   ฺtest_setattr_immutableฟ   s    z%frozendictTest.test_setattr_immutablec             C   s   |  j  d t |  j   d  S)Nzfrozendict(x=1, y='2'))r   r   rU   )r
   r   r   r   r   ย   s    zfrozendictTest.test_reprN)r   r   r   r   r   rV   rY   r[   r   r   r]   r^   r   r   r   r   r   rR   ข   s   rR   ฺ__main__)r   rK   ZunittestrX   Zjosepyr   ZTestCaser   r    r.   rR   r   ฺmainr   r   r   r   ฺ<module>   s   )+D$