11import datetime
22
33from tests .tests_tibiapy import TestCommons
4- from tibiapy import InvalidContent
4+ from tibiapy import InvalidContent , Sex , Vocation
55from tibiapy .models import Death , DeathParticipant , AccountBadge , Character
66from tibiapy .parsers .character import CharacterParser
77from tibiapy .urls import get_character_url
2222
2323
2424class TestCharacter (TestCommons ):
25- def _compare_character (self , mock_character , character ):
26- self .assertEqual (mock_character .name , character .name )
27- self .assertEqual (mock_character .world , character .world )
28- self .assertEqual (mock_character .vocation , character .vocation )
29- self .assertEqual (mock_character .level , character .level )
30- self .assertEqual (mock_character .sex , character .sex )
3125
3226 # region Tibia.com Character Tests
3327 def test_character_parser_from_content (self ):
3428 """Testing parsing a character's HTML content"""
3529 character = CharacterParser .from_content (self .load_resource (FILE_CHARACTER_RESOURCE ))
36- # TODO: Reenable
37- # self._compare_character(Character("Tschas", "Gladera", Vocation.ELDER_DRUID, 522, Sex.FEMALE), character)
30+ self .assertEqual ("Tschas" , character .name )
31+ self .assertEqual ("Gladera" , character .world )
32+ self .assertEqual (Vocation .ELDER_DRUID , character .vocation )
33+ self .assertEqual (833 , character .level )
34+ self .assertEqual (Sex .FEMALE , character .sex )
3835 self .assertIsNotNone (character .guild_membership )
3936 self .assertEqual ("Bald Dwarfs" , character .guild_membership .name )
4037 self .assertEqual ("Exalted" , character .guild_membership .rank )
@@ -51,12 +48,7 @@ def test_character_parser_from_content(self):
5148 self .assertEqual (character .url , get_character_url (character .name ))
5249 self .assertEqual (5 , len (character .other_characters ))
5350 self .assertFalse (character .is_hidden )
54-
55- # Badges
56- self .assertEqual (8 , len (character .account_badges ))
57- badge = character .account_badges [0 ]
58- self .assertEqual ("Ancient Hero" , badge .name )
59- self .assertEqual ("The account is older than 15 years." , badge .description )
51+ self .assertIn (character .name , character .url )
6052
6153 def test_character_parser_from_content_not_found (self ):
6254 """Testing parsing a character not found page"""
@@ -71,21 +63,16 @@ def test_character_parser_from_content_traded(self):
7163 char = CharacterParser .from_content (content )
7264
7365 self .assertIsInstance (char , Character )
74- self .assertEqual ("King Dragotz" , char .name )
7566 self .assertTrue (char .is_traded )
76- char_in_other = char .other_characters [0 ]
77- self .assertEqual ("King Dragotz" , char_in_other .name )
78- self .assertTrue (char_in_other .is_traded )
67+ self .assertTrue (any (c .is_traded for c in char .other_characters ), "at least one character should be traded" )
7968
8069 def test_character_parser_from_content_with_former_names (self ):
8170 """Testing parsing a character that has former names"""
8271 content = self .load_resource (FILE_CHARACTER_FORMER_NAMES )
8372
8473 char = CharacterParser .from_content (content )
8574
86- self .assertIsInstance (char .former_names , list )
87- self .assertTrue (char .former_names )
88- self .assertEqual (len (char .former_names ), 3 )
75+ self .assertIsNotEmpty (char .former_names )
8976
9077 def test_character_parser_from_content_with_position (self ):
9178 """Testing parsing a character with a position"""
@@ -94,12 +81,10 @@ def test_character_parser_from_content_with_position(self):
9481 position = "CipSoft Member"
9582
9683 char = CharacterParser .from_content (content )
97- self .assertEqual ("Steve" , char .name )
9884 self .assertEqual (position , char .position )
9985 self .assertEqual (position , char .account_information .position )
100- steve_other = char .other_characters [2 ]
101- self .assertEqual ("Steve" , steve_other .name )
102- self .assertEqual ("CipSoft Member" , steve_other .position )
86+ self .assertTrue (any (c .position == position for c in char .other_characters ),
87+ "at least one character should have a position" )
10388
10489 def test_character_parser_from_content_deleted_character (self ):
10590 """Testing parsing a character scheduled for deletion"""
@@ -108,81 +93,62 @@ def test_character_parser_from_content_deleted_character(self):
10893 self .assertEqual ("Gutek Handless" , char .name )
10994 self .assertIsNotNone (char .deletion_date )
11095 self .assertIsInstance (char .deletion_date , datetime .datetime )
111- self .assertEqual ( datetime . datetime ( 2023 , 7 , 4 , 16 , 10 , 41 , tzinfo = datetime . timezone . utc ), char .deletion_date )
96+ self .assertTrue ( char .is_scheduled_for_deletion )
11297
11398 def test_character_parser_from_content_complex_deaths (self ):
11499 """Testing parsing a character with complex deaths (summons, assists, etc)"""
115100 content = self .load_resource (FILE_CHARACTER_DEATHS_COMPLEX )
101+
116102 char = CharacterParser .from_content (content )
103+
104+ deaths = char .deaths
117105 self .assertEqual (5 , len (char .deaths ))
118- death1 , death2 , death3 , death4 , death5 = char .deaths
119- self .assertIsInstance (death1 , Death )
120- self .assertEqual (23 , len (death1 .killers ))
121- self .assertEqual (1 , len (death1 .assists ))
122-
123- self .assertIsInstance (death2 , Death )
124- self .assertEqual (1 , len (death2 .killers ))
125- self .assertEqual (0 , len (death2 .assists ))
126-
127- self .assertIsInstance (death3 , Death )
128- self .assertEqual (11 , len (death3 .killers ))
129- self .assertEqual (0 , len (death3 .assists ))
130- self .assertEqual ("a paladin familiar" , death3 .killers [- 1 ].summon )
131- self .assertEqual ("Alloy Hat" , death3 .killers [- 1 ].name )
132- self .assertTrue (death3 .killers [- 1 ].is_traded )
133-
134- self .assertIsInstance (death4 , Death )
135- self .assertEqual (12 , len (death4 .killers ))
136- self .assertEqual (0 , len (death4 .assists ))
137- self .assertEqual ("Cliff Lee Burton" , death4 .killers [- 1 ].name )
138- self .assertTrue (death4 .killers [- 1 ].is_traded )
139-
140- def test_character_parserparser_from_content_badges_and_title (self ):
106+ self .assertTrue (deaths [0 ].is_by_player )
107+ self .assertEqual (23 , len (deaths [0 ].killers ))
108+ self .assertTrue (deaths [0 ].killer .is_player )
109+ self .assertEqual (1 , len (deaths [0 ].assists ))
110+
111+ self .assertEqual (1 , len (deaths [1 ].killers ))
112+ self .assertEqual (0 , len (deaths [1 ].assists ))
113+
114+ self .assertEqual (11 , len (deaths [2 ].killers ))
115+ self .assertEqual (0 , len (deaths [2 ].assists ))
116+ self .assertEqual ("a paladin familiar" , deaths [2 ].killers [- 1 ].summon )
117+ self .assertEqual ("Alloy Hat" , deaths [2 ].killers [- 1 ].name )
118+ self .assertTrue (deaths [2 ].killers [- 1 ].is_traded )
119+
120+ self .assertEqual (12 , len (deaths [3 ].killers ))
121+ self .assertEqual (0 , len (deaths [3 ].assists ))
122+ self .assertEqual ("Cliff Lee Burton" , deaths [3 ].killers [- 1 ].name )
123+ self .assertTrue (deaths [3 ].killers [- 1 ].is_traded )
124+
125+ def test_character_parser_from_content_badges_and_title (self ):
141126 """Testing parsing a character with account badges and a title"""
142127 content = self .load_resource (FILE_CHARACTER_TITLE_BADGES )
143128 char = CharacterParser .from_content (content )
144- self .assertEqual ("Galarzaa Fidera" , char .name )
145- self .assertEqual (410 , char .achievement_points )
146129 self .assertEqual ("Gold Hoarder" , char .title )
147130 self .assertEqual (13 , char .unlocked_titles )
148- self .assertEqual (8 , len (char .account_badges ))
149- for badge in char .account_badges :
150- self .assertIsInstance (badge , AccountBadge )
151- self .assertIsInstance (badge .name , str )
152- self .assertIsInstance (badge .icon_url , str )
153- self .assertIsInstance (badge .description , str )
131+ self .assertSizeEquals (char .account_badges , 8 )
154132
155133 def test_character_parser_from_content_no_selected_badges (self ):
156134 """Testing parsing a character with visible badges but none selected."""
157135 content = self .load_resource (FILE_CHARACTER_NO_BADGES_SELECTED )
158136 char = CharacterParser .from_content (content )
159- self .assertEqual ("Cozzackirycerz" , char .name )
160- self .assertEqual (25 , char .achievement_points )
161- self .assertIsNone (char .title )
162- self .assertEqual (3 , char .unlocked_titles )
163- self .assertEqual (0 , len (char .account_badges ))
164- self .assertEqual (0 , len (char .former_names ))
137+ self .assertIsEmpty (char .account_badges )
165138
166139 def test_character_parser_from_content_multiple_houses (self ):
167140 """Testing parsing a character with multiple houses."""
168141 content = self .load_resource (FILE_CHARACTER_MULTIPLE_HOUSES )
169142
170143 char = CharacterParser .from_content (content )
171144
172- self .assertEqual (2 , len (char .houses ))
173- first_house = char .houses [0 ]
174- second_house = char .houses [1 ]
175- self .assertEqual ("Coastwood 8" , first_house .name )
176- self .assertEqual ("Tunnel Gardens 5" , second_house .name )
177- self .assertEqual ("Ab'Dendriel" , first_house .town )
178- self .assertEqual ("Kazordoon" , second_house .town )
145+ self .assertSizeAtLeast (char .houses , 2 )
179146
180147 def test_character_parser_from_content_truncated_deaths (self ):
181148 """Testing parsing a character with truncated daths"""
182149 content = self .load_resource (FILE_CHARACTER_TRUNCATED_DEATHS )
183150 char = CharacterParser .from_content (content )
184- self .assertEqual ("Godlike Terror" , char .name )
185- self .assertEqual (51 , len (char .deaths ))
151+ self .assertIsNotEmpty (char .deaths )
186152 self .assertTrue (char .deaths_truncated )
187153
188154 def test_character_parser_from_content_unrelated (self ):
@@ -192,26 +158,3 @@ def test_character_parser_from_content_unrelated(self):
192158 CharacterParser .from_content (content )
193159
194160 # endregion
195-
196- def test_death_types (self ):
197- """Testing different death types"""
198- assisted_suicide = Death (level = 280 ,
199- killers = [
200- DeathParticipant (name = "Galarzaa" , is_player = True , summon = None , is_traded = False ),
201- DeathParticipant (name = "a pixy" , is_player = False , summon = None , is_traded = False )
202- ],
203- assists = [],
204- time = datetime .datetime .now ())
205- self .assertEqual (assisted_suicide .killer , assisted_suicide .killers [0 ])
206- self .assertTrue (assisted_suicide .is_by_player )
207-
208- spawn_invasion = Death (level = 270 ,
209- killers = [
210- DeathParticipant (name = "a demon" , is_player = False , summon = None , is_traded = False ),
211- DeathParticipant (name = "Nezune" , is_player = True , summon = None , is_traded = False )
212- ],
213- assists = [],
214- time = datetime .datetime .now ())
215- self .assertEqual (spawn_invasion .killer , spawn_invasion .killers [0 ])
216- self .assertIsNone (spawn_invasion .killer .url )
217- self .assertTrue (spawn_invasion .is_by_player )
0 commit comments