
    Yf	-                     "   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
ej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G 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                   .    e Zd ZddZddZddZddZdS )BaseErrorTestsreturnNc                     t          j        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elements      U/var/www/html/env/lib/python3.11/site-packages/twisted/words/test/test_jabbererror.pytest_getElementPlainz#BaseErrorTests.test_getElementPlain   s`     O566,,..W[$///W-..22222    c                 b   t          j        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   s      r   test_getElementTextz"BaseErrorTests.test_getElementText   s     O5v>>,,..W-..222W\**F33322FF3CDDdKKKKKr   c                 J   t          j        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   s      r   test_getElementTextLangz&BaseErrorTests.test_getElementTextLang'   s     O5vwGG,,..W-..222W\**F333vv&67AAAAAr   c                    t          j        d          }t          j        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   s       r   test_getElementAppConditionz*BaseErrorTests.test_getElementAppCondition1   su     ^122O5BGGG,,..W-..222"-----r   r	   N)__name__
__module____qualname__r   r"   r%   r,    r   r   r   r      sl        3 3 3 3L L L LB B B B. . . . . .r   r   c                   &    e Zd ZddZddZddZdS )StreamErrorTestsr	   Nc                     t          j        d          }|                                }|                     |j        t
                     dS )zK
        Test namespace of the element representation of an error.
        r   N)r   StreamErrorr   r   r   
NS_STREAMSr   s      r   r   z%StreamErrorTests.test_getElementPlain=   s@     788,,..j11111r   c                     t          j        d          }|                                }|                     t          t          |d          j                   dS zR
        Test that the error condition element has the correct namespace.
        r   N)r   r5   r   r   NS_XMPP_STREAMSgetattrr   r   s      r   !test_getElementConditionNamespacez2StreamErrorTests.test_getElementConditionNamespaceE   W     788,,..WW.GHHL	
 	
 	
 	
 	
r   c                     t          j        dd          }|                                }|                     t          |j        j                   dS )M
        Test that the error text element has the correct namespace.
        r   r   N)r   r5   r   r   r9   r   r   r   s      r   test_getElementTextNamespacez-StreamErrorTests.test_getElementTextNamespaceO   sE     7@@,,..',*:;;;;;r   r-   )r.   r/   r0   r   r;   r?   r1   r   r   r3   r3   <   sP        2 2 2 2
 
 
 
< < < < < <r   r3   c                   B    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S )StanzaErrorTestsz)
    Tests for L{error.StreamError}.
    r	   Nc                     t          j        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   s     r   test_typeRemoteServerTimeoutz-StanzaErrorTests.test_typeRemoteServerTimeout]   sK     566((('''''r   c                     t          j        d          }|                                }|                     |j        d           |                     |d         d           |                     |d         d           dS )zC
        Test getting an element for a plain stanza error.
        r   NrF   cancelrG   501r   rE   r   r   r   r   s      r   r   z%StanzaErrorTests.test_getElementPlaine   st     788,,..d+++(333%00000r   c                     t          j        dd          }|                                }|                     |j        d           |                     |d         d           |                     |d         d           dS )zO
        Test getting an element for a stanza error with a given type.
        r   authNrF   rG   rK   rL   r   s      r   test_getElementTypez$StanzaErrorTests.test_getElementTypeo   sv     7@@,,..d+++&111%00000r   c                     t          j        d          }|                                }|                     t          t          |d          j                   dS r8   )r   rE   r   r   NS_XMPP_STANZASr:   r   r   s      r   r;   z2StanzaErrorTests.test_getElementConditionNamespacey   r<   r   c                     t          j        dd          }|                                }|                     t          |j        j                   dS )r>   r   r   )r   N)r   rE   r   r   rQ   r   r   r   s      r   r?   z-StanzaErrorTests.test_getElementTextNamespace   sH     7fEEE,,..',*:;;;;;r   c                 J   t          j        d          }d|d<   d|d<   d|d<   t          j        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chatrF   zuser1@example.comtozuser2@example.com/resourcefromservice-unavailabler   r   rJ   N)
r   r*   r   rE   
toResponseassertNotIdenticalr   r   nameassertNotEqual)r   stanzar   responses       r   test_toResponsez StanzaErrorTests.test_toResponse   s     <==v*t5v344<<''&111&)+>???$)EFFF&)7333038:OPPP/:::FOX->?????r   r-   )
r.   r/   r0   __doc__rH   r   rO   r;   r?   r_   r1   r   r   rA   rA   X   s         ( ( ( (1 1 1 11 1 1 1
 
 
 
< < < <@ @ @ @ @ @r   rA   c                   J    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 )ParseErrorTestsz)
    Tests for L{error._parseError}.
    r	   Nc                 8    t          j        d          | _        d S )N)Nr   )r   r*   r   )r   s    r   setUpzParseErrorTests.setUp   s    ^O44


r   c                 p    t          j        | j         d          }|                     ddddd|           dS )z:
        Test parsing of the empty error element.
        errornsN)	conditionr   textLangr)   )r   _parseErrorr   r   results     r   
test_emptyzParseErrorTests.test_empty   sM     "4:y99$PTUU	
 	
 	
 	
 	
r   c                     | j                             d           t          j        | j         d          }|                     d|d                    dS )zD
        Test parsing of an error element with a condition.
        )rf   bad-requestrf   rn   rg   Nr   
addElementri   r   rj   s     r   test_conditionzParseErrorTests.test_condition   sP     	
8999"4:y99{(;<<<<<r   c                    | j                             d          }|                    d           t          j        | j         d          }|                     d|d                    |                     d|d                    dS )z?
        Test parsing of an error element with a text.
        rf   r   testrf   r   Nrh   )r   rp   
addContentri   r   r   r   rk   s      r   	test_textzParseErrorTests.test_text   s{     z$$%899"4:y99000vj122222r   c                     | j                             d          }d|t          df<   |                    d           t          j        | j         d          }|                     d|d                    dS )zW
        Test parsing of an error element with a text with a defined language.
        rs   r$   r   rt   rf   rh   N)r   rp   r!   ru   ri   r   rv   s      r   test_textLangzParseErrorTests.test_textLang   so     z$$%899&VV^"4:y99&"455555r   c                     | j                             d          }t          j        | j         d          }|                     ||d                    dS )zR
        Test parsing of an error element with an app specific condition.
        r'   rg   rf   r)   Nro   r   rg   rk   s      r   test_appConditionz!ParseErrorTests.test_appCondition   sO     J))*ABB	"4:y99F>$:;;;;;r   c                     | j                             d           | j                             d          }t          j        | j         d          }|                     ||d                    dS )zY
        Test parsing of an error element with multiple app specific conditions.
        r{   )r'   
condition2rf   r)   Nro   r|   s      r   test_appConditionMultiplez)ParseErrorTests.test_appConditionMultiple   sf     	
5666J))*BCC	"4:y99F>$:;;;;;r   r-   )r.   r/   r0   r`   rd   rl   rq   rw   ry   r}   r   r1   r   r   rb   rb      s         5 5 5 5
 
 
 
= = = =3 3 3 36 6 6 6< < < << < < < < <r   rb   c                       e Zd ZddZddZdS )ExceptionFromStanzaTestsr	   Nc                 d   t          j        d          }|                    d          }|                    d           |                    d          }d|d<   |                    t          df           |                    d          }d	|d
<   t	          j        |          }|                     |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>
        Nr]   )z!http://jabber.org/protocol/pubsubpubsubsubscriptionsr   rJ   rF   r   )z(http://jabber.org/protocol/pubsub#errorsunsupportedzretrieve-subscriptionsfeatureN)r   r*   rp   rQ   r   exceptionFromStanzaassertIsInstancerE   r   rg   rF   r)   r   )r   r]   pr   ucrk   s         r   
test_basicz#ExceptionFromStanzaTests.test_basic   s   0  011MNN	_%%%g&&&		o'@ABBB\\UVV09*622fe&78882F4DEEE6;///V0111!fo.....r   c                    t          j        d          }|                    dd          }|                    dd          }d|d<   t          j        |          }|                     |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>
        r   bodyzAre you there?)contentr   zUnable to resolve hostname.502rG   rX   rC   N)r   r*   rp   r   r   r   rE   r   rg   rF   r   r   )r   r]   r   r   rk   s        r   test_legacyz$ExceptionFromStanzaTests.test_legacy  s       011f.>??g/LMM&	*622fe&7888.0@AAA---6DDD!fo.....r   r-   )r.   r/   r0   r   r   r1   r   r   r   r      s=        &/ &/ &/ &/P/ / / / / /r   r   c                       e Zd ZddZdS )ExceptionFromStreamErrorTestsr	   Nc                    t          j        d          }|                    t          df           t	          j        |          }|                     |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*   rp   r9   r   exceptionFromStreamErrorr   r5   r   rg   )r   r   rk   s      r   r   z(ExceptionFromStreamErrorTests.test_basic)  su     NHII	o'<=>>>/22fe&7888.0@AAAAAr   r-   )r.   r/   r0   r   r1   r   r   r   r   (  s.        B B B B B Br   r   N)r`   twisted.trialr   twisted.words.protocols.jabberr   twisted.words.xishr   r!   r6   r9   rQ   TestCaser   r3   rA   rb   r   r   r1   r   r   <module>r      s   
 # " " " " " 0 0 0 0 0 0 % % % % % %	//
77&. &. &. &. &.X& &. &. &.R< < < < <x( < < <8G@ G@ G@ G@ G@x( G@ G@ G@T=< =< =< =< =<h' =< =< =<@C/ C/ C/ C/ C/x0 C/ C/ C/LB B B B BH$5 B B B B Br   