File size: 1,769 Bytes
97c8e04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import pytest
import asyncio
import re
from unittest.mock import AsyncMock, MagicMock
from patchright_airbnb_scraper import PatchrightAirbnbScraper
from booking_scraper import BookingScraper

@pytest.mark.asyncio
async def test_airbnb_multi_image_extraction():
    scraper = PatchrightAirbnbScraper()
    # Mock markdown with multiple images and required structure
    markdown = """
![img1](https://test.com/1.jpg)
![img2](https://test.com/2.jpg)
![img3](https://test.com/3.jpg)
### Apartment in Heidelberg
Luxury Loft
€ 700 for 7 nights
https://www.airbnb.com/rooms/12345
"""
    deals = scraper._parse_markdown(markdown, "Heidelberg", 7)
    
    print(f"Deals found: {len(deals)}")
    assert len(deals) > 0
    # We expect an 'images' key with a list
    assert "images" in deals[0]
    assert len(deals[0]["images"]) == 3
    assert deals[0]["images"][0] == "https://test.com/1.jpg?im_w=720"

@pytest.mark.asyncio
async def test_booking_multi_image_extraction():
    scraper = BookingScraper()
    # Mock HTML with multiple images in a card
    html = """
    <div data-testid="property-card">
        <h3 data-testid="title">Grand Hotel</h3>
        <img data-testid="image" src="https://img.com/1.jpg">
        <div class="hidden-images">
            <img src="https://img.com/2.jpg">
            <img src="https://img.com/3.jpg">
        </div>
        <div data-testid="price-and-discounted-price">€ 700</div>
    </div>
    """
    from bs4 import BeautifulSoup
    soup = BeautifulSoup(html, 'html.parser')
    deals = scraper._parse_html(soup, "Heidelberg", "2026-03-08", "2026-03-15", 7)
    
    assert len(deals) > 0
    assert "images" in deals[0]
    assert len(deals[0]["images"]) == 3
    assert deals[0]["images"][0] == "https://img.com/1.jpg"