From 3b196ce4452aa50c3f42992417345aa4f6561bbe Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 22 Dec 2015 01:56:01 +0100 Subject: [PATCH] Add test testKickSendsMessages. --- irctest/__main__.py | 2 +- irctest/basecontrollers.py | 2 +- irctest/cases.py | 6 +-- ...{optional_extensions.py => optionality.py} | 5 +++ .../server_tests/test_channel_operations.py | 39 +++++++++++++++++++ 5 files changed, 49 insertions(+), 5 deletions(-) rename irctest/{optional_extensions.py => optionality.py} (86%) diff --git a/irctest/__main__.py b/irctest/__main__.py index 4120e8a..4af430e 100644 --- a/irctest/__main__.py +++ b/irctest/__main__.py @@ -5,7 +5,7 @@ import unittest import functools import importlib from .cases import _IrcTestCase -from .optional_extensions import OptionalityReportingTextTestRunner +from .optionality import OptionalityReportingTextTestRunner from .basecontrollers import BaseClientController, BaseServerController def main(args): diff --git a/irctest/basecontrollers.py b/irctest/basecontrollers.py index 5163d41..cf9e5b8 100644 --- a/irctest/basecontrollers.py +++ b/irctest/basecontrollers.py @@ -6,7 +6,7 @@ import time import subprocess import psutil -from .optional_extensions import NotImplementedByController +from .optionality import NotImplementedByController class _BaseController: """Base class for software controllers. diff --git a/irctest/cases.py b/irctest/cases.py index f296213..14ddd08 100644 --- a/irctest/cases.py +++ b/irctest/cases.py @@ -8,7 +8,7 @@ import supybot.utils from . import client_mock from . import authentication -from . import optional_extensions +from . import optionality from .irc_utils import message_parser from .irc_utils import capabilities @@ -292,12 +292,12 @@ class OptionalityHelper: def checkSaslSupport(self): if self.controller.supported_sasl_mechanisms: return - raise optional_extensions.NotImplementedByController('SASL') + raise optionality.NotImplementedByController('SASL') def checkMechanismSupport(self, mechanism): if mechanism in self.controller.supported_sasl_mechanisms: return - raise optional_extensions.OptionalSaslMechanismNotSupported(mechanism) + raise optionality.OptionalSaslMechanismNotSupported(mechanism) def skipUnlessHasMechanism(mech): def decorator(f): diff --git a/irctest/optional_extensions.py b/irctest/optionality.py similarity index 86% rename from irctest/optional_extensions.py rename to irctest/optionality.py index d27292b..a9875ef 100644 --- a/irctest/optional_extensions.py +++ b/irctest/optionality.py @@ -6,6 +6,11 @@ class NotImplementedByController(unittest.SkipTest, NotImplementedError): def __str__(self): return 'Not implemented by controller: {}'.format(self.args[0]) +class ImplementationChoice(unittest.SkipTest): + def __str__(self): + return 'Choice in the implementation makes it impossible to ' \ + 'perform a test: {}'.format(self.args[0]) + class OptionalExtensionNotSupported(unittest.SkipTest): def __str__(self): return 'Unsupported extension: {}'.format(self.args[0]) diff --git a/irctest/server_tests/test_channel_operations.py b/irctest/server_tests/test_channel_operations.py index 41c6a28..26e07bf 100644 --- a/irctest/server_tests/test_channel_operations.py +++ b/irctest/server_tests/test_channel_operations.py @@ -4,6 +4,8 @@ Section 3.2 of RFC 2812 """ from irctest import cases +from irctest import client_mock +from irctest import optionality from irctest.irc_utils import ambiguities from irctest.irc_utils.message_parser import Message @@ -180,3 +182,40 @@ class JoinTestCase(cases.BaseServerTestCase): self.assertMessageEqual(m, command='323', # RPL_LISTEND fail_msg='Third reply to LIST is not 322 (RPL_LIST) ' 'or 323 (RPL_LISTEND), or but: {msg}') + + def testKickSendsMessages(self): + """“Once a user has joined a channel, he receives information about + all commands his server receives affecting the channel. This + includes […] KICK” + -- + and + """ + self.connectClient('foo') + self.connectClient('bar') + self.connectClient('baz') + self.sendLine(1, 'JOIN #chan') + # TODO: check foo is an operator + self.sendLine(2, 'JOIN #chan') + self.sendLine(3, 'JOIN #chan') + + import time + time.sleep(0.1) + self.getMessages(1) + self.getMessages(2) + self.getMessages(3) + self.sendLine(1, 'KICK #chan bar :bye') + try: + m = self.getMessage(1) + if m.command == '482': + raise optionality.ImplementationChoice( + 'Channel creators are not opped by default.') + self.assertMessageEqual(m, command='KICK') + except client_mock.NoMessageException: + # The RFCs do not say KICK should be echoed + pass + m = self.getMessage(2) + self.assertMessageEqual(m, command='KICK', + params=['#chan', 'bar', 'bye']) + m = self.getMessage(3) + self.assertMessageEqual(m, command='KICK', + params=['#chan', 'bar', 'bye'])