def test_elastic_to_oikotie_missing__apartment__project_city(self): elastic_apartment = ApartmentMinimalFactory(project_city=None) try: map_oikotie_apartment(elastic_apartment) except ValueError as e: assert "project_city" in str(e) return raise Exception("Missing project_city should have thrown a ValueError")
def fetch_apartments_for_sale() -> Tuple[list, list]: """ Fetch apartments for sale from elasticsearch and map them for Oikotie """ s_obj = (Search().query("match", _language="fi").query( "match", apartment_state_of_sale=ApartmentStateOfSale.FOR_SALE)) s_obj.execute() scan = s_obj.scan() apartments = [] housing_companies = [] for hit in scan: try: apartment = map_oikotie_apartment(hit) except ValueError: _logger.warning(f"Could not map apartment {hit.uuid}") continue try: housing = map_oikotie_housing_company(hit) except ValueError: _logger.warning(f"Could not map housing company {hit.uuid}") continue apartments.append(apartment) housing_companies.append(housing) if not apartments: _logger.warning( "There were no apartments to map or could not map any apartments") _logger.info(f"Succefully mapped {len(apartments)} apartments for sale") return (apartments, housing_companies)
def test_elastic_to_oikotie__apartment_minimal__mapping_types(self): elastic_apartment = ApartmentMinimalFactory() oikotie_apartment = map_oikotie_apartment(elastic_apartment) check_dataclass_typing(oikotie_apartment)