Split testJoin into testJoinAllMessages and testJoinNamreply, and add testPartNotInChannel

This commit is contained in:
Valentin Lorentz 2015-12-21 15:45:05 +01:00
parent 469eedab89
commit d75ffcb2f5
2 changed files with 60 additions and 15 deletions

View File

@ -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

View File

@ -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
"( "=" / "*" / "@" ) <channel>
:[ "@" / "+" ] <nick> *( " " [ "@" / "+" ] <nick> )
-- <https://tools.ietf.org/html/rfc2812#section-5.2>
"""
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
"<channel> :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.”
-- <https://tools.ietf.org/html/rfc1459#section-6.1>
and <https://tools.ietf.org/html/rfc2812#section-5.2>
ERR_NOSUCHCHANNEL should only be used for invalid
channel names:
403 ERR_NOSUCHCHANNEL
"<channel name> :No such channel"
- Used to indicate the given channel name is invalid.
-- <https://tools.ietf.org/html/rfc1459#section-6.1>
and <https://tools.ietf.org/html/rfc2812#section-5.2>
"""
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')