本文整理汇总了Python中b3.plugins.admin.AdminPlugin类的典型用法代码示例。如果您正苦于以下问题:Python AdminPlugin类的具体用法?Python AdminPlugin怎么用?Python AdminPlugin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AdminPlugin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PluginmanagerTestCase
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)
示例2: CustomcommandsTestCase
class CustomcommandsTestCase(unittest2.TestCase):
def setUp(self):
self.sleep_patcher = patch("time.sleep")
self.sleep_mock = self.sleep_patcher.start()
# create a FakeConsole parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString(r"""<configuration/>""")
with logging_disabled():
from b3.fake import FakeConsole
self.console = FakeConsole(self.parser_conf)
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
self.adminPlugin._commands = {} # work around known bug in the Admin plugin which makes the _command property shared between all instances
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.console.screen = Mock()
self.console.time = time.time
self.console.upTime = Mock(return_value=3)
self.console.cron.stop()
def tearDown(self):
self.sleep_patcher.stop()
示例3: ProxyfilterTestCase
class ProxyfilterTestCase(unittest2.TestCase):
def setUp(self):
# create a FakeConsole parser
self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True))
self.parser_conf.loadFromString(r"""""")
with logging_disabled():
from b3.fake import FakeConsole
self.console = FakeConsole(self.parser_conf)
# load the admin plugin
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
self.adminPlugin._commands = {}
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
when(self.console.config).get_external_plugins_dir().thenReturn(os.path.join(os.getcwd(), '..', '..'))
# patch the Proxyfilter class not to execute
# proxy scans in a multithreaded environment
patch_proxy_filter()
def tearDown(self):
self.console.working = False
示例4: setUp
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)
示例5: Welcome_functional_test
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()
示例6: ChatloggerTestCase
class ChatloggerTestCase(unittest.TestCase):
def setUp(self):
testcase_lock.acquire()
self.addCleanup(cleanUp)
flush_console_streams()
# create a FakeConsole parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString(r"""<configuration/>""")
with logging_disabled():
from b3.fake import FakeConsole
self.console = FakeConsole(self.parser_conf)
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
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.console.screen = Mock()
self.console.time = time.time
self.console.upTime = Mock(return_value=3)
def tearDown(self):
try:
self.console.storage.shutdown()
except:
pass
示例7: Iourt41TestCase
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
示例8: DuelTestCase
class DuelTestCase(unittest2.TestCase):
def setUp(self):
console_conf = CfgConfigParser()
console_conf.loadFromString(r'''''')
self.console_main_conf = MainConfig(console_conf)
with logging_disabled():
from b3.fake import FakeConsole
self.console = FakeConsole(self.console_main_conf)
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
self.adminPlugin._commands = {}
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
# create our plugin instance
self.p = DuelPlugin(self.console)
self.p.onStartup()
with logging_disabled():
from b3.fake import FakeClient
self.mike = FakeClient(console=self.console, name="Mike", guid="MIKEGUID", groupBits=1)
self.bill = FakeClient(console=self.console, name="Bill", guid="BILLGUID", groupBits=1)
self.anna = FakeClient(console=self.console, name="Anna", guid="ANNAGUID", groupBits=1)
def tearDown(self):
unstub()
示例9: Admin_functional_test
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
)
示例10: CalladminTestCase
class CalladminTestCase(unittest2.TestCase):
def setUp(self):
self.sleep_patcher = patch("time.sleep")
self.sleep_mock = self.sleep_patcher.start()
# create a FakeConsole parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString(r"""<configuration/>""")
with logging_disabled():
from b3.fake import FakeConsole
self.console = FakeConsole(self.parser_conf)
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
self.adminPlugin._commands = {}
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getCvar('sv_hostname').thenReturn(Cvar(name='sv_hostname', value='Test Server'))
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
when(time).time().thenReturn(60)
def tearDown(self):
self.sleep_patcher.stop()
示例11: PluginTestCase
class PluginTestCase(unittest.TestCase):
def setUp(self):
# less logging
logging.getLogger('output').setLevel(logging.ERROR)
# create a parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString("""<configuration></configuration>""")
self.console = DummyParser(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.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
self.joe = FakeClient(self.console, name="Joe", guid="joe_guid", groupBits=1)
self.simon = FakeClient(self.console, name="Simon", guid="simon_guid", groupBits=0)
self.moderator = FakeClient(self.console, name="Moderator", guid="moderator_guid", groupBits=8)
logging.getLogger('output').setLevel(logging.DEBUG)
def tearDown(self):
self.console.working = False
示例12: Iourt41TestCase
class Iourt41TestCase(unittest.TestCase):
"""
Test case that is suitable for testing iourt41 parser specific features
"""
@classmethod
def setUpClass(cls):
# less logging
logging.getLogger('output').setLevel(logging.CRITICAL)
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 BF3 parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString("""
<configuration>
<settings name="messages">
<set name="kicked_by">$clientname was kicked by $adminname $reason</set>
<set name="kicked">$clientname was kicked $reason</set>
<set name="banned_by">$clientname was banned by $adminname $reason</set>
<set name="banned">$clientname was banned $reason</set>
<set name="temp_banned_by">$clientname was temp banned by $adminname for $banduration $reason</set>
<set name="temp_banned">$clientname was temp banned for $banduration $reason</set>
<set name="unbanned_by">$clientname was un-banned by $adminname $reason</set>
<set name="unbanned">$clientname was un-banned $reason</set>
</settings>
</configuration>
""")
self.console = Iourt41Parser(self.parser_conf)
self.console.startup()
# load the admin plugin
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.xml')
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
def getPlugin(name):
if name == 'admin':
return self.adminPlugin
else:
return self.console.getPlugin(name)
self.console.getPlugin = getPlugin
# prepare a few players
self.joe = FakeClient(self.console, name="Joe", guid="00000000000000000000000000000001", groupBits=1, team=TEAM_UNKNOWN)
self.simon = FakeClient(self.console, name="Simon", guid="00000000000000000000000000000002", groupBits=0, team=TEAM_UNKNOWN)
self.reg = FakeClient(self.console, name="Reg", guid="00000000000000000000000000000003", groupBits=4, team=TEAM_UNKNOWN)
self.moderator = FakeClient(self.console, name="Moderator", guid="00000000000000000000000000000004", groupBits=8, team=TEAM_UNKNOWN)
self.admin = FakeClient(self.console, name="Level-40-Admin", guid="00000000000000000000000000000005", groupBits=16, team=TEAM_UNKNOWN)
self.superadmin = FakeClient(self.console, name="God", guid="00000000000000000000000000000000", groupBits=128, team=TEAM_UNKNOWN)
# more logging
logging.getLogger('output').setLevel(logging.DEBUG)
示例13: MapcycleTestCase
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
示例14: Iourt41TestCase
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=''))
示例15: test_functional
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")])