def setUp(self): self.available_names = [ "hardcore", "normal", "infantry", "tdm", "conquest", "rush", "quickmatch", "hardcore-tdm", "hardcore-conquest" ] self.console = Mock() self.p = Poweradminbf3Plugin(self.console) self.p._list_available_server_config_files = lambda: self.available_names
def test_1(self): """nothing in config, no plugin config file, no b3 config file""" self.conf.loadFromString(""" <configuration plugin="poweradminbf3"> <settings name="preferences"/> </configuration> """) # the plugin config does not exist on the filesystem p = Poweradminbf3Plugin(fakeConsole, self.conf) p.onLoadConfig() self.assertIsNone(p._configPath)
def test_3(self): """junk in config, no plugin config file, no b3 config file""" self.conf.loadFromString(""" <configuration plugin="poweradminbf3"> <settings name="preferences"> <set name="config_path">I don't exists</set> </settings> </configuration> """) p = Poweradminbf3Plugin(fakeConsole, self.conf) p.onLoadConfig() self.assertIsNone(p._configPath)
def test_4(self): """absolute existing path in config file""" self.conf.loadFromString(""" <configuration plugin="poweradminbf3"> <settings name="preferences"> <set name="config_path">/somewhere/on/the/filesystem/</set> </settings> </configuration> """) p = Poweradminbf3Plugin(fakeConsole, self.conf) self.setExistingPaths(['/somewhere/on/the/filesystem/']) with patch.object(os.path, 'isdir', Mock(side_effect=Test_server_config_path.isdir)): p.onLoadConfig() self.assertEqual(os.path.normpath('/somewhere/on/the/filesystem/'), p._configPath)
def test_2bis(self): """nothing in config, plugin config file, no b3 config file""" self.conf.loadFromString(""" <configuration plugin="poweradminbf3"> <settings name="preferences"/> </configuration> """) self.conf.fileName = "somewhere/on/the/filesystem/plugin_poweradminbf3.xml" p = Poweradminbf3Plugin(fakeConsole, self.conf) self.setExistingPaths(["somewhere/on/the/filesystem//serverconfigs"]) with patch.object(os.path, 'isdir', Mock(side_effect=Test_server_config_path.isdir)): p.onLoadConfig() self.assertEqual( os.path.normpath("somewhere/on/the/filesystem//serverconfigs"), p._configPath)
def test_6(self): """existing path in config file relative to plugin config directory""" self.conf.loadFromString(""" <configuration plugin="poweradminbf3"> <settings name="preferences"> <set name="config_path">subdirectory</set> </settings> </configuration> """) self.conf.fileName = "somewhere/on/the/filesystem/plugin_poweradminbf3.xml" p = Poweradminbf3Plugin(fakeConsole, self.conf) self.setExistingPaths(["somewhere/on/the/filesystem/subdirectory"]) with patch.object(os.path, 'isdir', Mock(side_effect=Test_server_config_path.isdir)): p.onLoadConfig() self.assertEqual( os.path.normpath('somewhere/on/the/filesystem/subdirectory'), p._configPath)
def test_2(self): """nothing in config, no plugin config file, b3 config file""" self.conf.loadFromString(""" <configuration plugin="poweradminbf3"> <settings name="preferences"/> </configuration> """) # the plugin config does not exist on the filesystem p = Poweradminbf3Plugin(fakeConsole, self.conf) # make B3 think it has a config file on the filesystem p.console.config.fileName = "somewhere/on/the/filesystem/b3conf/b3.xml" self.setExistingPaths( ["somewhere/on/the/filesystem/b3conf/serverconfigs"]) with patch.object(os.path, 'isdir', Mock(side_effect=Test_server_config_path.isdir)): p.onLoadConfig() self.assertEqual( os.path.normpath( "somewhere/on/the/filesystem/b3conf/serverconfigs"), p._configPath)
from b3.fake import fakeConsole, superadmin from poweradminbf3 import Poweradminbf3Plugin from b3.config import XmlConfigParser conf = XmlConfigParser() conf.loadFromString(""" <configuration plugin="poweradminbf3"> <settings name="commands"> <set name="unlockmode">40</set> </settings> </configuration> """) p = Poweradminbf3Plugin(fakeConsole, conf) p.onLoadConfig() p.onStartup() superadmin.connects('superadmin') print "\n\n####################################### !unlockmode" superadmin.says('!unlockmode') superadmin.says('@unlockmode') print "\n\n####################################### !unlockmode junk" superadmin.says('!unlockmode junk') superadmin.says('@unlockmode junk') print "\n\n####################################### !unlockmode all"
def setUp(self): self.console = Mock() self.p = Poweradminbf3Plugin(self.console)