o
    ¼>hé)  ã                   @   s   d Z ddlmZ ddlmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZ G dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZG dd„ deƒZdS )z+
Tests for L{twisted.words.im.ircsupport}.
é    )ÚStringTransport)ÚChatUIÚConversationÚGroupConversation)Ú
IRCAccountÚIRCProto)ÚOfflineError)ÚIRCTestCasec                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚStubConversationc                 C   ó   d S ©N© ©Úselfr   r   ú‚/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/words/test/test_ircsupport.pyÚshow   ó   zStubConversation.showc                 C   ó   || _ || _d S r   )ÚmessageÚmetadata)r   r   r   r   r   r   ÚshowMessage   ó   
zStubConversation.showMessageN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r
      s    r
   c                   @   s&   e Zd Zdd„ Zdd„ Zddd„ZdS )	ÚStubGroupConversationc                 C   r   r   )ÚtopicÚ
topicSetBy)r   r   Únicknamer   r   r   ÚsetTopic   r   zStubGroupConversation.setTopicc                 C   r   r   r   r   r   r   r   r      r   zStubGroupConversation.showNc                 C   s   || _ || _|| _ d S r   )r   Útext)r   Úsenderr    r   r   r   r   ÚshowGroupMessage    s   
z&StubGroupConversation.showGroupMessager   )r   r   r   r   r   r"   r   r   r   r   r      s    r   c                   @   s(   e Zd Zedfdd„Zedfdd„ZdS )Ú
StubChatUIr   c                 C   ó   t  | |||¡S r   ©r   ÚgetGroupConversation©r   ÚgroupÚClassÚ
stayHiddenr   r   r   ÚgetConversation'   ó   zStubChatUI.getConversationc                 C   r$   r   r%   r'   r   r   r   r&   *   r,   zStubChatUI.getGroupConversationN)r   r   r   r
   r+   r   r&   r   r   r   r   r#   &   s    r#   c                   @   s¦   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"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"d d!„ZdS )#ÚIRCProtoTestsz 
    Tests for L{IRCProto}.
    ÚreturnNc                 C   s2   t dddd ddƒ| _t| jtƒ d ƒ| _tƒ | _d S )NzSome accountFÚalicezexample.comi  )r   Úaccountr   r#   Úprotor   Ú	transportr   r   r   r   ÚsetUp3   s
   ÿzIRCProtoTests.setUpc                 C   s$   | j  | j¡ |  | j ¡ d¡ dS )z˜
        When L{IRCProto} is connected to a transport, it sends I{NICK} and
        I{USER} commands with the username from the account object.
        z1NICK alice
USER alice foo bar :Twisted-IM user
N)r1   ÚmakeConnectionr2   ÚassertEqualBufferValueÚvaluer   r   r   r   Ú
test_login:   s
   þzIRCProtoTests.test_loginc                 C   s,   d| j _| j | j¡ |  | j ¡ d¡ dS )z’
        If created with an account with a password, L{IRCProto} sends a
        I{PASS} command before the I{NICK} and I{USER} commands.
        Úsecretz>PASS secret
NICK alice
USER alice foo bar :Twisted-IM user
N)r0   Úpasswordr1   r4   r2   r5   r6   r   r   r   r   Útest_authenticateE   s   þzIRCProtoTests.test_authenticatec                 C   s0   ddg| j _| j | j¡ |  | j ¡ d¡ dS )z‰
        If created with an account with a list of channels, L{IRCProto}
        joins each of those channels after registering.
        ú#fooz#barzGNICK alice
USER alice foo bar :Twisted-IM user
JOIN #foo
JOIN #bar
N)r0   Úchannelsr1   r4   r2   r5   r6   r   r   r   r   Útest_channelsS   s   þzIRCProtoTests.test_channelsc                 C   s4   | j  | j¡ | j  d¡ |  d| j j d¡¡ dS )zž
        L{IRCProto} can interpret I{ISUPPORT} (I{005}) messages from the server
        and reflect their information in its C{supported} attribute.
        z3:irc.example.com 005 alice MODES=4 CHANLIMIT=#:20
é   ÚMODESN)r1   r4   r2   ÚdataReceivedÚassertEqualÚ	supportedÚ
getFeaturer   r   r   r   Útest_isupportb   s   zIRCProtoTests.test_isupportc                 C   sb   | j  | j¡ | j  d¡ | j  d¡ | j  d¡ | j  d¡ |  d| j j¡ |  d| j j¡ dS )zB
        IRC NICK command changes the nickname of a user.
        z:alice JOIN #group1
ú:alice1 JOIN #group1
z:alice1 NICK newnick
z:alice3 NICK newnick3
ÚnewnickÚalice1N©r1   r4   r2   r@   ÚassertInÚ	_ingroupsÚassertNotInr   r   r   r   Ú	test_nickk   s   zIRCProtoTests.test_nickc                 C   s’   | j  | j¡ | j  d¡ |  d| j jd ¡ |  d| j jd ¡ | j  d¡ | j  d¡ | j  d¡ |  d| j jd ¡ |  d| j jd ¡ dS )	zF
        IRC PART command removes a user from an IRC channel.
        rE   Úgroup1rG   Úgroup2z:alice PART #group1
z:alice1 PART #group1
z:alice1 PART #group2
NrH   r   r   r   r   Ú	test_partw   s   zIRCProtoTests.test_partc                 C   s˜   | j  | j¡ | j  d¡ |  d| j jd ¡ |  d| j jd ¡ | j  d¡ |  d| j jd ¡ | j  d¡ |  t| j jd ƒdk¡ | j  d	¡ d
S )zH
        IRC QUIT command removes a user from all IRC channels.
        rE   rM   rG   rN   z:alice1 JOIN #group3
Úgroup3z:alice1 QUIT
r   z:alice3 QUIT
N)	r1   r4   r2   r@   rI   rJ   rK   Ú
assertTrueÚlenr   r   r   r   Ú	test_quit…   s   zIRCProtoTests.test_quitc                 C   sR   | j  | j¡ | j  d¡ | j  d¡ | j  d¡}|  |jd¡ |  |jd¡ dS )zH
        IRC TOPIC command changes the topic of an IRC channel.
        rE   z :alice1 TOPIC #group1 newtopic
rM   ÚnewtopicrG   N)r1   r4   r2   r@   r&   rA   r   r   )r   ÚgroupConversationr   r   r   Ú
test_topic“   s   zIRCProtoTests.test_topicc                 C   óÂ   | j  | j¡ | j  d¡ | j j | j  d¡¡}|  |jd¡ | j  d¡ | j  	d¡}|  |j
d¡ | j  d¡ | j  d¡ | j  	d	¡}|  t|d
ƒ¡ | j j | j  d¡¡}|  t|dƒ¡ dS )zG
        PRIVMSG sends a private message to a user or channel.
        z#:alice1 PRIVMSG t2 test_message_1
rG   Útest_message_1z(:alice1 PRIVMSG #group1 test_message_2
rM   Útest_message_2r/   z$:alice PRIVMSG #foo test_message_3
Úfoor    r   N©r1   r4   r2   r@   Úchatr+   Ú	getPersonrA   r   r&   r    ÚsetNickÚassertFalseÚhasattr©r   ÚconversationrU   r   r   r   Útest_privmsgž   ó   zIRCProtoTests.test_privmsgc                 C   rW   )z3
        CTCP ACTION to a user or channel.
        z):alice1 PRIVMSG alice1 :ACTION smiles
rG   Úsmilesz*:alice1 PRIVMSG #group1 :ACTION laughs
rM   Úlaughsr/   z(:alice PRIVMSG #group1 :ACTION cries
rZ   r    r   Nr[   ra   r   r   r   Útest_action²   rd   zIRCProtoTests.test_actionc                 C   sž   | j  | j¡ | j  d¡ dgdgdgdgdgdœ}dg d¢i}|  || j j¡ |  || j j¡ | j  d¡ |  i | j j¡ | j  d¡}|  |d |j¡ dS )zØ
        RPL_NAMREPLY server response (353) lists all the users in a channel.
        RPL_ENDOFNAMES server response (363) is sent at the end of RPL_NAMREPLY
        to indicate that there are no more names.
        z>:example.com 353 z3p = #bnl :pSwede Dan- SkOyg @MrOp +MrPlus
Úbnl)úDan-ÚpSwedeÚSkOygÚMrOpÚMrPlus)rj   ri   rk   rl   rm   z1:example.com 366 alice #bnl :End of /NAMES list
N)	r1   r4   r2   r@   rA   rJ   Ú_namrepliesr&   Úmembers)r   ÚexpectedInGroupsÚexpectedNamRepliesrU   r   r   r   Útest_rplNamreplyÆ   s"   ÿûzIRCProtoTests.test_rplNamreplyc                 C   s2   | j  | j¡ | j  d¡ |  d| j jd ¡ dS )z[
        RPL_TOPIC server response (332) is sent when a channel's topic is changed
        z1:example.com 332 alice, #foo :Some random topic
zSome random topicrZ   N)r1   r4   r2   r@   rA   Ú_topicsr   r   r   r   Útest_rplTopicà   s   zIRCProtoTests.test_rplTopicc                 C   sŽ   | j  | j¡ | j  d¡}|  t|jd¡ | j |j_| j 	¡  | d¡ |  
| jj ¡ d¡ | j 	¡  | dddi¡ |  
| jj ¡ d¡ d	S )
z*
        L{IRCPerson.sendMessage}
        r/   úSome messageúSome message 2s   PRIVMSG alice :Some message 2
re   ÚstyleÚemotes    PRIVMSG alice :ACTION smiles
N)r1   r4   r2   r]   ÚassertRaisesr   ÚsendMessager0   ÚclientÚclearrA   ÚioÚgetvalue)r   Úpersonr   r   r   Útest_sendMessageè   s   


ÿ
ÿzIRCProtoTests.test_sendMessagec                 C   s”   | j  | j¡ | j j d| j ¡}|  t|jd¡ | j |j_	| j 
¡  | d¡ |  | jj ¡ d¡ | j 
¡  | dddi¡ |  | jj ¡ d¡ d	S )
z.
        L{IRCGroup.sendGroupMessage}
        r;   ru   rv   s   PRIVMSG #foo :Some message 2
re   rw   rx   s   PRIVMSG #foo :ACTION smiles
N)r1   r4   r2   r\   ÚgetGroupry   r   ÚsendGroupMessager0   r{   r|   rA   r}   r~   )r   r(   r   r   r   Útest_sendGroupMessageý   s   


ÿ
ÿz#IRCProtoTests.test_sendGroupMessage)r.   N)r   r   r   Ú__doc__r3   r7   r:   r=   rD   rL   rO   rS   rV   rc   rg   rr   rt   r€   rƒ   r   r   r   r   r-   .   s"    





	







r-   N)r„   Útwisted.internet.testingr   Útwisted.words.im.basechatr   r   r   Útwisted.words.im.ircsupportr   r   Útwisted.words.im.localsr   Útwisted.words.test.test_ircr	   r
   r   r#   r-   r   r   r   r   Ú<module>   s   	