def test_map_InvalidRoundsPerMap(self): # WHEN when(self.parser).changeMap('XP4_Rubble', gamemode_id="CaptureTheFlag0", number_of_rounds=2).thenRaise( CommandFailedError(["InvalidRoundsPerMap"])) self.joe.says("!map talah") # THEN self.assertListEqual(['number of rounds must be 1 or greater'], self.joe.message_history)
def test_map_Full(self): # WHEN when(self.parser).changeMap('XP4_Rubble', gamemode_id="CaptureTheFlag0", number_of_rounds=2).thenRaise( CommandFailedError(["Full"])) self.joe.says("!map talah") # THEN self.assertListEqual(['map list maximum size has been reached'], self.joe.message_history)
def test_frostbite_error(self): when(self.console).write(('reservedSlotsList.clear', )).thenRaise( CommandFailedError(['f00'])) self.moderator.connects("moderator") self.moderator.message_history = [] self.moderator.says("!vipclear") self.assertEqual(["Error: f00"], self.moderator.message_history)
def test_frostbite_error(self, sleep_mock): when(self.console).write( ('admin.shutDown', )).thenRaise(CommandFailedError(['fOO'])) self.superadmin.connects("god") self.superadmin.message_history = [] self.superadmin.says("!serverreboot") self.assertEqual(['Error: fOO'], self.superadmin.message_history)
def test_frostbite_error_SoldierNotAlive(self): self.joe.connects("joe") self.superadmin.connects('superadmin') when(self.console).write(('admin.killPlayer', 'joe')).thenRaise(CommandFailedError(['SoldierNotAlive'])) self.superadmin.message_history = [] self.superadmin.says("!kill joe") self.assertEqual(['Joe is already dead'], self.superadmin.message_history)
def test_read_cvars_with_error(self): self.console.write.side_effect = CommandFailedError('theError') self.p = self.p client = Mock() self.p.load_server_config(client, "theConfName", ("vars.withnoarg",)) self.assertTrue(self.console.write.called) self.console.write.assert_called_with(('vars.withnoarg',)) client.message.assert_was_called_with('Error "theError" received at line 1 when sending "vars.withnoarg" to server')
def test_frostbite_error(self): self.joe.connects("joe") self.superadmin.connects('superadmin') when(self.console).write(('admin.killPlayer', 'joe')).thenRaise(CommandFailedError(['f00'])) self.superadmin.message_history = [] self.superadmin.says("!kill joe") self.assertEqual(["Error: ['f00']"], self.superadmin.message_history)
def test_map_Full(self): # WHEN with patch.object(self.parser, "changeMap", side_effect=CommandFailedError(["Full"])): self.joe.says("!map bank") # THEN self.assertListEqual(['map list maximum size has been reached'], self.joe.message_history)
def test_frostbite_error(self): self.joe.connects("joe") self.superadmin.connects('superadmin') when(self.console).write( ('reservedSlotsList.add', 'Joe')).thenRaise(CommandFailedError(['f00'])) self.superadmin.clearMessageHistory() self.superadmin.says("!vipadd joe") self.assertEqual(["Error: ['f00']"], self.superadmin.message_history)
def test_no_argument_while_unknown(self): when(self.console).write( ('vars.idleTimeout', )).thenRaise(CommandFailedError(['foo'])) self.superadmin.connects("god") self.superadmin.message_history = [] self.superadmin.says("!idle") self.assertEqual(['Idle kick is [unknown]'], self.superadmin.message_history) self.assertFalse(self.p.error.called)
def test_frostbite_error_PlayerNotInList(self): self.joe.connects("joe") self.superadmin.connects('superadmin') when(self.console).write( ('reservedSlotsList.remove', u'Joe')).thenRaise(CommandFailedError(['PlayerNotInList'])) self.superadmin.clearMessageHistory() self.superadmin.says("!vipremove joe") self.assertEqual(["There is no VIP named 'Joe'"], self.superadmin.message_history)
def test_map_InvalidGameModeOnMap(self): # WHEN when(self.parser).changeMap('XP4_Rubble', gamemode_id="CaptureTheFlag0", number_of_rounds=2).thenRaise( CommandFailedError(["InvalidGameModeOnMap"])) self.joe.says("!map talah") # THEN self.assertListEqual( ['Talah market cannot be played with gamemode Capture the Flag', 'supported gamemodes are : Conquest Assault64, Conquest Assault, Rush, Squad Rush, Squad Deathmatch, Team Deathmatch, Gun master, Scavenger' ], self.joe.message_history)
def test_write_cvars_with_error(self): self.console.write.side_effect = CommandFailedError('theError') self.p = self.p client = Mock() self.p.load_server_config(client, "theConfName", ("vars.theCvar theValue", )) self.assertTrue(self.console.write.called) self.console.write.assert_any_call(('vars.theCvar', 'theValue')) client.message.assert_any_call( 'Error "theError" received at line 1 when sending "vars.theCvar theValue" to server' )
def test_map_InvalidRoundsPerMap(self): # WHEN when(self.parser).changeMap('mp_bank', gamemode_id="TurfWarSmall0", number_of_rounds=2).thenRaise( CommandFailedError( ["InvalidRoundsPerMap"])) self.joe.says("!map bank") # THEN self.assertListEqual(['number of rounds must be 1 or greater'], self.joe.message_history)
def write(data): if type(data) in (tuple, list): if data[0].lower() == 'banlist.list': offset = 0 if len(data) > 1: try: offset = int(data[1]) except ValueError: raise CommandFailedError(['InvalidArguments']) # simulate that the Frostbite2 server responds with 5 bans at most for the banList.list command bans_to_send = self.__class__.bans[offset:offset + 5] return list(reduce(tuple.__add__, bans_to_send, tuple())) return []
def test_map_InvalidGameModeOnMap(self): self.parser.game.gameType = "Hotwire0" # WHEN when(self.parser).changeMap('mp_bank', gamemode_id="Hotwire0", number_of_rounds=2).thenRaise( CommandFailedError( ["InvalidGameModeOnMap"])) self.joe.says("!map bank") # THEN self.assertListEqual([ 'Bank Job cannot be played with gamemode Hotwire', 'supported gamemodes are : Conquest Large, Conquest Small, Heist, Blood Money, Crosshair, Rescue, Team Deathmatch' ], self.joe.message_history)
def write(data): if type(data) in (tuple, list): if data[0].lower() == 'maplist.list': offset = 0 if len(data) > 1: try: offset = int(data[1]) except ValueError: raise CommandFailedError('InvalidArguments') # simulate that the Frostbite2 server responds with 5 maps at most for the mapList.list command maps_to_send = self.__class__.maps[offset:offset + 5] return [len(maps_to_send), 3] + list(reduce(tuple.__add__, maps_to_send, tuple())) elif data[0].lower() == 'maplist.getmapindices': return self.__class__.map_indices return []
def test_frostbite_error(self): self.joe.connects("joe") self.joe.team = b3.TEAM_BLUE self.joe.teamId = 1 self.joe.squad = 1 # simulate Frostbite error when moving a player when(self.console).write(('admin.movePlayer', 'joe', 2, 0, 'true')).thenRaise( CommandFailedError(['SetTeamFailed'])) self.superadmin.connects('superadmin') self.superadmin.message_history = [] self.superadmin.says("!changeteam joe") self.assertEqual(1, self.joe.teamId) self.assertEqual(["Error, server replied ['SetTeamFailed']"], self.superadmin.message_history)
def test_frostbite_error(self): self.joe.connects("joe") self.joe.team = b3.TEAM_BLUE self.joe.teamId = 1 self.joe.squad = 1 self.moderator.connects("moderator") self.moderator.team = b3.TEAM_RED self.moderator.teamId = 2 self.moderator.squad = 2 # simulate Frostbite error when moving a player self.p._movePlayer = Mock( side_effect=CommandFailedError(['SetTeamFailed'])) self.superadmin.connects('superadmin') self.superadmin.message_history = [] self.superadmin.says("!swap joe moder") self.assertEqual(1, len(self.superadmin.message_history)) self.assertEqual( "Error while trying to swap joe with moderator. (SetTeamFailed)", self.superadmin.message_history[0])
def my_write(*args): if len(args) and len(args[0]) and 'mapList.add' == args[0][0]: raise CommandFailedError('theError') return []
def setCvar_proxy(var_name, value): if var_name == 'vehicleSpawnAllowed': raise CommandFailedError(['InvalidArguments']) else: return Mock()
def getCvar_proxy(var_name): if var_name == 'vehicleSpawnAllowed': raise CommandFailedError(['foo']) else: return Mock()
def test_exception_InvalidPlayerName(self): when(self.parser).write( ('player.isAlive', 'Foobar')).thenRaise(CommandFailedError(['InvalidPlayerName'])) self.assertEqual(b3.STATE_UNKNOWN, self.foobar.state)