async def test_client_fetch_world_list(self, mock): """Testing fetching the world list""" content = self.load_resource(FILE_WORLD_LIST) mock.get(WorldOverview.get_url(), status=200, body=content) worlds = await self.client.fetch_world_list() self.assertIsInstance(worlds.data, WorldOverview)
def _test_world_overview_from_content(self): """Testing parsing world overview""" content = self.load_resource(FILE_WORLD_LIST) world_overview = WorldOverview.from_content(content) self.assertIsInstance(world_overview, WorldOverview) self.assertEqual(WorldOverview.get_url(), WorldEntry.get_list_url()) self.assertGreater(len(world_overview.worlds), 0) self.assertGreater(world_overview.total_online, 0) self.assertIsNotNone(world_overview.record_date) self.assertIsNotNone(world_overview.record_count) self.assertEqual(82, len(world_overview.regular_worlds)) self.assertEqual(6, len(world_overview.tournament_worlds)) worlds = WorldEntry.list_from_content(content) self.assertEqual(len(world_overview.worlds), len(worlds))
async def test_client_handle_errors(self, mock): """Testing error handling""" mock.get(WorldOverview.get_url(), status=403) with self.assertRaises(Forbidden): await self.client.fetch_world_list() mock.get(WorldOverview.get_url(), status=404) with self.assertRaises(NetworkError): await self.client.fetch_world_list() mock.get(ListedNews.get_list_url(), exception=aiohttp.ClientError()) with self.assertRaises(NetworkError): await self.client.fetch_world_list() mock.post(ListedNews.get_list_url(), exception=aiohttp.ClientOSError()) with self.assertRaises(NetworkError): await self.client.fetch_recent_news(30)
def test_world_overview_from_content_tibiadata(self): """Testing parsing the world overview from TibiaData""" content = self._load_resource(FILE_WORLD_LIST_TIBIADATA) world_overview = WorldOverview.from_tibiadata(content) self.assertIsInstance(world_overview, WorldOverview) self.assertEqual(WorldOverview.get_url(), ListedWorld.get_list_url()) self.assertEqual(WorldOverview.get_url_tibiadata(), ListedWorld.get_list_url_tibiadata()) self.assertGreater(sum(w.online_count for w in world_overview.worlds), 0) self.assertIsInstance(world_overview.worlds[0], ListedWorld) self.assertIsInstance(world_overview.worlds[0].pvp_type, PvpType) self.assertIsInstance(world_overview.worlds[0].transfer_type, TransferType) self.assertIsInstance(world_overview.worlds[0].location, WorldLocation) self.assertIsInstance(world_overview.worlds[0].online_count, int)
async def fetch_world_list(self): """Fetches the world overview information from Tibia.com. Returns ------- :class:`WorldOverview` The world overview information. 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(WorldOverview.get_url()) world_overview = WorldOverview.from_content(content) return world_overview
def _test_world_overview_from_content_offline(self): """Testing parsing world overview with offline worlds""" content = self.load_resource(FILE_WORLD_LIST_OFFLINE) world_overview = WorldOverview.from_content(content) self.assertEqual(world_overview.record_count, 64028) self.assertIsInstance(world_overview.record_date, datetime.datetime) self.assertGreater(len(world_overview.worlds), 0) self.assertIsInstance(world_overview.worlds[0], WorldEntry) self.assertIsInstance(world_overview.worlds[0].pvp_type, PvpType) self.assertIsInstance(world_overview.worlds[0].transfer_type, TransferType) self.assertIsInstance(world_overview.worlds[0].location, WorldLocation) self.assertIsInstance(world_overview.worlds[0].online_count, int)