def test_house_from_tibiadata(self): """Testing parsing a house from TibiaData""" content = self._load_resource(FILE_HOUSE_TIBIADATA) house = House.from_tibiadata(content) self.assertIsInstance(house, House) self.assertEqual(house.id, 32012) self.assertEqual(house.world, "Gladera") self.assertEqual(house.type, HouseType.GUILDHALL) self.assertEqual(house.size, 7) self.assertEqual(house.status, HouseStatus.AUCTIONED) self.assertIsNone(house.owner)
async def get_house(house_id, world, *, tries=5) -> House: """Returns a dictionary containing a house's info, a list of possible matches or None. If world is specified, it will also find the current status of the house in that world.""" if tries == 0: raise errors.NetworkError(f"get_house({house_id},{world})") try: async with aiohttp.ClientSession() as session: async with session.get(House.get_url_tibiadata(house_id, world)) as resp: content = await resp.text(encoding='ISO-8859-1') house = House.from_tibiadata(content) except aiohttp.ClientError: await asyncio.sleep(config.network_retry_delay) return await get_house(house_id, world, tries=tries - 1) return house
def test_house_from_tibiadata_unrelated(self): """Testing parsing an unrelated section""" content = self._load_resource(tests.tests_character.FILE_CHARACTER_TIBIADATA) with self.assertRaises(InvalidContent): House.from_tibiadata(content)
def test_house_from_tibiadata_invalid_json(self): """Testing parsing an invalid json""" with self.assertRaises(InvalidContent): House.from_tibiadata("<p>Not json</p>")
def test_house_from_tibiadata_not_found(self): """Testing parsing a house that doesn't exist""" content = self._load_resource(FILE_HOUSE_TIBIADATA_NOT_FOUND) house = House.from_tibiadata(content) self.assertIsNone(house)