def test_highscores_from_content_battleye_and_pvp_filters(self): """Testing parsing Highscores""" content = self.load_resource(FILE_HIGHSCORES_BATTLEYE_PVP_FILTER) highscores = Highscores.from_content(content) self.assertEqual(None, highscores.world) self.assertEqual(VocationFilter.ALL, highscores.vocation) self.assertEqual(Category.EXPERIENCE, highscores.category) self.assertEqual(BattlEyeHighscoresFilter.INITIALLY_PROTECTED, highscores.battleye_filter) self.assertEqual(1000, highscores.results_count) self.assertEqual(1, highscores.from_rank) self.assertEqual(50, highscores.to_rank) self.assertEqual(1, highscores.page) self.assertEqual(20, highscores.total_pages) self.assertEqual(3, len(highscores.pvp_types_filter)) self.assertIsNotNone(highscores.url) self.assertEqual(datetime.timedelta(minutes=27), highscores.last_updated) for entry in highscores.entries: self.assertIsInstance(entry, HighscoresEntry) self.assertIsInstance(entry.name, str) self.assertIsInstance(entry.vocation, Vocation) self.assertIsInstance(entry.rank, int) self.assertIsInstance(entry.value, int) self.assertIsInstance(entry.level, int)
async def fetch_highscores_page(self, world, category=Category.EXPERIENCE, vocation=VocationFilter.ALL, page=1): """Fetches a single highscores page from Tibia.com Parameters ---------- world: :class:`str` The world to search the highscores in. category: :class:`Category` The highscores category to search, by default Experience. vocation: :class:`VocationFilter` The vocation filter to use. No filter used by default. page: :class:`int` The page to fetch, by default the first page is fetched. Returns ------- :class:`Highscores` The highscores information or ``None`` if not found. 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( Highscores.get_url(world, category, vocation, page)) highscores = Highscores.from_content(content) return highscores
def test_highscores_from_content(self): """Testing parsing Highscores""" content = self.load_resource(FILE_HIGHSCORES_FULL) highscores = Highscores.from_content(content) self.assertEqual("Estela", highscores.world) self.assertEqual(VocationFilter.KNIGHTS, highscores.vocation) self.assertEqual(Category.MAGIC_LEVEL, highscores.category) self.assertEqual(BattlEyeHighscoresFilter.ANY_WORLD, highscores.battleye_filter) self.assertEqual(1983, highscores.results_count) self.assertEqual(38, highscores.from_rank) self.assertEqual(38, highscores.to_rank) self.assertEqual(4, highscores.page) self.assertEqual(40, highscores.total_pages) self.assertIsNotNone(highscores.get_page_url(1)) self.assertIsNotNone(highscores.url) self.assertIsNotNone(highscores.next_page_url) self.assertIsNotNone(highscores.previous_page_url) self.assertEqual(datetime.timedelta(minutes=6), highscores.last_updated) for entry in highscores.entries: self.assertIsInstance(entry, HighscoresEntry) self.assertIsInstance(entry.name, str) self.assertIsInstance(entry.vocation, Vocation) self.assertIsInstance(entry.rank, int) self.assertIsInstance(entry.value, int) self.assertIsInstance(entry.level, int) self.assertEqual("Estela", entry.world)
def _test_highscores_from_content_no_results(self): """Testing parsing highscores with no results (first day of a new world)""" content = self.load_resource(FILE_HIGHSCORES_NO_RESULTS) highscores = Highscores.from_content(content) self.assertIsInstance(highscores, Highscores) self.assertEqual(highscores.world, "Unica") self.assertEqual(highscores.category, Category.EXPERIENCE) self.assertEqual(highscores.vocation, VocationFilter.ALL) self.assertEqual(highscores.total_pages, 0) self.assertEqual(len(highscores.entries), 0)
def test_highscore_changes(self): content = self.load_resource( "website_changes/1_community_highscores.txt") highscores = Highscores.from_content(content) self.assertIsNone(highscores.world) self.assertEqual(Category.EXPERIENCE, highscores.category) self.assertEqual(VocationFilter.ALL, highscores.vocation) self.assertEqual(1000, highscores.results_count) self.assertEqual(1, highscores.page) self.assertEqual(20, highscores.total_pages) first_entry = highscores.entries[0] self.assertEqual("Goraca", first_entry.name) self.assertEqual(Vocation.MASTER_SORCERER, first_entry.vocation) self.assertEqual(1904, first_entry.level) self.assertEqual(114_797_203_877, first_entry.value)
def test_highscores_from_content_loyalty(self): """Testing parsing experience loyalty""" content = self._load_resource(FILE_HIGHSCORES_LOYALTY) highscores = Highscores.from_content(content) self.assertEqual(highscores.world, "Calmera") self.assertEqual(highscores.vocation, VocationFilter.PALADINS) self.assertEqual(highscores.category, Category.LOYALTY_POINTS) self.assertEqual(highscores.results_count, 65) self.assertEqual(highscores.total_pages, 3) for entry in highscores.entries: self.assertIsInstance(entry, LoyaltyHighscoresEntry) self.assertIsInstance(entry.name, str) self.assertIsInstance(entry.vocation, Vocation) self.assertIsInstance(entry.rank, int) self.assertIsInstance(entry.value, int) self.assertIsInstance(entry.title, str)
def test_highscores_from_content_highscores(self): """Testing parsing experience highscores""" content = self._load_resource(FILE_HIGHSCORES_EXPERIENCE) highscores = Highscores.from_content(content) self.assertEqual(highscores.world, "Gladera") self.assertEqual(highscores.vocation, VocationFilter.PALADINS) self.assertEqual(highscores.category, Category.EXPERIENCE) self.assertEqual(highscores.results_count, 300) self.assertEqual(highscores.total_pages, 12) for entry in highscores.entries: self.assertIsInstance(entry, ExpHighscoresEntry) self.assertIsInstance(entry.name, str) self.assertIsInstance(entry.vocation, Vocation) self.assertIsInstance(entry.rank, int) self.assertIsInstance(entry.value, int) self.assertIsInstance(entry.level, int)
def test_highscores_from_content(self): """Testing parsing Highscores""" content = self._load_resource(FILE_HIGHSCORES_FULL) highscores = Highscores.from_content(content) self.assertEqual(highscores.world, "Estela") self.assertEqual(highscores.vocation, VocationFilter.KNIGHTS) self.assertEqual(highscores.category, Category.MAGIC_LEVEL) self.assertEqual(highscores.results_count, 300) self.assertEqual(highscores.from_rank, 76) self.assertEqual(highscores.to_rank, 100) self.assertEqual(highscores.page, 4) self.assertEqual(highscores.total_pages, 12) self.assertIsNotNone(highscores.url) for entry in highscores.entries: self.assertIsInstance(entry, HighscoresEntry) self.assertIsInstance(entry.name, str) self.assertIsInstance(entry.vocation, Vocation) self.assertIsInstance(entry.rank, int) self.assertIsInstance(entry.value, int)
def test_highscores_from_content(self): """Testing parsing Highscores""" content = self.load_resource(FILE_HIGHSCORES_FULL) highscores = Highscores.from_content(content) self.assertEqual("Estela", highscores.world) self.assertEqual(VocationFilter.KNIGHTS, highscores.vocation) self.assertEqual(Category.MAGIC_LEVEL, highscores.category) self.assertEqual(1932, highscores.results_count) self.assertEqual(31, highscores.from_rank) self.assertEqual(31, highscores.to_rank) self.assertEqual(4, highscores.page) self.assertEqual(39, highscores.total_pages) self.assertIsNotNone(highscores.url) self.assertEqual(datetime.timedelta(minutes=2), highscores.last_updated) for entry in highscores.entries: self.assertIsInstance(entry, HighscoresEntry) self.assertIsInstance(entry.name, str) self.assertIsInstance(entry.vocation, Vocation) self.assertIsInstance(entry.rank, int) self.assertIsInstance(entry.value, int) self.assertEqual("Estela", entry.world)
def test_highscores_from_content_unrelated_section(self): """Testing parsing an unrelated section""" content = self.load_resource(self.FILE_UNRELATED_SECTION) with self.assertRaises(InvalidContent): Highscores.from_content(content)
def test_highscores_from_content_empty(self): """Testing parsing highscores when empty (world doesn't exist)""" content = self.load_resource(FILE_HIGHSCORES_EMPTY) highscores = Highscores.from_content(content) self.assertIsNone(highscores)
def test_highscores_from_content_empty(self): """Testing parsing highscores empty highscores""" content = self._load_resource(FILE_HIGHSCORES_EMPTY) highscores = Highscores.from_content(content) self.assertIsNone(highscores)