Skip to content

Commit

Permalink
Fixed error on character parsing when character has no badges selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Galarzaa90 committed Sep 1, 2019
1 parent e78b55a commit da069d0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions tests/resources/character/tibiacom_no_badges_selected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="BoxContent" style="background-image:url(https://static.tibia.com/images/global/content/scroll.gif);">
<table border="0" cellspacing="1" cellpadding="4" width="100%"><tr bgcolor=#505050><td colspan=2 class=white><b>Character Information</b></td></tr><tr bgcolor=#F1E0C6><td width=20%>Name:</td><td>Cozzackirycerz <div style="float: right"></div></td></tr><tr bgcolor=#D4C0A1><td>Title:</td><td>None (3 titles unlocked)</td></tr><tr bgcolor=#F1E0C6><td>Sex:</td><td>male</td></tr><tr bgcolor=#D4C0A1><td>Vocation:</td><td>Elite Knight</td></tr><tr bgcolor=#F1E0C6><td>Level:</td><td>84</td></tr><tr bgcolor=#D4C0A1><td><nobr>Achievement Points:</nobr></td><td>25</td></tr><tr bgcolor=#F1E0C6><td>World:</td><td>Antica</td></tr><tr bgcolor=#D4C0A1><td>Residence:</td><td>Yalahar</td></tr><tr bgcolor=#F1E0C6><td>Last Login:</td><td>Sep&#160;01&#160;2019,&#160;13:44:28&#160;CEST</td></tr><tr bgcolor=#D4C0A1><td>Account&#160;Status:</td><td>Premium Account</td></tr></table>
<br /><br /><table border="0" cellspacing="1" cellpadding="4" width="100%"><tr bgcolor="#505050"><td colspan="100%" class="white"><b>Account Badges</b></td></tr><tr bgcolor="#F1E0C6"><td colspan="100%">There are no account badges set to be displayed for this character.</td></tr></table><br /><br /><table border="0" cellspacing="1" cellpadding="4" width="100%"><tr bgcolor="#505050"><td colspan="2" class="white"><b>Account Achievements</b></td></tr><tr bgcolor="#F1E0C6"><td colspan="2">There are no achievements set to be displayed for this character.</td></tr></table><br /><br /><table border="0" cellspacing="1" cellpadding="4" width="100%"><tr bgcolor="#505050"><td colspan="2" class="white"><b>Character Deaths</b></td></tr><tr bgcolor="#F1E0C6"><td width="25%" valign="top">Aug&#160;04&#160;2019,&#160;21:22:23&#160;CEST</td><td>Slain at Level 84 by <a href="https://www.tibia.com/community/?subtopic=characters&name=Sheva+La+Bonita">Sheva&#160;La&#160;Bonita</a>, <a href="https://www.tibia.com/community/?subtopic=characters&name=Horhe+Em+Divine">Horhe&#160;Em&#160;Divine</a>, <a href="https://www.tibia.com/community/?subtopic=characters&name=Salyok+Le">Salyok&#160;Le</a>, <a href="https://www.tibia.com/community/?subtopic=characters&name=Snorrunge">Snorrunge</a> and <a href="https://www.tibia.com/community/?subtopic=characters&name=Cozzackirycerz">Cozzackirycerz</a>.</td></tr><tr bgcolor="#D4C0A1"><td width="25%" valign="top">Aug&#160;03&#160;2019,&#160;04:17:00&#160;CEST</td><td>Killed at Level 83 by <a href="https://www.tibia.com/community/?subtopic=characters&name=Ova+Inferno">Ova&#160;Inferno</a> and <a href="https://www.tibia.com/community/?subtopic=characters&name=Shooter+Here">Shooter&#160;Here</a>.</td></tr></table><br /><br /> <FORM ACTION="https://www.tibia.com/community/?subtopic=characters" METHOD=post>
<TABLE WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=4>
<TR><TD BGCOLOR="#505050" CLASS=white><B>Search Character</B></TD></TR>
<TR><TD BGCOLOR="#D4C0A1"><TABLE BORDER=0 CELLPADDING=1><TR>
<TD>Name:</TD><TD><INPUT NAME="name" VALUE="Cozzackirycerz" SIZE=29 MAXLENGTH=29></TD>
<TD><INPUT TYPE=image NAME="Submit" SRC="https://static.tibia.com/images/global/buttons/sbutton_submit.gif" BORDER=0 WIDTH=120 HEIGHT=18></TD>
</TR></TABLE></TD></TR>
12 changes: 12 additions & 0 deletions tests/tests_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tibiapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from tibiapy.creature import *
from tibiapy.client import *

__version__ = '2.2.5'
__version__ = '2.2.6'

from logging import NullHandler

Expand Down
3 changes: 3 additions & 0 deletions tibiapy/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit da069d0

Please sign in to comment.