def test_handles_game_end_no_update(self): fun = funes.funes() red_ids = [10, 15, 12] blue_ids = [11, 14, 13] teams = (red_ids, blue_ids) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([3, 1], fun.get_teams_history('ad', teams, aggregate=True)) # aborted minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 7, 15, True) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([3, 1], fun.get_teams_history('ad', teams, aggregate=True)) # no team won minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 7, 10) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([3, 1], fun.get_teams_history('ad', teams, aggregate=True)) # empty team minqlx_fake.run_game(PLAYER_ID_MAP, [], blue_ids, 7, 15) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([3, 1], fun.get_teams_history('ad', teams, aggregate=True))
def test_loads_history_invalid_json(self): fun = funes.funes() self.assertEqual([], fun.get_history()) # still usable minqlx_fake.run_game(PLAYER_ID_MAP, [15, 12], [13, 16], 7, 15) teams = ((34, 12), (56, 78)) self.assertEqual([0, 0], fun.get_teams_history('ad', teams)) self.assertEqual([0, 0], fun.get_teams_history('ad', teams, aggregate=True))
def test_registers_commands_and_hooks(self): fun = funes.funes() self.assertEqual( ['funes'], [cmd[0] for cmd in minqlx_fake.Plugin.registered_commands]) self.assertEqual( ['game_start', 'game_end'], [hook[0] for hook in minqlx_fake.Plugin.registered_hooks])
def test_saves_history_same_date(self, m): fun = funes.funes() self.assertEqual(HISTORY_DATA, fun.get_history()) red_ids = [15, 12] blue_ids = [13, 16] minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 15, 14) expected = copy.deepcopy(HISTORY_DATA) expected.append(['2018-10', 'ad', [12, 15], [13, 16], 15, 14]) self.assertSavedJson(expected, m)
def test_handles_game_start_new_player(self): fun = funes.funes() # id 90 isn't in data minqlx_fake.start_game(PLAYER_ID_MAP, [11, 13, 14], [12, 10, 90], 7, 15) msgs = minqlx_fake.Plugin.messages # session, historic self.assertInMessages( 'fundi, p-lu-k, renga 0 v 0 cthulhu, mandiok, toro') self.assertInMessages( 'fundi, p-lu-k, renga 0 v 0 cthulhu, mandiok, toro')
def test_get_teams_history(self): fun = funes.funes() teams = ((10, 11, 12), (15, 13, 14)) self.assertEqual([1, 0], fun.get_teams_history('ad', teams)) self.assertEqual([5, 2], fun.get_teams_history('ad', teams, aggregate=True)) # change order teams = ((15, 13, 14), (10, 11, 12)) self.assertEqual([0, 1], fun.get_teams_history('ad', teams)) self.assertEqual([2, 5], fun.get_teams_history('ad', teams, aggregate=True))
def test_handles_game_start(self): fun = funes.funes() minqlx_fake.start_game(PLAYER_ID_MAP, [11, 13, 14], [12, 10, 15], 7, 15) # session, historic self.assertInMessages('fundi, p-lu-k, renga 1 v 2 coco, mandiok, toro') self.assertInMessages(' 1 v 3 (since 2018w10)') # flip red and blue teams: minqlx_fake.Plugin.reset_log() minqlx_fake.start_game(PLAYER_ID_MAP, [12, 10, 15], [11, 13, 14], 15, 1) msgs = minqlx_fake.Plugin.messages # session, historic self.assertInMessages('coco, mandiok, toro 2 v 1 fundi, p-lu-k, renga') self.assertInMessages(' 3 v 1 (since 2018w10)')
def test_handles_game_end(self, m): fun = funes.funes() red_ids = [10, 11, 12] blue_ids = [15, 13, 14] teams = (red_ids, blue_ids) self.assertEqual([1, 0], fun.get_teams_history('ad', teams)) self.assertEqual([5, 2], fun.get_teams_history('ad', teams, aggregate=True)) # blue won minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 7, 15) self.assertEqual([1, 1], fun.get_teams_history('ad', teams)) self.assertEqual([5, 3], fun.get_teams_history('ad', teams, aggregate=True)) # red won minqlx_fake.run_game(PLAYER_ID_MAP, red_ids, blue_ids, 15, 1) self.assertEqual([2, 1], fun.get_teams_history('ad', teams)) self.assertEqual([6, 3], fun.get_teams_history('ad', teams, aggregate=True))
def test_handles_game_end_player_left(self, m): fun = funes.funes() red_ids = [10, 11, 12] blue_ids = [15, 13, 14] teams = (red_ids, blue_ids) self.assertEqual([1, 0], fun.get_teams_history('ad', teams)) self.assertEqual([5, 2], fun.get_teams_history('ad', teams, aggregate=True)) # start game with 2v2 players minqlx_fake.start_game(PLAYER_ID_MAP, red_ids, blue_ids, 7, 15) current_teams = fun.teams() self.assertEqual(3, len(fun.teams()['red'])) self.assertEqual(3, len(fun.teams()['blue'])) # one player leaves. current_teams['red'].pop() minqlx_fake.Plugin.set_players_by_team(current_teams) # blue won. should update according to starting teams. minqlx_fake.end_game() self.assertEqual([1, 1], fun.get_teams_history('ad', teams)) self.assertEqual([5, 3], fun.get_teams_history('ad', teams, aggregate=True))
def test_funes(self): fun = funes.funes() player_names = [PLAYER_ID_MAP[id].name for id in PLAYER_ID_MAP] # no players loaded yet minqlx_fake.call_command('!funes') for player_name in player_names: self.assertNotInMessages(player_name) # no matches today and no history minqlx_fake.Plugin.reset_log() minqlx_fake.Plugin.set_players_by_team({ 'red': [PLAYER_ID_MAP[13], PLAYER_ID_MAP[16]], 'blue': [PLAYER_ID_MAP[12], PLAYER_ID_MAP[10]] }) minqlx_fake.call_command('!funes') self.assertInMessages('Since 2018w10: no history with these players.') self.assertInMessages('Today: no history with these players.') # no matches with this game type (but one with a different one) minqlx_fake.Plugin.reset_log() minqlx_fake.Plugin.set_players_by_team({ 'red': [PLAYER_ID_MAP[15], PLAYER_ID_MAP[16]], 'blue': [PLAYER_ID_MAP[10], PLAYER_ID_MAP[12]] }) minqlx_fake.call_command('!funes') self.assertInMessages('Since 2018w10: no history with these players.') self.assertInMessages('Today: no history with these players.') # no matches today, some history minqlx_fake.Plugin.reset_log() minqlx_fake.Plugin.set_players_by_team({ 'red': [PLAYER_ID_MAP[13], PLAYER_ID_MAP[16], PLAYER_ID_MAP[15]], 'blue': [PLAYER_ID_MAP[12], PLAYER_ID_MAP[10], PLAYER_ID_MAP[14]] }) minqlx_fake.call_command('!funes') msgs = minqlx_fake.Plugin.messages self.assertInMessages( 'mandiok, toro, blues 0 v 3 p-lu-k, renga, coco') self.assertInMessages( 'mandiok, p-lu-k, blues 2 v 0 toro, renga, coco') self.assertInMessages( 'mandiok, toro, renga 1 v 0 p-lu-k, coco, blues') self.assertInMessages( 'mandiok, toro, coco 0 v 1 p-lu-k, renga, blues') self.assertInMessages('Today: no history with these players.') # both matches today and history minqlx_fake.Plugin.reset_log() minqlx_fake.Plugin.set_players_by_team({ 'red': [PLAYER_ID_MAP[10], PLAYER_ID_MAP[11], PLAYER_ID_MAP[12]], 'blue': [PLAYER_ID_MAP[13], PLAYER_ID_MAP[14], PLAYER_ID_MAP[15]] }) minqlx_fake.call_command('!funes') msgs = minqlx_fake.Plugin.messages self.assertInMessages( 'mandiok, toro, coco 2 v 1 fundi, p-lu-k, renga') self.assertInMessages( 'mandiok, toro, p-lu-k 1 v 1 fundi, renga, coco') self.assertInMessages( 'mandiok, fundi, toro 1 v 0 p-lu-k, renga, coco') self.assertInMessages( 'mandiok, fundi, toro 5 v 2 p-lu-k, renga, coco') self.assertInMessages( 'mandiok, toro, coco 3 v 1 fundi, p-lu-k, renga') self.assertInMessages( 'mandiok, toro, p-lu-k 1 v 1 fundi, renga, coco') self.assertInMessages( 'mandiok, toro, renga 0 v 1 fundi, p-lu-k, coco')
def test_loads_history(self): fun = funes.funes() self.assertEqual(HISTORY_DATA, fun.get_history())