From d75ffcb2f5c86650200212db23c24456854c0bc7 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 21 Dec 2015 15:45:05 +0100 Subject: [PATCH] Split testJoin into testJoinAllMessages and testJoinNamreply, and add testPartNotInChannel --- irctest/controllers/limnoria.py | 3 - .../server_tests/test_channel_operations.py | 72 +++++++++++++++---- 2 files changed, 60 insertions(+), 15 deletions(-) diff --git a/irctest/controllers/limnoria.py b/irctest/controllers/limnoria.py index 464e89c..cedceeb 100644 --- a/irctest/controllers/limnoria.py +++ b/irctest/controllers/limnoria.py @@ -5,9 +5,6 @@ from irctest import authentication from irctest.basecontrollers import BaseClientController, DirectoryBasedController TEMPLATE_CONFIG = """ -supybot.plugins: Authentication -supybot.plugins.Authentication: True -supybot.plugins.Authentication.public: True supybot.directories.conf: {directory}/conf supybot.directories.data: {directory}/data supybot.directories.migrations: {directory}/migrations diff --git a/irctest/server_tests/test_channel_operations.py b/irctest/server_tests/test_channel_operations.py index 2a6ff0d..735bfbf 100644 --- a/irctest/server_tests/test_channel_operations.py +++ b/irctest/server_tests/test_channel_operations.py @@ -4,10 +4,11 @@ Section 3.2 of RFC 2812 """ from irctest import cases +from irctest.irc_utils import ambiguities from irctest.irc_utils.message_parser import Message class JoinTestCase(cases.BaseServerTestCase): - def testJoin(self): + def testJoinAllMessages(self): """“If a JOIN is successful, the user receives a JOIN message as confirmation and is then sent the channel's topic (using RPL_TOPIC) and the list of users who are on the channel (using RPL_NAMREPLY), which @@ -22,21 +23,68 @@ class JoinTestCase(cases.BaseServerTestCase): self.connectClient('foo') self.sendLine(1, 'JOIN #chan') m = self.getMessage(1) - self.assertMessageEqual(m, command='JOIN', params=['#chan']) - m = self.getMessage(1) - got_topic = False - if m.command in ('331', '332'): # RPL_NOTOPIC, RPL_TOPIC - got_topic = True - m = self.getMessage(1) - m = self.assertMessageEqual(m, command='353') # RPL_NAMREPLY - m = self.getMessage(1) - m = self.assertMessageEqual(m, command='366') # RPL_ENDOFNAMES + try: + self.assertMessageEqual(m, command='JOIN', params=['#chan']) + except AssertionError: + pass else: - m = self.assertMessageEqual(m, command='353') # RPL_NAMREPLY m = self.getMessage(1) - m = self.assertMessageEqual(m, command='366') # RPL_ENDOFNAMES + if m.command in ('331', '332'): # RPL_NOTOPIC, RPL_TOPIC + m = self.getMessage(1) + self.assertMessageEqual(m, command='353') # RPL_NAMREPLY + namreply = m + m = self.getMessage(1) + self.assertMessageEqual(m, command='366') # RPL_ENDOFNAMES + else: + self.assertMessageEqual(m, command='353') # RPL_NAMREPLY + namreply = m + m = self.getMessage(1) + self.assertMessageEqual(m, command='366') # RPL_ENDOFNAMES m = self.getMessage(1) self.assertIn(m.command, ('331', '332'), m) # RPL_NOTOPIC, RPL_TOPIC + + def testJoinNamreply(self): + """“353 RPL_NAMREPLY + "( "=" / "*" / "@" ) + :[ "@" / "+" ] *( " " [ "@" / "+" ] )” + -- + """ + self.connectClient('foo') + self.sendLine(1, 'JOIN #chan') + + for m in self.getMessages(1): + if m.command == '353': + self.assertIn(len(m.params), (3, 4), m) + params = ambiguities.normalize_namreply_params(m.params) + self.assertIn(params[1], '=*@', m) + self.assertEqual(params[2], '#chan', m) + self.assertIn(params[3], {'foo', '@foo', '+foo'}, m) + + + def testPartNotInChannel(self): + """“442 ERR_NOTONCHANNEL + " :You're not on that channel" + + - Returned by the server whenever a client tries to + perform a channel effecting command for which the + client isn't a member.” + -- + and + + ERR_NOSUCHCHANNEL should only be used for invalid + channel names: + “403 ERR_NOSUCHCHANNEL + " :No such channel" + + - Used to indicate the given channel name is invalid.” + -- + and + """ + self.connectClient('foo') + self.sendLine(1, 'PART #chan') + m = self.getMessage(1) + self.assertMessageEqual(m, command='442') # ERR_NOTONCHANNEL + def testJoinTwice(self): self.connectClient('foo') self.sendLine(1, 'JOIN #chan')