예제 #1
0
    async def fetch_tournament_leaderboard(self,
                                           tournament_cycle,
                                           world,
                                           page=1):
        """Fetches a tournament leaderboard from Tibia.com

        Parameters
        ----------
        tournament_cycle: :class:`int`
            The cycle of the tournament. if unspecified, it will get the currently running tournament.
        world: :class:`str`
            The name of the world to get the leaderboards for.
        page: :class:`int`
            The desired leaderboards page, by default 1 is used.

        Returns
        -------
        :class:`TournamentLeaderboard`
            The tournament's leaderboard if found, ``None`` otherwise.

        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(
            TournamentLeaderboard.get_url(world, tournament_cycle, page))
        tournament_leaderboard = TournamentLeaderboard.from_content(content)
        return tournament_leaderboard
예제 #2
0
    def test_tournament_leaderboard_from_content_ended(self):
        """Testing parsing the leaderboards for a tournament that already ended."""
        content = self.load_resource(FILE_TOURNAMENT_LEADERBOARD_ENDED)
        leaderboard = TournamentLeaderboard.from_content(content)

        self.assertIsInstance(leaderboard.tournament, ListedTournament)
        self.assertEqual("GLORY", leaderboard.tournament.title)
        self.assertIsInstance(leaderboard.tournament.start_date, datetime.date)
        self.assertIsInstance(leaderboard.tournament.end_date, datetime.date)
        self.assertEqual(datetime.timedelta(days=7), leaderboard.tournament.duration)
        self.assertEqual(3, leaderboard.tournament.cycle)
        self.assertEqual(1, leaderboard.from_rank)
        self.assertEqual(65, len(leaderboard.entries))
        self.assertEqual(1, leaderboard.total_pages)
        self.assertEqual(65, leaderboard.results_count)
        self.assertEqual("Endebra", leaderboard.world)
예제 #3
0
    def test_tournament_leaderboard_from_content_no_data(self):
        """Testing parsing the leaderboards's when there's no data."""
        content = self._load_resource(FILE_TOURNAMENT_LEADERBOARD_NO_DATA)
        leaderboard = TournamentLeaderboard.from_content(content)

        self.assertIsInstance(leaderboard.tournament, ListedTournament)
        self.assertEqual("TRIUMPH", leaderboard.tournament.title)
        self.assertIsNone(leaderboard.tournament.start_date)
        self.assertIsNone(leaderboard.tournament.end_date)
        self.assertIsNone(leaderboard.tournament.duration)
        self.assertEqual(4, leaderboard.tournament.cycle)
        self.assertEqual(0, leaderboard.from_rank)
        self.assertEqual(0, leaderboard.to_rank)
        self.assertEqual(0, len(leaderboard.entries))
        self.assertEqual(0, leaderboard.page)
        self.assertEqual(0, leaderboard.total_pages)
        self.assertEqual(0, leaderboard.results_count)
        self.assertEqual("Endebra", leaderboard.world)
예제 #4
0
    def test_tournament_leaderboard_from_content_running(self):
        """Testing parsing the leaderboards for a tournament that is currently running."""
        content = self._load_resource(FILE_TOURNAMENT_LEADERBOARD_CURRENT)
        leaderboard = TournamentLeaderboard.from_content(content)

        self.assertIsInstance(leaderboard.tournament, ListedTournament)
        self.assertEqual("TRIUMPH", leaderboard.tournament.title)
        self.assertIsNone(leaderboard.tournament.start_date)
        self.assertIsNone(leaderboard.tournament.end_date)
        self.assertIsNone(leaderboard.tournament.duration)
        self.assertEqual(4, leaderboard.tournament.cycle)
        self.assertEqual(1, leaderboard.from_rank)
        self.assertEqual(100, leaderboard.to_rank)
        self.assertEqual(100, len(leaderboard.entries))
        self.assertEqual(1, leaderboard.page)
        self.assertEqual(2, leaderboard.total_pages)
        self.assertEqual(198, leaderboard.results_count)
        self.assertEqual("Endebra", leaderboard.world)
예제 #5
0
 def test_tournament_leaderboards_from_content_unrelated(self):
     """Testing parsing an unrelated tibia.com section"""
     content = self._load_resource(self.FILE_UNRELATED_SECTION)
     with self.assertRaises(InvalidContent):
         TournamentLeaderboard.from_content(content)
예제 #6
0
    def test_tournament_leaderboard_from_content_selector(self):
        """Testing parsing the leaderboards's initial page."""
        content = self._load_resource(FILE_TOURNAMENT_LEADERBOARD_SELECTOR)
        leaderboard = TournamentLeaderboard.from_content(content)

        self.assertIsNone(leaderboard)