def test_explorimmo_viager(self): query = Query() query.type = POSTS_TYPES.VIAGER query.cities = [] for city in self.backend.search_city('85'): city.backend = self.backend.name query.cities.append(city) self.check_against_query(query)
def test_foncia_sale(self): query = Query() query.area_min = 20 query.type = POSTS_TYPES.SALE query.cities = [] for city in self.backend.search_city('paris'): city.backend = self.backend.name query.cities.append(city) self.check_against_query(query)
def test_logicimmo_viager(self): query = Query() query.type = POSTS_TYPES.VIAGER query.cities = [] for city in self.backend.search_city('paris'): city.backend = self.backend.name query.cities.append(city) if len(query.cities) == 3: break self.check_against_query(query)
def test_foncia_furnished_rent(self): query = Query() query.area_min = 20 query.cost_max = 1500 query.type = POSTS_TYPES.FURNISHED_RENT query.cities = [] for city in self.backend.search_city('paris'): city.backend = self.backend.name query.cities.append(city) self.check_against_query(query)
def test_explorimmo_rent(self): query = Query() query.area_min = 20 query.cost_max = 1500 query.type = POSTS_TYPES.RENT query.cities = [] for city in self.backend.search_city('paris'): city.backend = self.backend.name query.cities.append(city) self.check_against_query(query)
def test_logicimmo_sale(self): query = Query() query.area_min = 20 query.type = POSTS_TYPES.SALE query.cities = [] for city in self.backend.search_city('paris'): city.backend = self.backend.name query.cities.append(city) if len(query.cities) == 3: break self.check_against_query(query)
def test_pap_viager(self): query = Query() query.type = POSTS_TYPES.VIAGER query.cities = [] for city in self.backend.search_city('paris'): city.backend = self.backend.name query.cities.append(city) # Remove rooms from the tested fields as viager never have them self.FIELDS_ANY_HOUSINGS_LIST = ["photos", "station", "bedrooms"] self.FIELDS_ANY_SINGLE_HOUSING = ["photos", "bedrooms", "station"] self.check_against_query(query)
def test_seloger_rent_personal(self): query = Query() query.area_min = 20 query.cost_max = 1500 query.type = POSTS_TYPES.RENT query.advert_types = [ADVERT_TYPES.PROFESSIONAL] query.cities = [] for city in self.backend.search_city('paris'): city.backend = self.backend.name query.cities.append(city) self.check_against_query(query)
def test_logicimmo_personal(self): query = Query() query.area_min = 20 query.cost_max = 900 query.type = POSTS_TYPES.RENT query.advert_types = [ADVERT_TYPES.PERSONAL] query.cities = [] for city in self.backend.search_city('paris'): city.backend = self.backend.name query.cities.append(city) results = list(self.backend.search_housings(query)) self.assertEqual(len(results), 0)
def build_queries(self, constraints_dict): """ Build Woob ``woob.capabilities.housing.Query`` objects from the constraints defined in the configuration. Each query has at most 3 cities, to comply with housing websites limitations. :param constraints_dict: A dictionary of constraints, as defined in the config. :return: A list of Woob ``woob.capabilities.housing.Query`` objects. Returns ``None`` if an error occurred. """ queries = [] # First, find all matching cities for the postal codes in constraints matching_cities = [] for postal_code in constraints_dict["postal_codes"]: try: for city in self.webnip.do("search_city", postal_code): matching_cities.append(city) except CallErrors as exc: # If an error occured, just log it LOGGER.error( ("An error occured while building query for postal code %s: %s" ), postal_code, str(exc), ) if not matching_cities: # If postal code gave no match, warn the user LOGGER.warn( "Postal code %s could not be matched with a city.", postal_code) # Remove "TOUTES COMMUNES" entry which are duplicates of the individual # cities entries in Logicimmo module. matching_cities = [ city for city in matching_cities if not (city.backend == "logicimmo" and city.name.startswith("TOUTES COMMUNES")) ] # Then, build queries by grouping cities by at most 3 for cities_batch in tools.batch(matching_cities, 3): query = Query() query.cities = list(cities_batch) try: query.house_types = [ getattr(HOUSE_TYPES, house_type.upper()) for house_type in constraints_dict["house_types"] ] except AttributeError: LOGGER.error("Invalid house types constraint.") return None try: query.type = getattr(POSTS_TYPES, constraints_dict["type"].upper()) except AttributeError: LOGGER.error("Invalid post type constraint.") return None query.area_min = constraints_dict["area"][0] query.area_max = constraints_dict["area"][1] query.cost_min = constraints_dict["cost"][0] query.cost_max = constraints_dict["cost"][1] query.nb_rooms = constraints_dict["rooms"][0] queries.append(query) return queries