from finn_eiendom.ad import scrape_ad from tests.fixtures import SAMPLE_FINN_LISTING_HTML, SAMPLE_FINN_LISTING_HTML_NEW def test_scrape_ad(): ad = scrape_ad( SAMPLE_FINN_LISTING_HTML, url="https://www.finn.no/realestate/homes/ad.html?finnkode=462400360", ) assert ad.finnkode == "462400360" assert ad.title == "Flott 3-roms i Ferner" assert ad.address == "Fernerveien 42, 0554 Oslo" assert ad.area_m2 == 77 assert ad.asking_price == 7200000 assert ad.total_price == 7200991 assert ad.common_costs == 3500 assert ad.rooms == 4 assert ad.bedrooms == 3 assert ad.floor == "4. etasje" assert ad.construction_year == 2005 assert ad.energy_rating == "C" assert ad.heating == "Fjernvarme" assert "Moderne kjøkken" in ad.listing_description assert ad.broker_company == "Meglerhuset AS" def test_scrape_ad_new_structure(): ad = scrape_ad( SAMPLE_FINN_LISTING_HTML_NEW, url="https://www.finn.no/realestate/homes/ad.html?finnkode=455978973", ) assert ad.finnkode == "455978973" assert ad.title.startswith("Romslig 5-roms i 5.etasje") assert ad.address == "Hegdehaugsveien 3, 0352 Oslo" assert ad.property_type == "Leilighet" assert ad.ownership_type == "Andel" assert ad.asking_price == 10900000 assert ad.total_price == 10986901 assert ad.common_costs == 12011 assert ad.area_m2 == 124 assert ad.rooms == 5 assert ad.bedrooms == 2 assert ad.construction_year == 1938 assert ad.floor == "5. etasje" assert "kort vei" in ad.listing_description.lower()