class Votesession_TestCase(Bf3TestCase): map_list = MapListBlock( ['3', '3', 'MP_001', 'RushLarge0', '1', 'MP_003', 'ConquestSmall0', '2', 'MP_007', 'SquadDeathMatch0', '3']) @staticmethod def write(data): """ simulate the write method of the B3 parser used to communicate with the BF3 server """ if data == ('mapList.getMapIndices',): return ['0', '1'] def setUp(self): Bf3TestCase.setUp(self) self.conf = CfgConfigParser() self.conf.loadFromString(self.__class__.CONFIG) self.p = VotemapPlugin(self.console, self.conf) self.p.onLoadConfig() self.p.onStartup() self.getFullMapRotationList_patcher = patch.object(self.console, 'getFullMapRotationList', Mock(return_value=Test_command_votemap.map_list)) self.getFullMapRotationList_patcher.start() self.write_patcher = patch.object(self.console, 'write', wraps=Test_command_votemap.write) self.write_mock = self.write_patcher.start() def tearDown(self): Bf3TestCase.tearDown(self) if hasattr(self.p, 'current_vote_session_timer') and self.p.current_vote_session_timer: self.p.current_vote_session_timer.cancel() self.getFullMapRotationList_patcher.stop() self.write_patcher.stop()
class Test_command_cancelvote(Bf3TestCase): def setUp(self): Bf3TestCase.setUp(self) self.conf = CfgConfigParser() self.conf.loadFromString("""\ [commands] cancelvote-cv: 20 """) self.p = VotemapPlugin(self.console, self.conf) self.p.onLoadConfig() self.p.onStartup() def test_no_vote(self): self.admin.connects('admin') self.admin.says('!cancelvote') self.assertEqual(['There is no vote to cancel'], self.admin.message_history) def test_nominal(self): self.admin.connects('admin') self.p.current_vote_session = Mock() self.p.current_vote_session_timer = Mock() self.admin.says('!cancelvote') self.assertEqual(['Vote canceled'], self.admin.message_history) self.assertIsNone(self.p.current_vote_session) self.assertIsNone(self.p.current_vote_session_timer) def test_alias(self): self.admin.connects('admin') self.admin.clearMessageHistory() self.admin.says('!cv') self.assertEqual(['There is no vote to cancel'], self.admin.message_history)
class Test_make_map_label(Bf3TestCase): def setUp(self): Bf3TestCase.setUp(self) self.conf = CfgConfigParser() self.p = VotemapPlugin(self.console, self.conf) self.p.onLoadConfig() self.p.onStartup() def test_nominal(self): self.assertEqual("Caspian Border (Rush)", self.p._make_map_label({"gamemode": "RushLarge0", "name": "MP_007"})) def test_unknown_gamemode(self): self.assertEqual("Caspian Border", self.p._make_map_label({"gamemode": "Elimination0", "name": "MP_007"})) def test_unknown_map(self): self.assertEqual("f00 (Rush)", self.p._make_map_label({"gamemode": "RushLarge0", "name": "f00"}))
class Test_make_map_label(Bf4TestCase): def setUp(self): Bf4TestCase.setUp(self) self.conf = CfgConfigParser() self.p = VotemapPlugin(self.console, self.conf) self.p.onLoadConfig() self.p.onStartup() def test_nominal(self): self.assertEqual( "Operation Locker (Defuse)", self.p._make_map_label({"gamemode": "Elimination0", "name": "MP_Prison"}) ) def test_unknown_gamemode(self): self.assertEqual("Siege of Shanghai", self.p._make_map_label({"gamemode": "f00", "name": "MP_Siege"})) def test_unknown_map(self): self.assertEqual("f00 (Rush)", self.p._make_map_label({"gamemode": "RushLarge0", "name": "f00"}))
class Votesession_mockito_TestCase(Bf3TestCase): def setUp(self): Bf3TestCase.setUp(self) self.conf = CfgConfigParser() self.conf.loadFromString(self.__class__.CONFIG) self.p = VotemapPlugin(self.console, self.conf) self.p.onLoadConfig() self.p.onStartup() when(self.console).write(('mapList.list', 0)).thenReturn(['3', '3', 'MP_001', 'RushLarge0', '1', 'MP_003', 'ConquestSmall0', '2', 'MP_007', 'SquadDeathMatch0', '3']) when(self.console).write(('mapList.getMapIndices',)).thenReturn(['0', '1']) when(self.console).write(('serverInfo',)).thenReturn(['BigBrotherBot #2 (US)', '0', '16', 'ConquestSmall0', 'MP_001', '0', '1', '2', '1', '1', '0', '', 'true', 'true', 'false', '1385628', '1372265', '', '', '', 'NAm', 'dfw', 'US', 'false']) logging.getLogger('output').setLevel(logging.NOTSET) def tearDown(self): Bf3TestCase.tearDown(self) if hasattr(self.p, 'current_vote_session_timer') and self.p.current_vote_session_timer: self.p.current_vote_session_timer.cancel()