Skip to content

Commit a9f4d69

Browse files
committed
Added some missing test cases
1 parent 8404955 commit a9f4d69

File tree

4 files changed

+62
-7
lines changed

4 files changed

+62
-7
lines changed

tests/tests_client.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import asynctest
55
from aioresponses import aioresponses
66

7-
from tests.tests_bazaar import FILE_BAZAAR_CURRENT
7+
from tests.tests_bazaar import FILE_BAZAAR_CURRENT, FILE_BAZAAR_HISTORY, FILE_AUCTION_FINISHED
88
from tests.tests_character import FILE_CHARACTER_RESOURCE, FILE_CHARACTER_NOT_FOUND
9+
from tests.tests_events import FILE_EVENT_CALENDAR
910
from tests.tests_forums import FILE_CM_POST_ARCHIVE_PAGES
1011
from tests.tests_guild import FILE_GUILD_FULL, FILE_GUILD_LIST
1112
from tests.tests_highscores import FILE_HIGHSCORES_FULL
@@ -17,7 +18,8 @@
1718
from tibiapy import CharacterBazaar, Client, Character, CMPostArchive, Guild, Highscores, VocationFilter, Category, \
1819
House, ListedHouse, \
1920
ListedGuild, \
20-
KillStatistics, ListedNews, News, World, WorldOverview, Forbidden, NetworkError, Creature
21+
KillStatistics, ListedNews, News, World, WorldOverview, Forbidden, NetworkError, Creature, AuctionDetails, \
22+
EventSchedule
2123

2224

2325
class TestClient(asynctest.TestCase, TestCommons):
@@ -229,4 +231,46 @@ async def test_client_fetch_current_auctions(self, mock):
229231
response = await self.client.fetch_current_auctions()
230232
self.assertIsInstance(response.data, CharacterBazaar)
231233

234+
async def test_client_fetch_current_auctions_invalid_page(self):
235+
"""Testing fetching the current auctions with an invalid page"""
236+
with self.assertRaises(ValueError):
237+
await self.client.fetch_current_auctions(-1)
238+
239+
@aioresponses()
240+
async def test_client_fetch_auction_history(self, mock):
241+
"""Testing fetching the auction history"""
242+
content = self.load_resource(FILE_BAZAAR_HISTORY)
243+
mock.get(CharacterBazaar.get_auctions_history_url(), status=200, body=content)
244+
response = await self.client.fetch_auction_history()
245+
self.assertIsInstance(response.data, CharacterBazaar)
246+
247+
async def test_client_fetch_auction_history_invalid_page(self):
248+
"""Testing fetching the auction history with an incorrect page"""
249+
with self.assertRaises(ValueError):
250+
await self.client.fetch_auction_history(-1)
232251

252+
@aioresponses()
253+
async def test_client_fetch_auction(self, mock):
254+
"""Testing fetching an auction"""
255+
content = self.load_resource(FILE_AUCTION_FINISHED)
256+
mock.get(AuctionDetails.get_url(134), status=200, body=content)
257+
response = await self.client.fetch_auction(134)
258+
self.assertIsInstance(response.data, AuctionDetails)
259+
260+
async def test_client_fetch_auction_invalid_id(self):
261+
"""Testing fetching an auction with an invalid id"""
262+
with self.assertRaises(ValueError):
263+
await self.client.fetch_auction(-1)
264+
265+
@aioresponses()
266+
async def test_client_fetch_event_calendar(self, mock):
267+
"""Testing fetching the auction history"""
268+
content = self.load_resource(FILE_EVENT_CALENDAR)
269+
mock.get(EventSchedule.get_url(), status=200, body=content)
270+
response = await self.client.fetch_event_schedule()
271+
self.assertIsInstance(response.data, EventSchedule)
272+
273+
async def test_client_fetch_event_calendar_invalid_params(self):
274+
"""Testing fetching the auction history"""
275+
with self.assertRaises(ValueError):
276+
await self.client.fetch_event_schedule(3)

tests/tests_creature.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ def test_creature_detail_from_content(self):
4444
self.assertIsNotNone(creature)
4545
self.assertEqual("Animated Feathers", creature.name)
4646
self.assertEqual("animatedfeather", creature.race)
47+
self.assertEqual(13000, creature.hitpoints)
48+
self.assertEqual(9860, creature.experience)
49+
self.assertIsNone(creature.mana_cost)
50+
self.assertFalse(creature.summonable)
51+
self.assertFalse(creature.convinceable)
4752
self.assertIsNotNone(creature.description)
4853
# endregion

tibiapy/client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ async def fetch_current_auctions(self, page=1, filters=None):
228228
ValueError
229229
If the page number is not 1 or greater.
230230
"""
231-
if not page:
231+
if page <= 0:
232232
raise ValueError('page must be 1 or greater.')
233233
response = await self._request("GET", CharacterBazaar.get_current_auctions_url(page, filters))
234234
start_time = time.perf_counter()
@@ -261,7 +261,7 @@ async def fetch_auction_history(self, page=1):
261261
ValueError
262262
If the page number is not 1 or greater.
263263
"""
264-
if not page:
264+
if page <= 0:
265265
raise ValueError('page must be 1 or greater.')
266266
response = await self._request("GET", CharacterBazaar.get_auctions_history_url(page))
267267
start_time = time.perf_counter()
@@ -303,7 +303,11 @@ async def fetch_auction(self, auction_id, *, fetch_items=False, fetch_mounts=Fal
303303
This usually means that Tibia.com is rate-limiting the client because of too many requests.
304304
NetworkError
305305
If there's any connection errors during the request.
306+
ValueError
307+
If the auction id is not 1 or greater.
306308
"""
309+
if auction_id <= 0:
310+
raise ValueError('auction_id must be 1 or greater.')
307311
response = await self._request("GET", AuctionDetails.get_url(auction_id))
308312
start_time = time.perf_counter()
309313
auction = AuctionDetails.from_content(response.content, auction_id, skip_details)
@@ -321,7 +325,7 @@ async def fetch_auction(self, auction_id, *, fetch_items=False, fetch_mounts=Fal
321325
return TibiaResponse(response, auction, parsing_time)
322326

323327
async def _fetch_all_pages(self, auction_id, paginator, item_type):
324-
"""Fetches all the pages of a auction paginator.
328+
"""Fetches all the pages of an auction paginator.
325329
326330
Parameters
327331
----------
@@ -411,7 +415,7 @@ async def fetch_cm_post_archive(self, start_date, end_date, page=1):
411415
return TibiaResponse(response, cm_post_archive, parsing_time)
412416

413417
async def fetch_event_schedule(self, month=None, year=None):
414-
"""Fetches the event calendar.
418+
"""Fetches the event calendar. By default, it gets the events for the current month.
415419
416420
.. versionadded:: 3.0.0
417421
@@ -434,6 +438,8 @@ async def fetch_event_schedule(self, month=None, year=None):
434438
This usually means that Tibia.com is rate-limiting the client because of too many requests.
435439
NetworkError
436440
If there's any connection errors during the request.
441+
ValueError
442+
If only one of year or month are defined.
437443
"""
438444
if (year is None and month is not None) or (year is not None and month is None):
439445
raise ValueError("both year and month must be defined or neither must be defined.")

tibiapy/creature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def from_content(cls, content):
254254
255255
Returns
256256
-------
257-
:class:`Character`
257+
:class:`CreatureDetail`
258258
The character contained in the page.
259259
"""
260260
try:

0 commit comments

Comments
 (0)