async def fetch_house(self, house_id, world): """Fetches a house in a specific world by its id. Parameters ---------- house_id: :class:`int` The house's internal id. world: :class:`str` The name of the world to look for. Returns ------- :class:`House` The house if found, ``None`` otherwise. Raises ------ Forbidden If a 403 Forbidden error was returned. This usually means that Tibia.com is rate-limiting the client because of too many requests. NetworkError If there's any connection errors during the request. """ content = await self._get(House.get_url(house_id, world)) house = House.from_content(content) return house
def test_house_from_content(self): """Testing parsing a house""" content = self.load_resource(FILE_HOUSE_FULL) house = House.from_content(content) self.assertIsInstance(house, House) self.assertEqual(house.name, "Sorcerer's Avenue Labs 2e") self.assertEqual(house.beds, 1) self.assertTrue(house.rent, 715) self.assertEqual(house.status, HouseStatus.AUCTIONED) self.assertEqual(house.url, House.get_url(house.id, house.world)) self.assertIsNone(house.owner) self.assertIsNone(house.owner_url) self.assertIsNotNone(house.highest_bidder) self.assertIsNotNone(house.highest_bidder_url) self.assertEqual(house.highest_bid, 0) house_json_raw = house.to_json() house_json = json.loads(house_json_raw) self.assertEqual(house.image_url, house_json["image_url"])
def test_house_from_content_unrelated(self): """Testing parsing an unrelated section""" content = self._load_resource(self.FILE_UNRELATED_SECTION) with self.assertRaises(InvalidContent): House.from_content(content)
def test_house_from_content_not_found(self): """Testing parsing a house that doesn't exist""" content = self._load_resource(FILE_HOUSE_NOT_FOUND) house = House.from_content(content) self.assertIsNone(house)