mirror of
https://github.com/progval/irctest.git
synced 2025-04-07 07:49:52 +00:00
Don't pass a 'config' argument to the controller, only Oragono had it.
Instead, annotate tests with the optional features they may need from the IRCd.
This commit is contained in:
@ -13,13 +13,14 @@ class _BaseController:
|
|||||||
A software controller is an object that handles configuring and running
|
A software controller is an object that handles configuring and running
|
||||||
a process (eg. a server or a client), as well as sending it instructions
|
a process (eg. a server or a client), as well as sending it instructions
|
||||||
that are not part of the IRC specification."""
|
that are not part of the IRC specification."""
|
||||||
pass
|
def __init__(self, test_config):
|
||||||
|
self.test_config = test_config
|
||||||
|
|
||||||
class DirectoryBasedController(_BaseController):
|
class DirectoryBasedController(_BaseController):
|
||||||
"""Helper for controllers whose software configuration is based on an
|
"""Helper for controllers whose software configuration is based on an
|
||||||
arbitrary directory."""
|
arbitrary directory."""
|
||||||
def __init__(self):
|
def __init__(self, test_config):
|
||||||
super().__init__()
|
super().__init__(test_config)
|
||||||
self.directory = None
|
self.directory = None
|
||||||
self.proc = None
|
self.proc = None
|
||||||
|
|
||||||
|
@ -18,6 +18,14 @@ class _IrcTestCase(unittest.TestCase):
|
|||||||
"""Base class for test cases."""
|
"""Base class for test cases."""
|
||||||
controllerClass = None # Will be set by __main__.py
|
controllerClass = None # Will be set by __main__.py
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def config():
|
||||||
|
"""Some configuration to pass to the controllers.
|
||||||
|
For example, Oragono only enables its MySQL support if
|
||||||
|
config()["chathistory"]=True.
|
||||||
|
"""
|
||||||
|
return {}
|
||||||
|
|
||||||
def description(self):
|
def description(self):
|
||||||
method_doc = self._testMethodDoc
|
method_doc = self._testMethodDoc
|
||||||
if not method_doc:
|
if not method_doc:
|
||||||
@ -29,7 +37,7 @@ class _IrcTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.controller = self.controllerClass()
|
self.controller = self.controllerClass(self.config())
|
||||||
self.inbuffer = []
|
self.inbuffer = []
|
||||||
if self.show_io:
|
if self.show_io:
|
||||||
print('---- new test ----')
|
print('---- new test ----')
|
||||||
@ -235,15 +243,12 @@ class BaseServerTestCase(_IrcTestCase):
|
|||||||
invalid_metadata_keys = frozenset()
|
invalid_metadata_keys = frozenset()
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
config = None
|
|
||||||
if hasattr(self, 'customizedConfig'):
|
|
||||||
config = self.customizedConfig()
|
|
||||||
self.server_support = {}
|
self.server_support = {}
|
||||||
self.find_hostname_and_port()
|
self.find_hostname_and_port()
|
||||||
self.controller.run(self.hostname, self.port, password=self.password,
|
self.controller.run(self.hostname, self.port, password=self.password,
|
||||||
valid_metadata_keys=self.valid_metadata_keys,
|
valid_metadata_keys=self.valid_metadata_keys,
|
||||||
invalid_metadata_keys=self.invalid_metadata_keys,
|
invalid_metadata_keys=self.invalid_metadata_keys,
|
||||||
ssl=self.ssl, config=config)
|
ssl=self.ssl)
|
||||||
self.clients = {}
|
self.clients = {}
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.controller.kill()
|
self.controller.kill()
|
||||||
|
@ -168,6 +168,16 @@ class OragonoController(BaseServerController, DirectoryBasedController):
|
|||||||
if config is None:
|
if config is None:
|
||||||
config = copy.deepcopy(BASE_CONFIG)
|
config = copy.deepcopy(BASE_CONFIG)
|
||||||
|
|
||||||
|
enable_chathistory = self.test_config.get("chathistory")
|
||||||
|
enable_roleplay = self.test_config.get("oragono_roleplay")
|
||||||
|
if enable_chathistory or enable_roleplay:
|
||||||
|
config = self.addMysqlToConfig(config)
|
||||||
|
|
||||||
|
if enable_roleplay:
|
||||||
|
config['roleplay'] = {
|
||||||
|
'enabled': True,
|
||||||
|
}
|
||||||
|
|
||||||
self.port = port
|
self.port = port
|
||||||
bind_address = "127.0.0.1:%s" % (port,)
|
bind_address = "127.0.0.1:%s" % (port,)
|
||||||
listener_conf = None # plaintext
|
listener_conf = None # plaintext
|
||||||
|
@ -27,6 +27,11 @@ def validate_chathistory_batch(msgs):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
class ChathistoryTestCase(cases.BaseServerTestCase):
|
class ChathistoryTestCase(cases.BaseServerTestCase):
|
||||||
|
@staticmethod
|
||||||
|
def config():
|
||||||
|
return {
|
||||||
|
"chathistory": True,
|
||||||
|
}
|
||||||
|
|
||||||
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
||||||
def testInvalidTargets(self):
|
def testInvalidTargets(self):
|
||||||
@ -123,9 +128,6 @@ class ChathistoryTestCase(cases.BaseServerTestCase):
|
|||||||
self.validate_echo_messages(NUM_MESSAGES, echo_messages)
|
self.validate_echo_messages(NUM_MESSAGES, echo_messages)
|
||||||
self.validate_chathistory(echo_messages, 1, chname)
|
self.validate_chathistory(echo_messages, 1, chname)
|
||||||
|
|
||||||
def customizedConfig(self):
|
|
||||||
return self.controller.addMysqlToConfig()
|
|
||||||
|
|
||||||
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
||||||
def testChathistoryDMs(self):
|
def testChathistoryDMs(self):
|
||||||
c1 = secrets.token_hex(12)
|
c1 = secrets.token_hex(12)
|
||||||
|
@ -7,9 +7,11 @@ RELAYMSG_CAP = 'draft/relaymsg'
|
|||||||
RELAYMSG_TAG_NAME = 'draft/relaymsg'
|
RELAYMSG_TAG_NAME = 'draft/relaymsg'
|
||||||
|
|
||||||
class RelaymsgTestCase(cases.BaseServerTestCase):
|
class RelaymsgTestCase(cases.BaseServerTestCase):
|
||||||
|
@staticmethod
|
||||||
def customizedConfig(self):
|
def config():
|
||||||
return self.controller.addMysqlToConfig()
|
return {
|
||||||
|
"chathistory": True,
|
||||||
|
}
|
||||||
|
|
||||||
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
||||||
def testRelaymsg(self):
|
def testRelaymsg(self):
|
||||||
|
@ -3,13 +3,11 @@ from irctest.numerics import ERR_CANNOTSENDRP
|
|||||||
from irctest.irc_utils.junkdrawer import random_name
|
from irctest.irc_utils.junkdrawer import random_name
|
||||||
|
|
||||||
class RoleplayTestCase(cases.BaseServerTestCase):
|
class RoleplayTestCase(cases.BaseServerTestCase):
|
||||||
|
@staticmethod
|
||||||
def customizedConfig(self):
|
def config():
|
||||||
config = self.controller.baseConfig()
|
return {
|
||||||
config['roleplay'] = {
|
"oragono_roleplay": True,
|
||||||
'enabled': True,
|
|
||||||
}
|
}
|
||||||
return self.controller.addMysqlToConfig(config)
|
|
||||||
|
|
||||||
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
||||||
def testRoleplay(self):
|
def testRoleplay(self):
|
||||||
|
@ -16,9 +16,11 @@ def extract_playback_privmsgs(messages):
|
|||||||
|
|
||||||
|
|
||||||
class ZncPlaybackTestCase(cases.BaseServerTestCase):
|
class ZncPlaybackTestCase(cases.BaseServerTestCase):
|
||||||
|
@staticmethod
|
||||||
def customizedConfig(self):
|
def config():
|
||||||
return self.controller.addMysqlToConfig()
|
return {
|
||||||
|
"chathistory": True,
|
||||||
|
}
|
||||||
|
|
||||||
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
@cases.SpecificationSelector.requiredBySpecification('Oragono')
|
||||||
def testZncPlayback(self):
|
def testZncPlayback(self):
|
||||||
|
Reference in New Issue
Block a user