From da069d0f3545a3edddf1e2b2ff20ef042b38e966 Mon Sep 17 00:00:00 2001 From: Allan Galarza Date: Sun, 1 Sep 2019 13:09:03 -0700 Subject: [PATCH] Fixed error on character parsing when character has no badges selected --- CHANGELOG.rst | 6 ++++++ tests/resources/README.md | 3 ++- .../character/tibiacom_no_badges_selected.txt | 9 +++++++++ tests/tests_character.py | 12 ++++++++++++ tibiapy/__init__.py | 2 +- tibiapy/character.py | 3 +++ 6 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/resources/character/tibiacom_no_badges_selected.txt diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 40ed4416..fc9aee16 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,12 @@ Changelog Due to this library relying on external content, older versions are not guaranteed to work. Try to always use the latest version. +.. _v2.2.6: + +2.2.6 (2019-09-01) +================== +- Fixed bug with account badges parsing failing when no badges were selected. + .. _v2.2.5: 2.2.5 (2019-08-22) diff --git a/tests/resources/README.md b/tests/resources/README.md index 80969769..0e6b9c77 100644 --- a/tests/resources/README.md +++ b/tests/resources/README.md @@ -9,7 +9,8 @@ deaths by summons, players, assisted deaths, etcetera. - [tibiacom_former_names.txt](character/tibiacom_former_names.txt) - A character with former names. - [tibiacom_full.txt](character/tibiacom_full.txt) - A full character response. - [tibiacom_not_found.txt](character/tibiacom_not_found.txt) - A character not found page. -- [tibiacom_title_badges.txt](character/tibiacom_title_badges.txt) - A character not found page. +- [tibiacom_title_badges.txt](character/tibiacom_title_badges.txt) - A character with unlocked titles and badges. +- [tibiacom_no_badges_selected.txt](character/tibiacom_no_badges_selected.txt) - A character with no selected badges. - [tibiadata.json](character/tibiadata.json) - A character on TibiaData, also showing Pvp deaths with assists. - [tibiadata_deleted.json](character/tibiadata_deleted.json) - A character scheduled for deletion on TibiaData. - [tibiadata_not_found.json](character/tibiadata_not_found.json) - The response of a character not found on TibiaData. diff --git a/tests/resources/character/tibiacom_no_badges_selected.txt b/tests/resources/character/tibiacom_no_badges_selected.txt new file mode 100644 index 00000000..6237fba2 --- /dev/null +++ b/tests/resources/character/tibiacom_no_badges_selected.txt @@ -0,0 +1,9 @@ +
+
Character Information
Name:Cozzackirycerz
Title:None (3 titles unlocked)
Sex:male
Vocation:Elite Knight
Level:84
Achievement Points:25
World:Antica
Residence:Yalahar
Last Login:Sep 01 2019, 13:44:28 CEST
Account Status:Premium Account
+

Account Badges
There are no account badges set to be displayed for this character.


Account Achievements
There are no achievements set to be displayed for this character.


Character Deaths
Aug 04 2019, 21:22:23 CESTSlain at Level 84 by Sheva La Bonita, Horhe Em Divine, Salyok Le, Snorrunge and Cozzackirycerz.
Aug 03 2019, 04:17:00 CESTKilled at Level 83 by Ova Inferno and Shooter Here.


+ + + \ No newline at end of file diff --git a/tests/tests_character.py b/tests/tests_character.py index 7763dd0c..8bd541c0 100644 --- a/tests/tests_character.py +++ b/tests/tests_character.py @@ -14,6 +14,7 @@ FILE_CHARACTER_DELETION = "character/tibiacom_deletion.txt" FILE_CHARACTER_DEATHS_COMPLEX = "character/tibiacom_deaths_complex.txt" FILE_CHARACTER_TITLE_BADGES = "character/tibiacom_title_badges.txt" +FILE_CHARACTER_NO_BADGES_SELECTED = "character/tibiacom_no_badges_selected.txt" FILE_CHARACTER_TIBIADATA = "character/tibiadata.json" FILE_CHARACTER_TIBIADATA_UNHIDDEN = "character/tibiadata_unhidden.json" @@ -116,6 +117,17 @@ def test_character_from_content_badges_and_title(self): self.assertIsInstance(badge.icon_url, str) self.assertIsInstance(badge.description, str) + def test_character_from_content_no_selected_badges(self): + """Testing parsing a character with visible badges but none selected.""" + content = self._load_resource(FILE_CHARACTER_NO_BADGES_SELECTED) + char = Character.from_content(content) + self.assertEqual("Cozzackirycerz", char.name) + self.assertEqual(25, char.achievement_points) + self.assertIsNone(char.title) + self.assertEqual(3, char.unlocked_titles) + self.assertEqual(0, len(char.account_badges)) + self.assertEqual(0, len(char.former_names)) + def test_character_from_content_unrelated(self): """Testing parsing an unrelated tibia.com section""" content = self._load_resource(self.FILE_UNRELATED_SECTION) diff --git a/tibiapy/__init__.py b/tibiapy/__init__.py index 1f0396fd..72c3a7bd 100644 --- a/tibiapy/__init__.py +++ b/tibiapy/__init__.py @@ -13,7 +13,7 @@ from tibiapy.creature import * from tibiapy.client import * -__version__ = '2.2.5' +__version__ = '2.2.6' from logging import NullHandler diff --git a/tibiapy/character.py b/tibiapy/character.py index 6333bb4a..41de3f89 100644 --- a/tibiapy/character.py +++ b/tibiapy/character.py @@ -435,6 +435,9 @@ def _parse_badges(self, rows): columns = row.find_all('td') for column in columns: popup = column.find("span", attrs={"class": "HelperDivIndicator"}) + if not popup: + # Badges are visible, but none selected. + return m = badge_popup_regexp.search(popup['onmouseover']) if m: name = m.group(1)
Search Character
+ + +
Name: