def test_spells(self): player = Player(data=MOCK_SEARCH_PLAYER, client=None) self.assertIsInstance(player.spells, list) for index, hero in enumerate(player.spells): self.assertIsInstance(hero, player.spell_cls) self.assertEqual(hero.name, SPELL_ORDER[index])
def test_legend_statistics(self): data = { "legendStatistics": { "legendTrophies": 4460, "bestSeason": { "id": "2016-01", "rank": 3708, "trophies": 5085 }, "bestVersusSeason": { "id": "2018-06", "rank": 19207, "trophies": 4827 }, "currentSeason": { "rank": 69, "trophies": 5470 }, } } player = Player(data=data, client=None) stats = LegendStatistics(data=data["legendStatistics"]) self.assertEqual(player.legend_statistics, stats) self.assertIsInstance(player.legend_statistics, LegendStatistics) self.assertIsInstance(player.legend_statistics.legend_trophies, int) self.assertIsInstance(player.legend_statistics.best_season, Season) self.assertNotEqual(player.legend_statistics.current_season, player.legend_statistics.previous_season)
def test_heroes(self): player = Player(data=MOCK_SEARCH_PLAYER, client=None) self.assertIsInstance(player.heroes, list) valid_hero_order = [ n for n in HERO_ORDER if n in set(h.name for h in player.heroes) ] for index, hero in enumerate(player.heroes): self.assertIsInstance(hero, player.hero_cls) self.assertEqual(hero.name, valid_hero_order[index]) get_hero = player.get_hero(hero.name) self.assertEqual(hero, get_hero) get_nonsense_hero = player.get_hero("this is a nonsense string") self.assertIsNone(get_nonsense_hero)
def test_achievements(self): player = Player(data=MOCK_SEARCH_PLAYER, client=None) self.assertIsInstance(player.achievements, list) valid_achievement_order = [ n for n in ACHIEVEMENT_ORDER if n in set(a.name for a in player.achievements) ] for index, achievement in enumerate(player.achievements): self.assertIsInstance(achievement, player.achievement_cls) self.assertEqual(achievement.name, valid_achievement_order[index]) get_achievement = player.get_achievement(achievement.name) self.assertEqual(get_achievement, achievement) get_nonsense_achievement = player.get_achievement( "this is a nonsense string") self.assertIsNone(get_nonsense_achievement)
def test_labels(self): data = [ { "id": 57000000, "name": "Clan Wars" }, { "id": 57000001, "name": "Clan War League" }, { "id": 57000015, "name": "Veteran" }, ] player = Player(data=MOCK_SEARCH_PLAYER, client=None) for index, case in enumerate(data): label = Label(data=case, client=None) self.assertEqual(player.labels[index], label) self.assertIsInstance(player.labels[index], Label) self.assertIsInstance(player.labels, list)
def test_troops(self): player = Player(data=MOCK_SEARCH_PLAYER, client=None) self.assertIsInstance(player.troops, list) for troop in player.troops: self.assertIsInstance(troop, player.troop_cls) # we can't use the full HOME_TROOP_ORDER in case the player hasn't unlocked a specific troop troop_names = set(t.name for t in player.troops) valid_home_troop_order = [ name for name in HOME_TROOP_ORDER if name in troop_names ] valid_builder_troop_order = [ name for name in BUILDER_TROOPS_ORDER if name in troop_names ] valid_siege_machine_order = [ name for name in SIEGE_MACHINE_ORDER if name in troop_names ] for index, troop in enumerate(player.home_troops): self.assertIn(troop, player.troops) self.assertTrue(troop.is_home_base) self.assertIsInstance(troop, player.troop_cls) self.assertEqual(troop.name, valid_home_troop_order[index]) for index, troop in enumerate(player.builder_troops): self.assertIn(troop, player.troops) self.assertTrue(troop.is_builder_base) self.assertIsInstance(troop, player.troop_cls) self.assertEqual(troop.name, valid_builder_troop_order[index]) for index, troop in enumerate(player.siege_machines): self.assertIn(troop, player.troops) self.assertTrue(troop.is_home_base) self.assertIsInstance(troop, player.troop_cls) self.assertEqual(troop.name, valid_siege_machine_order[index])
def test_versus_attack_wins(self): data = [{"versusBattleWins": 1234}, {"versusBattleWins": 0}, {}] for case in data: player = Player(data=case, client=None) self.assertEqual(player.versus_attack_wins, case.get("versusBattleWins"))
def test_best_versus_trophies(self): data = [{"bestVersusTrophies": 4467}, {"bestVersusTrophies": 0}, {}] for case in data: player = Player(data=case, client=None) self.assertEqual(player.best_versus_trophies, case.get("bestVersusTrophies"))
def test_builder_hall(self): data = [{"builderHallLevel": 8}, {"builderHallLevel": 0}, {}] for case in data: player = Player(data=case, client=None) self.assertEqual(player.builder_hall, case.get("builderHallLevel", 0))
def test_town_hall_weapon(self): data = [{"townHallWeaponLevel": 4}, {"townHallWeaponLevel": 0}, {}] for case in data: player = Player(data=case, client=None) self.assertEqual(player.town_hall_weapon, case.get("townHallWeaponLevel"))
def test_town_hall(self): data = [{"townHallLevel": 13}, {"townHallLevel": 6}, {}] for case in data: player = Player(data=case, client=None) self.assertEqual(player.town_hall, case.get("townHallLevel"))
def test_war_stars(self): data = [{"warStars": 1234}, {"warStars": 0}, {}] for case in data: player = Player(data=case, client=None) self.assertEqual(player.war_stars, case.get("warStars"))