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