def test_listed_guild_from_content(self): """Testing parsing the list of guilds of a world""" content = self.load_resource(FILE_GUILD_LIST) guilds = ListedGuild.list_from_content(content) self.assertTrue(guilds) self.assertIsNotNone(ListedGuild.get_world_list_url(guilds[0].world)) self.assertEqual("Zuna", guilds[0].world) self.assertTrue(guilds[0].active) self.assertFalse(guilds[-1].active)
def test_listed_guild_from_tibiadata(self): """Testing parsing a guild list from TibiaData""" content = self._load_resource(FILE_GUILD_TIBIADATA_LIST) guilds = ListedGuild.list_from_tibiadata(content) self.assertTrue(guilds) self.assertIsNotNone( ListedGuild.get_world_list_url_tibiadata(guilds[0].world)) self.assertEqual("Zunera", guilds[0].world) self.assertIsInstance(guilds[0], ListedGuild) self.assertTrue(guilds[0].active) self.assertFalse(guilds[-1].active)
async def test_client_fetch_world_guilds(self, mock): """Testing fetching a world's guild list""" world = "Zuna" content = self.load_resource(FILE_GUILD_LIST) mock.get(ListedGuild.get_world_list_url(world), status=200, body=content) guilds = await self.client.fetch_world_guilds(world) self.assertIsInstance(guilds.data[0], ListedGuild)
async def fetch_world_guilds(self, world: str): """Fetches the list of guilds in a world from Tibia.com Parameters ---------- world: :class:`str` The name of the world. Returns ------- list of :class:`ListedGuild` The lists of guilds in the world. Raises ------ Forbidden If a 403 Forbidden error was returned. This usually means that Tibia.com is rate-limiting the client because of too many requests. NetworkError If there's any connection errors during the request. """ content = await self._get(ListedGuild.get_world_list_url(world)) guilds = ListedGuild.list_from_content(content) return guilds
def test_listed_guild_from_content_unrelated(self): """Testing parsing and unrelated section""" content = self.load_resource(self.FILE_UNRELATED_SECTION) with self.assertRaises(InvalidContent): ListedGuild.list_from_content(content)
def test_listed_guild_from_content_not_found(self): """Testing parsing the guild list of a world that doesn't exist""" content = self.load_resource(FILE_GUILD_LIST_NOT_FOUND) guilds = ListedGuild.list_from_content(content) self.assertIsNone(guilds)
def test_listed_guild_from_tibiadata_invalid_json(self): """Testing parsing an invalid json""" with self.assertRaises(InvalidContent): ListedGuild.list_from_tibiadata("<b>Not JSON</b>")
def test_listed_guild_from_tibiadata_unrelated_section(self): """Testing parsing an unrelated section""" content = self._load_resource( tests.tests_character.FILE_CHARACTER_TIBIADATA) with self.assertRaises(InvalidContent): ListedGuild.list_from_tibiadata(content)
def test_listed_guild_from_tibiadata_not_found(self): """Testing parsing a non existent guild""" content = self._load_resource(FILE_GUILD_TIBIADATA_LIST_NOT_FOUND) guilds = ListedGuild.list_from_tibiadata(content) # There's no way to tell if the searched world doesn't exist or has no guilds self.assertEqual(guilds, [])