Beispiel #1
0
    def test_listed_house_list_from_tibiadata(self):
        """Testing parsing a house list from TibiaData"""
        content = self._load_resource(FILE_HOUSE_TIBIADATA_LIST)
        houses = ListedHouse.list_from_tibiadata(content)

        self.assertIsInstance(houses, list)
        self.assertGreater(len(houses), 0)
        self.assertIsInstance(houses[0], ListedHouse)
        self.assertEqual(houses[0].town, "Edron")
        self.assertEqual(houses[0].type, HouseType.GUILDHALL)
        self.assertEqual(houses[0].status, HouseStatus.RENTED)
        self.assertIsInstance(houses[0].id, int)
        self.assertIsNotNone(ListedHouse.get_list_url_tibiadata(houses[0].world, houses[0].town))
Beispiel #2
0
    def test_listed_house_from_content(self):
        """Testing parsing the house list of a world and city"""
        content = self._load_resource(FILE_HOUSE_LIST)
        houses = ListedHouse.list_from_content(content)

        self.assertIsInstance(houses, list)
        self.assertGreater(len(houses), 0)
        self.assertIsInstance(houses[0], ListedHouse)
        self.assertEqual(houses[0].town, "Carlin")
        self.assertEqual(houses[0].type, HouseType.HOUSE)
        self.assertEqual(houses[0].status, HouseStatus.RENTED)
        self.assertIsInstance(houses[0].id, int)
        self.assertIsNotNone(ListedHouse.get_list_url(houses[0].world, houses[0].town))

        self.assertEqual(houses[25].status, HouseStatus.RENTED)
Beispiel #3
0
    def test_listed_house_list_from_tibiadata_not_found(self):
        """Testing parsing a list of a world that doesn't exist"""
        content = self._load_resource(FILE_HOUSE_TIBIADATA_LIST_NOT_FOUND)
        houses = ListedHouse.list_from_tibiadata(content)

        self.assertIsInstance(houses, list)
        self.assertEqual(len(houses), 0)
Beispiel #4
0
    async def test_client_fetch_world_houses(self, mock):
        """Testing fetching a world's houses"""
        world = "Antica"
        city = "Edron"
        content = self.load_resource(FILE_HOUSE_LIST)
        mock.get(ListedHouse.get_list_url(world, city),
                 status=200,
                 body=content)
        houses = await self.client.fetch_world_houses(world, city)

        self.assertIsInstance(houses.data, list)
        self.assertIsInstance(houses.data[0], ListedHouse)
Beispiel #5
0
    async def fetch_world_houses(self,
                                 world,
                                 town,
                                 house_type=HouseType.HOUSE,
                                 status: HouseStatus = None,
                                 order=HouseOrder.NAME):
        """Fetches the house list of a world and type.

        Parameters
        ----------
        world: :class:`str`
            The name of the world.
        town: :class:`str`
            The name of the town.
        house_type: :class:`HouseType`
            The type of building. House by default.
        status: :class:`HouseStatus`, optional
            The house status to filter results. By default no filters will be applied.
        order: :class:`HouseOrder`, optional
            The ordering to use for the results. By default they are sorted by name.

        Returns
        -------
        list of :class:`ListedHouse`
            The lists of houses meeting the criteria if found.

        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(
            ListedHouse.get_list_url(world, town, house_type, status, order))
        houses = ListedHouse.list_from_content(content)
        return houses
Beispiel #6
0
 def test_listed_house_list_from_tibiadata_unrelated_section(self):
     """Testing parsing an unrelated section"""
     with self.assertRaises(InvalidContent):
         ListedHouse.list_from_tibiadata(self._load_resource(tests.tests_character.FILE_CHARACTER_TIBIADATA))
Beispiel #7
0
 def test_listed_house_list_from_tibiadata_invalid_json(self):
     """Testing parsing an invalid json"""
     with self.assertRaises(InvalidContent):
         ListedHouse.list_from_tibiadata("nope")
Beispiel #8
0
 def test_listed_house_from_content_unrelated(self):
     """Testing parsing an unrelated section"""
     content = self._load_resource(self.FILE_UNRELATED_SECTION)
     with self.assertRaises(InvalidContent):
         ListedHouse.list_from_content(content)
Beispiel #9
0
    def test_listed_house_from_content_not_found(self):
        """Testing parsing an empty house list"""
        content = self._load_resource(FILE_HOUSE_NOT_FOUND)
        houses = ListedHouse.list_from_content(content)

        self.assertIsNone(houses)
Beispiel #10
0
    def test_listed_house_from_content_empty(self):
        """Testing parsing an empty house list"""
        content = self._load_resource(FILE_HOUSE_LIST_EMPTY)
        houses = ListedHouse.list_from_content(content)

        self.assertEqual(len(houses), 0)