本文整理汇总了Python中b3.plugins.admin.AdminPlugin.onLoadConfig方法的典型用法代码示例。如果您正苦于以下问题:Python AdminPlugin.onLoadConfig方法的具体用法?Python AdminPlugin.onLoadConfig怎么用?Python AdminPlugin.onLoadConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类b3.plugins.admin.AdminPlugin
的用法示例。
在下文中一共展示了AdminPlugin.onLoadConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
def setUp(self):
B3TestCase.setUp(self)
with logging_disabled():
admin_conf = CfgConfigParser()
admin_plugin = AdminPlugin(self.console, admin_conf)
admin_plugin.onLoadConfig()
admin_plugin.onStartup()
when(self.console).getPlugin('admin').thenReturn(admin_plugin)
conf = CfgConfigParser()
conf.loadFromString(dedent(r"""
[commands]
mapstats-stats: 0
testscore-ts: 0
topstats-top: 0
topxp: 0
[settings]
startPoints: 100
resetscore: no
resetxp: no
show_awards: no
show_awards_xp: no
"""))
self.p = StatsPlugin(self.console, conf)
self.p.onLoadConfig()
self.p.onStartup()
self.joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=1, team=TEAM_RED)
self.mike = FakeClient(self.console, name="Mike", guid="mikeguid", groupBits=1, team=TEAM_RED)
self.joe.connects(1)
self.mike.connects(2)
示例2: Welcome_functional_test
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class Welcome_functional_test(B3TestCase):
def setUp(self):
B3TestCase.setUp(self)
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
self.conf = CfgConfigParser()
self.p = WelcomePlugin(self.console, self.conf)
self.joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=1, team=b3.TEAM_RED)
self.mike = FakeClient(self.console, name="Mike", guid="mikeguid", groupBits=1, team=b3.TEAM_RED)
self.bill = FakeClient(self.console, name="Bill", guid="billguid", groupBits=1, team=b3.TEAM_RED)
self.superadmin = FakeClient(self.console, name="SuperAdmin", guid="superadminguid", groupBits=128, team=b3.TEAM_RED)
def load_config(self, config_content=None):
"""
load the given config content, or the default config if config_content is None.
"""
if config_content is None:
self.conf.load(b3.getAbsolutePath('@b3/conf/plugin_welcome.ini'))
else:
self.conf.loadFromString(config_content)
self.p.onLoadConfig()
self.p.onStartup()
示例3: PluginmanagerTestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class PluginmanagerTestCase(B3TestCase):
def setUp(self):
B3TestCase.setUp(self)
self.console.gameName = 'f00'
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
self.conf = CfgConfigParser()
self.conf.loadFromString(dedent(r"""
[commands]
plugin: superadmin
"""))
self.p = PluginmanagerPlugin(self.console, self.conf)
when(self.console).getPlugin("pluginmanager").thenReturn(self.adminPlugin)
self.p.onLoadConfig()
self.p.onStartup()
when(self.console.config).get_external_plugins_dir().thenReturn(b3.getAbsolutePath('@b3\\extplugins'))
# store them also in the console _plugins dict
self.console._plugins['admin'] = self.adminPlugin
self.console._plugins['pluginmanager'] = self.p
def tearDown(self):
self.console._plugins.clear()
B3TestCase.tearDown(self)
示例4: Iourt41TestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class Iourt41TestCase(Iourt41_TestCase_mixin):
"""
Test case that is suitable for testing Iourt41 parser specific features
"""
def setUp(self):
# create a Iourt41 parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString("""<configuration><settings name="server"><set name="game_log"></set></settings></configuration>""")
self.console = Iourt41Parser(self.parser_conf)
self.console.write = Mock(name="write", side_effect=write)
self.console.startup()
# load the admin plugin
if B3version(b3_version) >= B3version("1.10dev"):
admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
else:
admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
def tearDown(self):
self.console.working = False
示例5: Admin_functional_test
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class Admin_functional_test(B3TestCase):
""" tests from a class inherithing from Admin_functional_test must call self.init() """
def setUp(self):
B3TestCase.setUp(self)
self.conf = XmlConfigParser()
self.p = AdminPlugin(self.console, self.conf)
def init(self, config_content=None):
""" optionally specify a config for the plugin. If called with no parameter, then the default config is loaded """
if config_content is None:
if not os.path.isfile(ADMIN_CONFIG_FILE):
B3TestCase.tearDown(self) # we are skipping the test at a late stage after setUp was called
raise unittest.SkipTest("%s is not a file" % ADMIN_CONFIG_FILE)
else:
self.conf.load(ADMIN_CONFIG_FILE)
else:
self.conf.loadFromString(config_content)
self.p.onLoadConfig()
self.p.onStartup()
self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="joeguid", groupBits=128, team=TEAM_RED)
self.mike = FakeClient(
self.console, name="Mike", exactName="Mike", guid="mikeguid", groupBits=1, team=TEAM_BLUE
)
示例6: Iourt41TestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class Iourt41TestCase(unittest.TestCase):
"""
Test case that is suitable for testing Iourt41 parser specific features
"""
@classmethod
def setUpClass(cls):
with logging_disabled():
from b3.parsers.q3a.abstractParser import AbstractParser
from b3.fake import FakeConsole
AbstractParser.__bases__ = (FakeConsole,)
# Now parser inheritance hierarchy is :
# Iourt41Parser -> abstractParser -> FakeConsole -> Parser
def setUp(self):
with logging_disabled():
# create a Iourt41 parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString("""<configuration><settings name="server"><set name="game_log"></set></settings></configuration>""")
self.console = Iourt41Parser(self.parser_conf)
self.console.startup()
# load the admin plugin
if B3version(b3_version) >= B3version("1.10dev"):
admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
else:
admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
# prepare a few players
from b3.fake import FakeClient
self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.simon = FakeClient(self.console, name="Simon", exactName="Simon", guid="qsdfdsqfdsqf", groupBits=0, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.reg = FakeClient(self.console, name="Reg", exactName="Reg", guid="qsdfdsqfdsqf33", groupBits=4, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.moderator = FakeClient(self.console, name="Moderator", exactName="Moderator", guid="sdf455ezr", groupBits=8, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.admin = FakeClient(self.console, name="Level-40-Admin", exactName="Level-40-Admin", guid="875sasda", groupBits=16, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.superadmin = FakeClient(self.console, name="God", exactName="God", guid="f4qfer654r", groupBits=128, team=TEAM_UNKNOWN, teamId=0, squad=0)
def tearDown(self):
self.console.working = False
# sys.stdout.write("\tactive threads count : %s " % threading.activeCount())
# sys.stderr.write("%s\n" % threading.enumerate())
def init_default_cvar(self):
when(self.console).getCvar('timelimit').thenReturn(Cvar('timelimit', value=20))
when(self.console).getCvar('g_maxGameClients').thenReturn(Cvar('g_maxGameClients', value=16))
when(self.console).getCvar('sv_maxclients').thenReturn(Cvar('sv_maxclients', value=16))
when(self.console).getCvar('sv_privateClients').thenReturn(Cvar('sv_privateClients', value=0))
when(self.console).getCvar('g_allowvote').thenReturn(Cvar('g_allowvote', value=0))
when(self.console).getCvar('g_gear').thenReturn(Cvar('g_gear', value=''))
示例7: MapcycleTestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class MapcycleTestCase(unittest2.TestCase):
@classmethod
def setUpClass(cls):
with logging_disabled():
from b3.parsers.q3a.abstractParser import AbstractParser
from b3.fake import FakeConsole
AbstractParser.__bases__ = (FakeConsole,)
# Now parser inheritance hierarchy is :
# Iourt41Parser -> abstractParser -> FakeConsole -> Parser
def setUp(self):
# create a Iourt42 parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString(dedent(r"""
<configuration>
<settings name="server">
<set name="game_log"></set>
</settings>
</configuration>
"""))
self.console = Iourt42Parser(self.parser_conf)
# initialize some fixed cvars which will be used by both the plugin and the iourt42 parser
when(self.console).getCvar('auth').thenReturn(Cvar('auth', value='0'))
when(self.console).getCvar('fs_basepath').thenReturn(Cvar('g_maxGameClients', value='/fake/basepath'))
when(self.console).getCvar('fs_homepath').thenReturn(Cvar('sv_maxclients', value='/fake/homepath'))
when(self.console).getCvar('fs_game').thenReturn(Cvar('fs_game', value='q3ut4'))
when(self.console).getCvar('gamename').thenReturn(Cvar('gamename', value='q3urt42'))
# start the parser
self.console.startup()
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
# force fake mapname here so Mapcycle Plugin will
# not catch useless EVT_GAME_MAP_CHANGE
self.console.game.mapName = 'ut4_casa'
self.conf = XmlConfigParser()
self.conf.loadFromString(dedent(MAPCYCLE_PLUGIN_CONFIG))
# patch the mapcycle plugin for testing purpose
patch_mapcycle_plugin()
self.p = MapcyclePlugin(self.console, self.conf)
self.p.onLoadConfig()
self.p.onStartup()
def tearDown(self):
self.console.working = False
示例8: test_functional
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class test_functional(unittest.TestCase):
@classmethod
def setUpClass(cls):
from b3.fake import FakeConsole
RavagedParser.__bases__ = (FakeConsole,)
# Now parser inheritance hierarchy is :
# RavagedParser -> FakeConsole -> Parser
def setUp(self):
self.status_response = None # defaults to STATUS_RESPONSE module attribute
self.conf = XmlConfigParser()
self.conf.loadFromString("""<configuration></configuration>""")
self.parser = RavagedParser(self.conf)
self.parser.output = Mock()
self.parser.output.write = Mock()
ADMIN_CONFIG = XmlConfigParser()
ADMIN_CONFIG.load(ADMIN_CONFIG_FILE)
self.adminPlugin = AdminPlugin(self.parser, ADMIN_CONFIG)
when(self.parser).getPlugin("admin").thenReturn(self.adminPlugin)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
self.parser.startup()
def tearDown(self):
if hasattr(self, "parser"):
del self.parser.clients
self.parser.working = False
def test_map(self):
# GIVEN
when(self.parser.output).write("getmaplist false").thenReturn(u"""0 CTR_Bridge
1 CTR_Canyon
2 CTR_Derelict
3 CTR_IceBreaker
4 CTR_Liberty
5 CTR_Rooftop
6 Thrust_Bridge
7 Thrust_Canyon
8 Thrust_Chasm
9 Thrust_IceBreaker
10 Thrust_Liberty
11 Thrust_Oilrig
12 Thrust_Rooftop
""".encode('UTF-8'))
admin = FakeClient(console=self.parser, name="admin", guid="guid_admin", groupBits=128)
admin.connects("guid_admin")
# WHEN
with patch.object(self.parser.output, 'write', wraps=self.parser.output.write) as write_mock:
admin.says("!map chasm")
# THEN
write_mock.assert_has_calls([call("addmap Thrust_Chasm 1"), call("nextmap")])
示例9: Admin_TestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class Admin_TestCase(B3TestCase):
def setUp(self):
B3TestCase.setUp(self)
self.conf = XmlConfigParser()
self.conf.load(ADMIN_CONFIG_FILE)
self.p = AdminPlugin(self.console, self.conf)
self.p.onLoadConfig()
self.p.onStartup()
示例10: Bf3TestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class Bf3TestCase(unittest.TestCase):
"""
Test case that is suitable for testing BF3 parser specific features
"""
@classmethod
def setUpClass(cls):
# less logging
logging.getLogger('output').setLevel(logging.ERROR)
from b3.parsers.frostbite2.abstractParser import AbstractParser
from b3.fake import FakeConsole
AbstractParser.__bases__ = (FakeConsole,)
# Now parser inheritance hierarchy is :
# Bf3Parser -> AbstractParser -> FakeConsole -> Parser
# Update method says of FakeClient so it let the Bf3Parser fire the SAY event
def says(self, msg):
print "\n%s says \"%s\"" % (self.name, msg)
self.console.queueEvent(self.console.OnPlayerChat(action=None, data=(self.cid, msg, 'all')))
FakeClient.says = says
def setUp(self):
# create a BF3 parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString(r"""<configuration/>""")
self.console = Bf3Parser(self.parser_conf)
self.console.startup()
# load the admin plugin
if B3version(b3_version) >= B3version("1.10dev"):
admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
else:
admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
#when(self.console).time().thenReturn(time.time())
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
# prepare a few players
self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.simon = FakeClient(self.console, name="Simon", exactName="Simon", guid="qsdfdsqfdsqf", groupBits=0, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.reg = FakeClient(self.console, name="Reg", exactName="Reg", guid="qsdfdsqfdsqf33", groupBits=4, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.moderator = FakeClient(self.console, name="Moderator", exactName="Moderator", guid="sdf455ezr", groupBits=8, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.admin = FakeClient(self.console, name="Level-40-Admin", exactName="Level-40-Admin", guid="875sasda", groupBits=16, team=TEAM_UNKNOWN, teamId=0, squad=0)
self.superadmin = FakeClient(self.console, name="God", exactName="God", guid="f4qfer654r", groupBits=128, team=TEAM_UNKNOWN, teamId=0, squad=0)
def tearDown(self):
self.console.working = False
示例11: UrtauthTestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class UrtauthTestCase(unittest2.TestCase):
@classmethod
def setUpClass(cls):
with logging_disabled():
from b3.parsers.q3a.abstractParser import AbstractParser
from b3.fake import FakeConsole
AbstractParser.__bases__ = (FakeConsole,)
# Now parser inheritance hierarchy is :
# Iourt41Parser -> abstractParser -> FakeConsole -> Parser
def setUp(self):
# create a Iourt42 parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString(dedent(r"""
<configuration>
<settings name="server">
<set name="game_log"></set>
</settings>
</configuration>
"""))
self.console = Iourt42Parser(self.parser_conf)
when(self.console).getCvar('auth').thenReturn(Cvar('auth', value='1'))
when(self.console).getCvar('fs_basepath').thenReturn(Cvar('fs_basepath', value='/fake/basepath'))
when(self.console).getCvar('fs_homepath').thenReturn(Cvar('fs_homepath', value='/fake/homepath'))
when(self.console).getCvar('fs_game').thenReturn(Cvar('fs_game', value='q3ut4'))
when(self.console).getCvar('gamename').thenReturn(Cvar('gamename', value='q3urt42'))
# start the parser
self.console.startup()
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
self.conf = CfgConfigParser()
self.conf.loadFromString(dedent(r"""
[settings]
maxlevel: reg
reason: ^7you need an ^1auth ^7account to play here
"""))
self.p = UrtauthPlugin(self.console, self.conf)
self.p.onLoadConfig()
self.p.onStartup()
def tearDown(self):
self.console.working = False
示例12: Admin_functional_test
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class Admin_functional_test(B3TestCase):
def setUp(self):
B3TestCase.setUp(self)
self.conf = XmlConfigParser()
self.conf.load(ADMIN_CONFIG_FILE)
self.p = AdminPlugin(self.console, self.conf)
self.p.onLoadConfig()
self.p.onStartup()
self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="joeguid", groupBits=128, team=TEAM_RED)
self.mike = FakeClient(self.console, name="Mike", exactName="Mike", guid="mikeguid", groupBits=1, team=TEAM_BLUE)
示例13: AdvTestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class AdvTestCase(B3TestCase):
"""
Ease test cases that need an working B3 console and need to control the ADV plugin config
"""
def setUp(self):
self.log = logging.getLogger('output')
self.log.propagate = False
B3TestCase.setUp(self)
global ADV_CONFIG_CONTENT, ADV_CONFIG_FILE, ADMIN_CONFIG_FILE, timer_patcher
if os.path.exists(ADV_CONFIG_FILE):
with open(ADV_CONFIG_FILE, 'r') as f:
ADV_CONFIG_CONTENT = f.read()
self.adminPluginConf = CfgConfigParser()
self.adminPluginConf.load(ADMIN_CONFIG_FILE)
self.adminPlugin = AdminPlugin(self.console, self.adminPluginConf)
when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
self.console.startup()
self.log.propagate = True
timer_patcher = patch('threading.Timer')
timer_patcher.start()
def tearDown(self):
B3TestCase.tearDown(self)
timer_patcher.stop()
unstub()
def init_plugin(self, config_content=None):
conf = None
if config_content:
conf = XmlConfigParser()
conf.setXml(config_content)
elif ADV_CONFIG_CONTENT:
conf = XmlConfigParser()
conf.setXml(ADV_CONFIG_CONTENT)
else:
unittest.skip("cannot get default plugin config file at %s" % ADV_CONFIG_FILE)
self.p = AdvPlugin(self.console, conf)
self.p.save = Mock()
self.conf = self.p.config
self.log.setLevel(logging.DEBUG)
self.log.info("============================= Adv plugin: loading config ============================")
self.p.onLoadConfig()
self.log.info("============================= Adv plugin: starting =================================")
self.p.onStartup()
示例14: IpbanTestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class IpbanTestCase(unittest2.TestCase):
def setUp(self):
self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
self.parser_conf.loadFromString(dedent(r""""""))
self.console = FakeConsole(self.parser_conf)
self.console.gameName = 'f00'
self.console.startup()
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
self.evt_queue = []
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
with logging_disabled():
from b3.fake import FakeClient
# prepare a few players
self.mike = FakeClient(self.console, name="Mike", exactName="Mike", guid="MIKEGUID", groupBits=16, ip='1.1.1.1')
self.paul = FakeClient(self.console, name="Paul", exactName="Paul", guid="PAULGUID", groupBits=1, ip='2.2.2.2')
self.john = FakeClient(self.console, name="John", exactName="John", guid="JOHNGUID", groupBits=0, ip='3.3.3.3')
self.mary = FakeClient(self.console, name="Mary", exactName="Mary", guid="MARYGUID", groupBits=0, ip='4.4.4.4')
self.conf = CfgConfigParser()
self.p = IpbanPlugin(self.console, self.conf)
# return some mock data
when(self.p).getBanIps().thenReturn(['2.2.2.2', '6.6.6.6', '7.7.7.7'])
when(self.p).getTempBanIps().thenReturn(['3.3.3.3', '8.8.8.8', '9.9.9.9'])
def tearDown(self):
self.console.working = False
self.mike.disconnects()
self.paul.disconnects()
self.john.disconnects()
self.mary.disconnects()
def init(self, config_content=None):
if config_content:
self.conf.loadFromString(config_content)
else:
self.conf.loadFromString(dedent(r"""
[settings]
maxlevel: user
"""))
self.p.onLoadConfig()
self.p.onStartup()
示例15: XlrstatsTestCase
# 需要导入模块: from b3.plugins.admin import AdminPlugin [as 别名]
# 或者: from b3.plugins.admin.AdminPlugin import onLoadConfig [as 别名]
class XlrstatsTestCase(B3TestCase):
def setUp(self):
"""
This method is called before each test.
It is meant to set up the SUT (System Under Test) in a manner that will ease the testing of its features.
"""
with logging_disabled():
# The B3TestCase class provides us a working B3 environment that does not require any database connexion.
# The B3 console is then accessible with self.console
B3TestCase.setUp(self)
# set additional B3 console stuff that will be used by the XLRstats plugin
self.console.gameName = "MyGame"
self.parser_conf.add_section('b3')
self.parser_conf.set('b3', 'time_zone', 'GMT')
# we make our own AdminPlugin and make sure it is the one return in any case
self.adminPlugin = AdminPlugin(self.console, DEFAULT_ADMIN_CONFIG_FILE)
when(self.console).getPlugin("admin").thenReturn(self.adminPlugin)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
# We need a config for the Xlrstats plugin
self.conf = CfgConfigParser() # It is an empty config but we can fill it up later
# Now we create an instance of the SUT (System Under Test) which is the XlrstatsPlugin
self.p = XlrstatsPlugin(self.console, self.conf)
when(self.console).getPlugin("xlrstats").thenReturn(self.p)
# create a client object to represent the game server
with patch("b3.clients.Clients.authorizeClients"): # we patch authorizeClients or it will spawn a thread
# with a 5 second timer
self.console.clients.newClient(-1, name="WORLD", guid="WORLD", hide=True)
def init(self, config_content=None):
"""
Load the config and starts the xlrstats plugin.
If no config_content is provided, use the default config file
:param config_content: optional XLRstats config
:type config_content: str
"""
if config_content is None:
self.conf.load(DEFAULT_XLRSTATS_CONFIG_FILE)
else:
self.conf.loadFromString(config_content)
self.p.onLoadConfig()
self.p.minlevel = 1 # tests in this module assume unregistered players aren't considered by Xlrstats
self.p.onStartup()