o
    ¼>h	-  ã                   @   s¨   d Z ddlmZ ddlmZ ddlmZ dZdZdZ	dZ
G d	d
„ d
ejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZdS )z4
Tests for L{twisted.words.protocols.jabber.error}.
é    )Úunittest)Úerror)Údomishz$http://www.w3.org/XML/1998/namespaceú http://etherx.jabber.org/streamsz#urn:ietf:params:xml:ns:xmpp-streamsz#urn:ietf:params:xml:ns:xmpp-stanzasc                   @   s4   e Zd Zddd„Zddd„Zddd„Zdd	d
„ZdS )ÚBaseErrorTestsÚreturnNc                 C   s6   t  d¡}| ¡ }|  |jd¡ |  t|jƒd¡ dS )z<
        Test getting an element for a plain error.
        úfeature-not-implementedNé   )r   Ú	BaseErrorÚ
getElementÚassertIdenticalÚuriÚassertEqualÚlenÚchildren©ÚselfÚeÚelement© r   úƒ/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/words/test/test_jabbererror.pyÚtest_getElementPlain   s   
z#BaseErrorTests.test_getElementPlainc                 C   sT   t  dd¡}| ¡ }|  t|jƒd¡ |  t|jƒd¡ |  |j t	df¡d¡ dS )zC
        Test getting an element for an error with a text.
        r   Útexté   ÚlangN)
r   r
   r   r   r   r   Ústrr   ÚgetAttributeÚNS_XMLr   r   r   r   Útest_getElementText   s
   z"BaseErrorTests.test_getElementTextc                 C   sT   t  ddd¡}| ¡ }|  t|jƒd¡ |  t|jƒd¡ |  |jtdf d¡ dS )zP
        Test getting an element for an error with a text and language.
        r   r   Úen_USr   r   N)	r   r
   r   r   r   r   r   r   r   r   r   r   r   Útest_getElementTextLang'   s
   z&BaseErrorTests.test_getElementTextLangc                 C   sD   t  d¡}tjd|d}| ¡ }|  t|jƒd¡ |  |j|¡ dS )zV
        Test getting an element for an error with an app specific condition.
        )ÚtestnsÚmyerrorr   )ÚappConditionr   N)	r   ÚElementr   r
   r   r   r   r   r"   )r   Úacr   r   r   r   r   Útest_getElementAppCondition1   s
   
z*BaseErrorTests.test_getElementAppCondition©r   N)Ú__name__Ú
__module__Ú__qualname__r   r   r    r&   r   r   r   r   r      s
    

	


r   c                   @   s*   e Zd Zd	dd„Zd	dd„Zd	dd„ZdS )
ÚStreamErrorTestsr   Nc                 C   s$   t  d¡}| ¡ }|  |jt¡ dS )zK
        Test namespace of the element representation of an error.
        r   N)r   ÚStreamErrorr   r   r   Ú
NS_STREAMSr   r   r   r   r   =   s   
z%StreamErrorTests.test_getElementPlainc                 C   ó*   t  d¡}| ¡ }|  tt|dƒj¡ dS ©zR
        Test that the error condition element has the correct namespace.
        r   N)r   r,   r   r   ÚNS_XMPP_STREAMSÚgetattrr   r   r   r   r   Ú!test_getElementConditionNamespaceE   ó
   
ÿz2StreamErrorTests.test_getElementConditionNamespacec                 C   s(   t  dd¡}| ¡ }|  t|jj¡ dS )úM
        Test that the error text element has the correct namespace.
        r   r   N)r   r,   r   r   r0   r   r   r   r   r   r   Útest_getElementTextNamespaceO   s   z-StreamErrorTests.test_getElementTextNamespacer'   )r(   r)   r*   r   r2   r5   r   r   r   r   r+   <   s    


r+   c                   @   sL   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„Zddd„Z	dS )ÚStanzaErrorTestsz)
    Tests for L{error.StreamError}.
    r   Nc                 C   s*   t  d¡}|  d|j¡ |  d|j¡ dS )zI
        Remote Server Timeout should yield type wait, code 504.
        zremote-server-timeoutÚwaitÚ504N)r   ÚStanzaErrorr   ÚtypeÚcode)r   r   r   r   r   Útest_typeRemoteServerTimeout]   s   
z-StanzaErrorTests.test_typeRemoteServerTimeoutc                 C   sD   t  d¡}| ¡ }|  |jd¡ |  |d d¡ |  |d d¡ dS )zC
        Test getting an element for a plain stanza error.
        r   Nr:   Úcancelr;   Ú501©r   r9   r   r   r   r   r   r   r   r   e   s
   
z%StanzaErrorTests.test_getElementPlainc                 C   sF   t  dd¡}| ¡ }|  |jd¡ |  |d d¡ |  |d d¡ dS )zO
        Test getting an element for a stanza error with a given type.
        r   ÚauthNr:   r;   r>   r?   r   r   r   r   Útest_getElementTypeo   s
   z$StanzaErrorTests.test_getElementTypec                 C   r.   r/   )r   r9   r   r   ÚNS_XMPP_STANZASr1   r   r   r   r   r   r2   y   r3   z2StanzaErrorTests.test_getElementConditionNamespacec                 C   s*   t jddd}| ¡ }|  t|jj¡ dS )r4   r   r   )r   N)r   r9   r   r   rB   r   r   r   r   r   r   r5   ƒ   s   z-StanzaErrorTests.test_getElementTextNamespacec                 C   s®   t  d¡}d|d< d|d< d|d< t d¡}| |¡}|  ||¡ |  |d d¡ |  |d d¡ |  |d d	¡ |  |jjd
 jd¡ |  |jd d¡ |  	|j|j¡ dS )zë
        Test an error response is generated from a stanza.

        The addressing on the (new) response stanza should be reversed, an
        error child (with proper properties) added and the type set to
        C{'error'}.
        )zjabber:clientÚmessageÚchatr:   zuser1@example.comÚtozuser2@example.com/resourceÚfromúservice-unavailabler   r   r=   N)
r   r$   r   r9   Ú
toResponseÚassertNotIdenticalr   r   ÚnameÚassertNotEqual)r   Ústanzar   Úresponser   r   r   Útest_toResponse‹   s   


z StanzaErrorTests.test_toResponser'   )
r(   r)   r*   Ú__doc__r<   r   rA   r2   r5   rN   r   r   r   r   r6   X   s    







r6   c                   @   sV   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„Zddd„Z	ddd„Z
dS )ÚParseErrorTestsz)
    Tests for L{error._parseError}.
    r   Nc                 C   s   t  d¡| _d S )N)Nr   )r   r$   r   )r   r   r   r   ÚsetUp§   s   zParseErrorTests.setUpc                 C   s(   t  | j d¡}|  dddddœ|¡ dS )z:
        Test parsing of the empty error element.
        ÚerrornsN)Ú	conditionr   ÚtextLangr#   )r   Ú_parseErrorr   ©r   Úresultr   r   r   Ú
test_emptyª   s
   þzParseErrorTests.test_emptyc                 C   s.   | j  d¡ t  | j d¡}|  d|d ¡ dS )zD
        Test parsing of an error element with a condition.
        )rR   úbad-requestrR   rY   rS   N©r   Ú
addElementrU   r   rV   r   r   r   Útest_condition´   ó   zParseErrorTests.test_conditionc                 C   sH   | j  d¡}| d¡ t  | j d¡}|  d|d ¡ |  d|d ¡ dS )z?
        Test parsing of an error element with a text.
        ©rR   r   ÚtestrR   r   NrT   )r   r[   Ú
addContentrU   r   ©r   r   rW   r   r   r   Ú	test_text¼   s
   
zParseErrorTests.test_textc                 C   sD   | j  d¡}d|tdf< | d¡ t  | j d¡}|  d|d ¡ dS )zW
        Test parsing of an error element with a text with a defined language.
        r^   r   r   r_   rR   rT   N)r   r[   r   r`   rU   r   ra   r   r   r   Útest_textLangÆ   s
   
zParseErrorTests.test_textLangc                 C   s.   | j  d¡}t  | j d¡}|  ||d ¡ dS )zR
        Test parsing of an error element with an app specific condition.
        ©r!   rS   rR   r#   NrZ   ©r   rS   rW   r   r   r   Útest_appConditionÐ   r]   z!ParseErrorTests.test_appConditionc                 C   s:   | j  d¡ | j  d¡}t  | j d¡}|  ||d ¡ dS )zY
        Test parsing of an error element with multiple app specific conditions.
        rd   )r!   Ú
condition2rR   r#   NrZ   re   r   r   r   Útest_appConditionMultipleØ   s   z)ParseErrorTests.test_appConditionMultipler'   )r(   r)   r*   rO   rQ   rX   r\   rb   rc   rf   rh   r   r   r   r   rP   ¢   s    








rP   c                   @   s    e Zd Zddd„Zddd„ZdS )ÚExceptionFromStanzaTestsr   Nc                 C   s¦   t  d¡}| d¡}| d¡ | d¡}d|d< | tdf¡ | d¡}d	|d
< t |¡}|  |tj¡ |  d|j	¡ |  d|j
¡ |  ||j¡ |  |g|j¡ dS )aí  
        Test basic operations of exceptionFromStanza.

        Given a realistic stanza, check if a sane exception is returned.

        Using this stanza::

          <iq type='error'
              from='pubsub.shakespeare.lit'
              to='francisco@denmark.lit/barracks'
              id='subscriptions1'>
            <pubsub xmlns='http://jabber.org/protocol/pubsub'>
              <subscriptions/>
            </pubsub>
            <error type='cancel'>
              <feature-not-implemented
                xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
              <unsupported xmlns='http://jabber.org/protocol/pubsub#errors'
                           feature='retrieve-subscriptions'/>
            </error>
          </iq>
        ©NrL   )z!http://jabber.org/protocol/pubsubÚpubsubÚsubscriptionsr   r=   r:   r   )z(http://jabber.org/protocol/pubsub#errorsÚunsupportedzretrieve-subscriptionsÚfeatureN)r   r$   r[   rB   r   ÚexceptionFromStanzaÚassertIsInstancer9   r   rS   r:   r#   r   )r   rL   Úpr   ÚucrW   r   r   r   Ú
test_basicã   s   





z#ExceptionFromStanzaTests.test_basicc                 C   s„   t  d¡}|jddd}|jddd}d|d< t |¡}|  |tj¡ |  d	|j¡ |  d
|j	¡ |  d|j
¡ |  |g|j¡ dS )aÙ  
        Test legacy operations of exceptionFromStanza.

        Given a realistic stanza with only legacy (pre-XMPP) error information,
        check if a sane exception is returned.

        Using this stanza::

          <message type='error'
                   to='piers@pipetree.com/Home'
                   from='qmacro@jaber.org'>
            <body>Are you there?</body>
            <error code='502'>Unable to resolve hostname.</error>
          </message>
        rj   ÚbodyzAre you there?)Úcontentr   zUnable to resolve hostname.Ú502r;   rG   r7   N)r   r$   r[   r   ro   rp   r9   r   rS   r:   r   r   )r   rL   rq   r   rW   r   r   r   Útest_legacy  s   

z$ExceptionFromStanzaTests.test_legacyr'   )r(   r)   r*   rs   rw   r   r   r   r   ri   â   s    
(ri   c                   @   s   e Zd Zddd„ZdS )ÚExceptionFromStreamErrorTestsr   Nc                 C   sB   t  d¡}| tdf¡ t |¡}|  |tj¡ |  d|j	¡ dS )ac  
        Test basic operations of exceptionFromStreamError.

        Given a realistic stream error, check if a sane exception is returned.

        Using this error::

          <stream:error xmlns:stream='http://etherx.jabber.org/streams'>
            <xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>
          </stream:error>
        )r   r   zxml-not-well-formedN)
r   r$   r[   r0   r   ÚexceptionFromStreamErrorrp   r,   r   rS   )r   r   rW   r   r   r   rs   )  s
   

z(ExceptionFromStreamErrorTests.test_basicr'   )r(   r)   r*   rs   r   r   r   r   rx   (  s    rx   N)rO   Útwisted.trialr   Útwisted.words.protocols.jabberr   Útwisted.words.xishr   r   r-   r0   rB   ÚTestCaser   r+   r6   rP   ri   rx   r   r   r   r   Ú<module>   s   )J@F