
    Vh	-                     8   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y)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y)BaseErrorTestsNc                     t        j                  d      }|j                         }| j                  |j                  d       | j                  t        |j                        d       y)z<
        Test getting an element for a plain error.
        feature-not-implementedN   )r   	BaseError
getElementassertIdenticaluriassertEquallenchildrenselfeelements      S/home/dcms/DCMS/lib/python3.12/site-packages/twisted/words/test/test_jabbererror.pytest_getElementPlainz#BaseErrorTests.test_getElementPlain   sM     OO56,,.W[[$/W--.2    c                 F   t        j                  dd      }|j                         }| j                  t	        |j
                        d       | j                  t        |j                        d       | j                  |j                  j                  t        df      d       y)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   sx     OO5v>,,.W--.2W\\*F322FF3CDdKr   c                 0   t        j                  ddd      }|j                         }| j                  t	        |j
                        d       | j                  t        |j                        d       | j                  |j                  t        df   d       y)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'   st     OO5vwG,,.W--.2W\\*F3vv&67Ar   c                     t        j                  d      }t        j                  d|      }|j	                         }| j                  t        |j                        d       | j                  |j                  |       y)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   s^     ^^12OO5BG,,.W--.2"-r   returnN)__name__
__module____qualname__r   r!   r$   r+    r   r   r   r      s    3LB.r   r   c                   $    e Zd ZddZddZddZy)StreamErrorTestsNc                     t        j                  d      }|j                         }| j                  |j                  t
               y)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=   s4     78,,.j1r   c                     t        j                  d      }|j                         }| j                  t        t        |d      j                         y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   A     78,,.WW.GHLL	
r   c                     t        j                  dd      }|j                         }| j                  t        |j
                  j                         y)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   s<     7@,,.',,*:*:;r   r,   )r.   r/   r0   r   r;   r?   r1   r   r   r3   r3   <   s    2
<r   r3   c                   @    e Zd ZdZd	dZd	dZd	dZd	dZd	dZd	dZ	y)
StanzaErrorTestsz)
    Tests for L{error.StreamError}.
    Nc                     t        j                  d      }| j                  d|j                         | j                  d|j                         y)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]   s=     56('r   c                     t        j                  d      }|j                         }| j                  |j                  d       | j                  |d   d       | j                  |d   d       y)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   s\     78,,.d+(3%0r   c                     t        j                  dd      }|j                         }| j                  |j                  d       | j                  |d   d       | j                  |d   d       y)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   s^     7@,,.d+&1%0r   c                     t        j                  d      }|j                         }| j                  t        t        |d      j                         yr8   )r   rE   r   r   NS_XMPP_STANZASr:   r   r   s      r   r;   z2StanzaErrorTests.test_getElementConditionNamespacey   r<   r   c                     t        j                  dd      }|j                         }| j                  t        |j
                  j                         y)r>   r
   r   )r   N)r   rE   r   r   rQ   r   r   r   s      r   r?   z-StanzaErrorTests.test_getElementTextNamespace   s<     7fE,,.',,*:*:;r   c                 *   t        j                  d      }d|d<   d|d<   d|d<   t        j                  d      }|j	                  |      }| j                  ||       | j                  |d   d       | j                  |d   d       | j                  |d   d	       | j                  |j                  j                  d
   j                  d       | j                  |j                  d   d       | j                  |j                  |j                         y)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<<'&1&)+>?$)EF&)7300388:OP/:FOOX->->?r   r,   )
r.   r/   r0   __doc__rH   r   rO   r;   r?   r_   r1   r   r   rA   rA   X   s&    (11
<@r   rA   c                   H    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
y)ParseErrorTestsz)
    Tests for L{error._parseError}.
    Nc                 8    t        j                  d      | _        y )N)Nr   )r   r)   r   )r   s    r   setUpzParseErrorTests.setUp   s    ^^O4
r   c                 r    t        j                  | j                   d      }| j                  ddddd|       y)z:
        Test parsing of the empty error element.
        errornsN)	conditionr   textLangr(   )r   _parseErrorr   r   results     r   
test_emptyzParseErrorTests.test_empty   s8     ""4::y9$PTU	
r   c                     | j                   j                  d       t        j                  | j                   d      }| j                  d|d          y)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   sB     	

89""4::y9{(;<r   c                     | j                   j                  d      }|j                  d       t        j                  | j                   d      }| j	                  d|d          | j	                  d|d          y)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   sd     zz$$%89""4::y90vj12r   c                     | j                   j                  d      }d|t        df<   |j                  d       t        j                  | j                   d      }| j                  d|d          y)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   s^     zz$$%89&VV^""4::y9&"45r   c                     | j                   j                  d      }t        j                  | j                   d      }| j                  ||d          y)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   sD     JJ))*AB	""4::y9F>$:;r   c                     | j                   j                  d       | j                   j                  d      }t        j                  | j                   d      }| j                  ||d          y)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   sW     	

56JJ))*BC	""4::y9F>$:;r   r,   )r.   r/   r0   r`   rd   rl   rq   rw   ry   r}   r   r1   r   r   rb   rb      s*    5
=36<<r   rb   c                       e Zd ZddZddZy)ExceptionFromStanzaTestsNc                 D   t        j                  d      }|j                  d      }|j                  d       |j                  d      }d|d<   |j                  t        df       |j                  d      }d	|d
<   t	        j
                  |      }| j                  |t        j                         | j                  d|j                         | j                  d|j                         | j                  ||j                         | j                  |g|j                         y)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MN	_%g&&		o'@AB\\UV09**62fe&7&782F4D4DE6;;/V001!foo.r   c                    t        j                  d      }|j                  dd      }|j                  dd      }d|d<   t        j                  |      }| j                  |t        j                         | j                  d	|j                         | j                  d
|j                         | j                  d|j                         | j                  |g|j                         y)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f.>?g/LM&	**62fe&7&78.0@0@A-6D!foo.r   r,   )r.   r/   r0   r   r   r1   r   r   r   r      s    &/P/r   r   c                       e Zd ZddZy)ExceptionFromStreamErrorTestsNc                     t        j                  d      }|j                  t        df       t	        j
                  |      }| j                  |t        j                         | j                  d|j                         y)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)  sb     NNHI	o'<=>//2fe&7&78.0@0@Ar   r,   )r.   r/   r0   r   r1   r   r   r   r   (  s    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 %	//
77&.X&& &.R<x(( <8G@x(( G@T=<h'' =<@C/x00 C/LBH$5$5 Br   