Ϫf)dZddlmZddlmZmZmZddlmZm Z ddl m Z ddl m Z GddeZGd d eZGd d eZGd de Zy)z+ Tests for L{twisted.words.im.ircsupport}. )StringTransport)ChatUI ConversationGroupConversation) IRCAccountIRCProto) OfflineError) IRCTestCaseceZdZdZdZy)StubConversationcyNselfs D/usr/lib/python3/dist-packages/twisted/words/test/test_ircsupport.pyshowzStubConversation.show c ||_||_yr)messagemetadata)rrrs r showMessagezStubConversation.showMessages   rN)__name__ __module__ __qualname__rrrrrr r s  !rr c eZdZdZdZddZy)StubGroupConversationc ||_||_yr)topic topicSetBy)rr nicknames rsetTopiczStubGroupConversation.setTopics "rcyrrrs rrzStubGroupConversation.showrrNc.||_||_||_yr)rtext)rsenderr&rs rshowGroupMessagez&StubGroupConversation.showGroupMessage s     rr)rrrr#rr(rrrrrs# !rrc$eZdZedfdZedfdZy) StubChatUIrc2tj||||SrrgetGroupConversationrgroupClass stayHiddens rgetConversationzStubChatUI.getConversation'**4zJJrc2tj||||Srr,r.s rr-zStubChatUI.getGroupConversation*r3rN)rrrr r2rr-rrrr*r*&s+;K1FRSKrr*ceZdZdZddZddZddZddZddZddZ dd Z dd Z dd Z dd Z dd ZddZddZddZddZy) IRCProtoTestsz Tests for L{IRCProto}. Nctdddddd|_t|jtd|_t |_y)Nz Some accountFalicez example.comi )raccountrr*protor transportrs rsetUpzIRCProtoTests.setUp3s=! E7D-  dllJL$? (*rc|jj|j|j|jj dy)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)r:makeConnectionr;assertEqualBufferValuevaluers r test_loginzIRCProtoTests.test_login:s; !!$..1 ## NN " F rcd|j_|jj|j|j |jj dy)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)r9passwordr:r>r;r?r@rs rtest_authenticatezIRCProtoTests.test_authenticateEsI !)  !!$..1 ## NN " 6 rcddg|j_|jj|j|j |jj dy)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)r9channelsr:r>r;r?r@rs r test_channelszIRCProtoTests.test_channelsSsN "( 0  !!$..1 ## NN "  rc|jj|j|jjd|j d|jj j dy)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)r:r>r; dataReceived assertEqual supported getFeaturers r test_isupportzIRCProtoTests.test_isupportbsR !!$..1  WX DJJ00;;GDErc|jj|j|jjd|jjd|jjd|jjd|j d|jj |j d|jj y)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 newnickalice1Nr:r>r;rMassertIn _ingroups assertNotInrs r test_nickzIRCProtoTests.test_nickks !!$..1  9:  :;  :;  ;< i!5!56 4::#7#78rcn|jj|j|jjd|j d|jj d|j d|jj d|jjd|jjd|jjd|j d|jj d|j d|jj dy) zF IRC PART command removes a user from an IRC channel. rSgroup1rUgroup2z:alice PART #group1 z:alice1 PART #group1 z:alice1 PART #group2 NrVrs r test_partzIRCProtoTests.test_partws !!$..1  :; h 4 4X >? 4::#7#7#AB  9:  :;  :; 4::#7#7#AB 4::#7#7#ABrc|jj|j|jjd|j d|jj d|j d|jj d|jjd|j d|jj d|jjd|jt|jj ddk(|jjd y ) zH IRC QUIT command removes a user from all IRC channels. rSr\rUr]z:alice1 JOIN #group3 group3z:alice1 QUIT rz:alice3 QUIT N) r:r>r;rMrWrXrY assertTruelenrs r test_quitzIRCProtoTests.test_quits !!$..1  :; h 4 4X >? 4::#7#7#AB  :; h 4 4X >?  23 DJJ00:;q@A  23rc`|jj|j|jjd|jjd|jj d}|j |j d|j |jdy)zH IRC TOPIC command changes the topic of an IRC channel. rSz :alice1 TOPIC #group1 newtopic r\newtopicrUN)r:r>r;rMr-rNr r!)rgroupConversations r test_topiczIRCProtoTests.test_topics !!$..1  :;  DE JJ;;HE *00*= *55x@rcf|jj|j|jjd|jjj |jj d}|j|jd|jjd|jjd}|j|jd|jjd|jjd|jjd }|jt|d |jjj |jj d}|jt|d y ) zG PRIVMSG sends a private message to a user or channel. z#:alice1 PRIVMSG t2 test_message_1 rUtest_message_1z(:alice1 PRIVMSG #group1 test_message_2 r\test_message_2r8z$:alice PRIVMSG #foo test_message_3 foor&rNr:r>r;rMchatr2 getPersonrNrr-r&setNick assertFalsehasattrr conversationrfs r test_privmsgzIRCProtoTests.test_privmsgs7 !!$..1  GHzz66tzz7K7KH7UV  --/?@  LM JJ;;HE *//1AB 7#  HI JJ;;EB !2F;<zz66tzz7K7KG7TU  y9:rcf|jj|j|jjd|jjj |jj d}|j|jd|jjd|jjd}|j|jd|jjd|jjd|jjd }|jt|d |jjj |jj d}|jt|d y ) z3 CTCP ACTION to a user or channel. z):alice1 PRIVMSG alice1 :ACTION smiles rUsmilesz*:alice1 PRIVMSG #group1 :ACTION laughs r\laughsr8z(:alice PRIVMSG #group1 :ACTION cries rkr&rNrlrrs r test_actionzIRCProtoTests.test_actions5 !!$..1  QRzz66tzz7K7KH7UV  --x8  RS JJ;;HE *//: 7#  PQ JJ;;EB !2F;<zz66tzz7K7KG7TU  y9:rc8|jj|j|jjddgdgdgdgdgd}dgdi}|j ||jj |j ||jj |jjd|j i|jj |jjd}|j |d|jy)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-pSwedeSkOygMrOpMrPlus)r|r{r}r~rz1:example.com 366 alice #bnl :End of /NAMES list N) r:r>r;rMrNrX _namrepliesr-members)rexpectedInGroupsexpectedNamRepliesrfs rtest_rplNamreplyzIRCProtoTests.test_rplNamreplys !!$..1  N GgWGg  $%RS )4::+?+?@ +TZZ-C-CD  UV TZZ334 JJ;;EB +E24E4M4MNrc|jj|j|jjd|j d|jj dy)z[ RPL_TOPIC server response (332) is sent when a channel's topic is changed z1:example.com 332 alice, #foo :Some random topic zSome random topicrkN)r:r>r;rMrN_topicsrs r test_rplTopiczIRCProtoTests.test_rplTopicsM !!$..1  UV ,djj.@.@.GHrc~|jj|j|jjd}|j t |j d|j|j_|jj|j d|j|jjjd|jj|j dddi|j|jjjdy ) z* L{IRCPerson.sendMessage} r8 Some messageSome message 2sPRIVMSG alice :Some message 2 rvstyleemotes PRIVMSG alice :ACTION smiles N) r:r>r;rn assertRaisesr sendMessager9clientclearrNiogetvalue)rpersons rtest_sendMessagezIRCProtoTests.test_sendMessages !!$..1%%g. ,(:(:NK $  +,  NN   & & (*N  8gw%78  NN   & & (*U rc|jj|j|jjj d|j}|j t |jd|j|j_ |jj|jd|j|jjjd|jj|jdddi|j|jjjdy ) z. L{IRCGroup.sendGroupMessage} rGrrsPRIVMSG #foo :Some message 2 rvrrsPRIVMSG #foo :ACTION smiles N)r:r>r;rmgetGrouprr sendGroupMessager9rrrNrr)rr/s rtest_sendGroupMessagez#IRCProtoTests.test_sendGroupMessages !!$..1 ((< ,(>(>O#zz   /0  NN   & & (*M   x'7);<  NN   & & (*T r)returnN)rrr__doc__r<rArErIrQrZr^rcrgrtrxrrrrrrrr6r6.sW+      F 9 C 4 A;(;(O4I * rr6N)rtwisted.internet.testingrtwisted.words.im.basechatrrrtwisted.words.im.ircsupportrrtwisted.words.im.localsr twisted.words.test.test_ircr r rr*r6rrrrsS5MM<03!|! !- !KKb Kb r