Ejemplo n.º 1
0
    def test_character_from_content(self):
        """Testing parsing a character's HTML content"""
        character = Character.from_content(self.load_resource(FILE_CHARACTER_RESOURCE))
        self._compare_character(Character("Tschas", "Gladera", Vocation.ELDER_DRUID, 522, Sex.FEMALE), character)
        self.assertIsNotNone(character.guild_membership)
        self.assertEqual("Bald Dwarfs", character.guild_membership.name)
        self.assertEqual("Emperor", character.guild_membership.rank)
        self.assertIsNotNone(character.guild_url)
        self.assertIsNone(character.married_to_url)
        self.assertEqual(character.guild_name, character.guild_membership.name)
        self.assertEqual(character.guild_rank, character.guild_membership.rank)
        self.assertEqual(AccountStatus.PREMIUM_ACCOUNT, character.account_status)
        self.assertEqual(304, character.achievement_points)
        self.assertIsNone(character.deletion_date)
        self.assertIsNotNone(character.deaths)
        self.assertEqual(2, character.deaths.__len__())
        self.assertEqual(parse_tibia_datetime("Aug 02 2021, 17:32:07 CEST"), character.last_login)
        self.assertEqual(character.url, Character.get_url(character.name))
        self.assertEqual(5, len(character.other_characters))
        self.assertFalse(character.hidden)

        # Badges
        self.assertEqual(3, len(character.account_badges))
        badge = character.account_badges[0]
        self.assertEqual("Ancient Hero", badge.name)
        self.assertEqual("The account is older than 15 years.", badge.description)
Ejemplo n.º 2
0
 def test_character_from_content(self):
     """Testing parsing a character's HTML content"""
     character = Character.from_content(
         self._load_resource(FILE_CHARACTER_RESOURCE))
     self._compare_character(
         Character("Tschas", "Gladera", Vocation.DRUID, 260, Sex.FEMALE),
         character)
     self.assertIsNotNone(character.guild_membership)
     self.assertEqual("Atlantis", character.guild_membership.name)
     self.assertEqual("Gaia", character.guild_membership.rank)
     self.assertIsNotNone(character.guild_url)
     self.assertIsNone(character.married_to_url)
     self.assertEqual(character.guild_name, character.guild_membership.name)
     self.assertEqual(character.guild_rank, character.guild_membership.rank)
     self.assertEqual(AccountStatus.FREE_ACCOUNT, character.account_status)
     self.assertEqual(182, character.achievement_points)
     self.assertIsNone(character.house)
     self.assertIsNone(character.deletion_date)
     self.assertIsNotNone(character.deaths)
     self.assertEqual(0, character.deaths.__len__())
     self.assertEqual(parse_tibia_datetime("Aug 04 2019, 13:56:59 CEST"),
                      character.last_login)
     self.assertEqual(character.url, Character.get_url(character.name))
     self.assertEqual(5, len(character.other_characters))
     self.assertFalse(character.hidden)
def get_character(name):
    """Fetch a character using requests instead of aiohttp."""
    url = Character.get_url(name)

    r = requests.get(url)
    content = r.text
    character = Character.from_content(content)
    return character
Ejemplo n.º 4
0
    async def test_client_fetch_character_not_found(self, mock):
        """Testing fetching a non existent character"""
        name = "Nezune"
        content = self.load_resource(FILE_CHARACTER_NOT_FOUND)
        mock.get(Character.get_url(name), status=200, body=content)
        character = await self.client.fetch_character(name)

        self.assertIsNone(character.data)
Ejemplo n.º 5
0
    async def test_client_fetch_character(self, mock):
        """Testing fetching a character"""
        name = "Tschas"
        content = self.load_resource(FILE_CHARACTER_RESOURCE)
        mock.get(Character.get_url(name), status=200, body=content)
        character = await self.client.fetch_character(name)

        self.assertIsInstance(character.data, Character)
Ejemplo n.º 6
0
    def test_character_changes(self):
        content = self.load_resource(
            "website_changes/2_community_characters_bobeek.txt")
        character = Character.from_content(content)

        self.assertEqual("Bobeek", character.name)
        self.assertIsNotNone(character.guild_membership)
        self.assertEqual("Hill", character.guild_membership.name)
        self.assertEqual("King", character.guild_membership.rank)
        self.assertEqual("Goraca", character.married_to)
        self.assertEqual(character.guild_name, character.guild_membership.name)
        self.assertEqual(character.guild_rank, character.guild_membership.rank)
        self.assertEqual(AccountStatus.PREMIUM_ACCOUNT,
                         character.account_status)
        self.assertEqual(1038, character.achievement_points)
        self.assertIsNone(character.deletion_date)
        self.assertIsNotNone(character.deaths)
        self.assertEqual(1, character.deaths.__len__())
        self.assertEqual(character.url, Character.get_url(character.name))
        self.assertEqual(3, len(character.other_characters))
        self.assertFalse(character.hidden)
Ejemplo n.º 7
0
    async def fetch_character(self, name):
        """Fetches a character by its name from Tibia.com

        Parameters
        ----------
        name: :class:`str`
            The name of the character.

        Returns
        -------
        :class:`Character`
            The character if found, else ``None``.

        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(Character.get_url(name.strip()))
        char = Character.from_content(content)
        return char