3
,sY*                 @   sb   d Z ddlmZ ddlmZ ddlmZ G dd dejZG dd dejZ	G d	d
 d
ejZ
dS )z2
Tests for L{twisted.words.protocols.jabber.jid}.
    )unicode)unittest)jidc               @   sD   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S )JIDParsingTestsc             C   s   | j tjdd | j tjdd | j tjdd | j tjdd | j tjdd | j tjdd | j tjdd | j tjdd | j tjdd | j tjdd dS )z/
        Test different forms of JIDs.
        zuser@host/resourceuserhostresourcez	user@hostNzhost/resourcezfoo/bar@bazfoobar@bazzboo@foo/bar@bazboozboo@foo/bar/bazbar/bazzboo/foo@bar@bazfoo@bar@bazzboo/foo/barfoo/barzboo//foo/foo)r   r   r   )r   r   N)Nr   N)Nr   r   )Nr	   r
   )r   r	   r
   )r   r	   r   )Nr   r   )Nr   r   )Nr   r   )assertEqualr   parse)self r   C/usr/lib/python3/dist-packages/twisted/words/test/test_jabberjid.py
test_parse   s(    zJIDParsingTests.test_parsec             C   s   | j tjtjd dS )z3
        Test for failure on no host part.
        zuser@N)assertRaisesr   InvalidFormatr   )r   r   r   r   test_noHost*   s    zJIDParsingTests.test_noHostc             C   s   | j tjtjd dS )z
        Test for failure on double @ signs.

        This should fail because @ is not a valid character for the host
        part of the JID.
        z
user@@hostN)r   r   r   r   )r   r   r   r   test_doubleAt0   s    zJIDParsingTests.test_doubleAtc             C   s   | j tjtjd dS )z
        Test for failure on two @ signs.

        This should fail because @ is not a valid character for the host
        part of the JID.
        zuser@host@hostN)r   r   r   r   )r   r   r   r   test_multipleAt9   s    zJIDParsingTests.test_multipleAtc             C   s   | j tjdddd dS )z@
        Test case mapping of the user part of the JID.
        ZUsErr   r   r   N)r   r   r   )r   r   prep)r   r   r   r   test_prepCaseMapUserE   s    z$JIDParsingTests.test_prepCaseMapUserc             C   s   | j tjdddd dS )z@
        Test case mapping of the host part of the JID.
        r   hoSTr   r   N)r   r   r   )r   r   r   )r   r   r   r   test_prepCaseMapHostL   s    z$JIDParsingTests.test_prepCaseMapHostc             C   s0   | j tjdddd | jtjdddd dS )	zH
        Test no case mapping of the resourcce part of the JID.
        r   r   r   r   ZResourceN)r   r   r   )r   r   r   )r   r   r   assertNotEqual)r   r   r   r   test_prepNoCaseMapResourceS   s    z*JIDParsingTests.test_prepNoCaseMapResourceN)
__name__
__module____qualname__r   r   r   r   r   r   r    r   r   r   r   r      s   	r   c               @   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#S )$JIDTestsc             C   s   | j ttj dS )zC
        Test that using no arguments raises an exception.
        N)r   RuntimeErrorr   JID)r   r   r   r   test_noneArguments^   s    zJIDTests.test_noneArgumentsc             C   s8   t jd}| j|jd | j|jd | j|jd dS )zI
        Test that the attributes correspond with the JID parts.
        zuser@host/resourcer   r   r   N)r   r&   r   r   r   r   )r   jr   r   r   test_attributesd   s    
zJIDTests.test_attributesc             C   s   t jd}| jd|j  dS )z6
        Test the extraction of the bare JID.
        zuser@host/resourcez	user@hostN)r   r&   r   userhost)r   r(   r   r   r   test_userhostm   s    
zJIDTests.test_userhostc             C   s   t jd}| jd|j  dS )zU
        Test the extraction of the bare JID of the full form host/resource.
        zhost/resourcer   N)r   r&   r   r*   )r   r(   r   r   r   test_userhostOnlyHostt   s    
zJIDTests.test_userhostOnlyHostc             C   s(   t jd}t jd}| j||j  dS )z<
        Test getting a JID object of the bare JID.
        zuser@host/resourcez	user@hostN)r   r&   	internJIDassertIdenticaluserhostJID)r   j1j2r   r   r   test_userhostJID{   s    

zJIDTests.test_userhostJIDc             C   s   t jd}| j||j  dS )zW
        Test getting a JID object of the bare JID when there was no resource.
        z	user@hostN)r   r&   r.   r/   )r   r(   r   r   r   test_userhostJIDNoResource   s    
z#JIDTests.test_userhostJIDNoResourcec             C   s    t jdd}| jd|j  dS )zW
        Test giving a string representation of the JID with only a host part.
        Nr   )tuple)Nr   N)r   r&   r   full)r   r(   r   r   r   test_fullHost   s    zJIDTests.test_fullHostc             C   s    t jdd}| jd|j  dS )zU
        Test giving a string representation of the JID with host, resource.
        Nr   r   )r4   zhost/resource)Nr   r   )r   r&   r   r5   )r   r(   r   r   r   test_fullHostResource   s    zJIDTests.test_fullHostResourcec             C   s    t jdd}| jd|j  dS )zQ
        Test giving a string representation of the JID with user, host.
        r   r   N)r4   z	user@host)r   r   N)r   r&   r   r5   )r   r(   r   r   r   test_fullUserHost   s    zJIDTests.test_fullUserHostc             C   s    t jdd}| jd|j  dS )zA
        Test giving a string representation of the JID.
        r   r   r   )r4   zuser@host/resourceN)r   r   r   )r   r&   r   r5   )r   r(   r   r   r   test_fullAll   s    zJIDTests.test_fullAllc             C   s0   t jd}t jd}| j|| | j|| dS )z$
        Test JID equality.
        zuser@host/resourceN)r   r&   ZassertNotIdenticalr   )r   r0   r1   r   r   r   test_equality   s    

zJIDTests.test_equalityc             C   s   t jd}| j|dk dS )z$
        Test JID equality.
        zuser@host/resourceN)r   r&   ZassertFalse)r   r(   r   r   r   test_equalityWithNonJIDs   s    
z!JIDTests.test_equalityWithNonJIDsc             C   s$   t jd}t jd}| j|| dS )z&
        Test JID inequality.
        zuser1@host/resourcezuser2@host/resourceN)r   r&   r   )r   r0   r1   r   r   r   test_inequality   s    

zJIDTests.test_inequalityc             C   s   t jd}| j|d dS )z$
        Test JID equality.
        zuser@host/resourceN)r   r&   r   )r   r(   r   r   r   test_inequalityWithNonJIDs   s    
z#JIDTests.test_inequalityWithNonJIDsc             C   s,   t jd}t jd}| jt|t| dS )z'
        Test JID hashability.
        zuser@host/resourceN)r   r&   r   hash)r   r0   r1   r   r   r   test_hashable   s    

zJIDTests.test_hashablec             C   s    t jdd}| jdt| dS )z6
        Test unicode representation of JIDs.
        r   r   r   )r4   zuser@host/resourceN)r   r   r   )r   r&   r   r   )r   r(   r   r   r   test_unicode   s    zJIDTests.test_unicodec             C   s(   t jdd}| jdtd t| dS )	z5
        Test representation of JID objects.
        r   r   r   )r4   zJID(%s)zuser@host/resourceN)r   r   r   )r   r&   r   repr)r   r(   r   r   r   	test_repr   s    zJIDTests.test_reprN)r!   r"   r#   r'   r)   r+   r,   r2   r3   r6   r7   r8   r9   r:   r;   r<   r=   r?   r@   rB   r   r   r   r   r$   \   s"   		r$   c               @   s   e Zd Zdd ZdS )InternJIDTestsc             C   s$   t jd}t jd}| j|| dS )zD
        Test that two interned JIDs yield the same object.
        z	user@hostN)r   r-   r.   )r   r0   r1   r   r   r   test_identity   s    

zInternJIDTests.test_identityN)r!   r"   r#   rD   r   r   r   r   rC      s   rC   N)__doc__Ztwisted.python.compatr   Ztwisted.trialr   Ztwisted.words.protocols.jabberr   ZTestCaser   r$   rC   r   r   r   r   <module>   s   O