Repository navigation
Expand file tree
/
Copy pathtest_webhook.py
More file actions
60 lines (55 loc) · 1.92 KB
/
Copy pathtest_webhook.py
File metadata and controls
60 lines (55 loc) · 1.92 KB
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
54
55
56
57
58
59
60
import pytest
from bs4 import BeautifulSoup
from main import parse_booking_html
def test_parse_booking_html_with_ids():
html = """
<html>
<body>
<h1>Booking Confirmation</h1>
<p>Guest: <span id="guest_name">John Doe</span></p>
<p>Check-in: <span id="check_in">2026-08-01</span></p>
<p>Check-out: <span id="check_out">2026-08-05</span></p>
<p>Total Price: <span id="total_price">$450.50</span></p>
</body>
</html>
"""
result = parse_booking_html(html)
assert result["guest_name"] == "John Doe"
assert result["check_in"].strftime("%Y-%m-%d") == "2026-08-01"
assert result["check_out"].strftime("%Y-%m-%d") == "2026-08-05"
assert result["total_price"] == 450.5
def test_parse_booking_html_with_tables():
html = """
<html>
<body>
<h1>Booking Details</h1>
<table>
<tr>
<th>Guest Name</th>
<td>Jane Smith</td>
</tr>
<tr>
<th>Check-in Date</th>
<td>2026-09-10</td>
</tr>
<tr>
<th>Check-out Date</th>
<td>2026-09-12</td>
</tr>
<tr>
<th>Total Price</th>
<td>$200.00</td>
</tr>
</table>
</body>
</html>
"""
result = parse_booking_html(html)
assert result["guest_name"] == "Jane Smith"
assert result["check_in"].strftime("%Y-%m-%d") == "2026-09-10"
assert result["check_out"].strftime("%Y-%m-%d") == "2026-09-12"
assert result["total_price"] == 200.0
def test_parse_booking_html_missing_fields():
html = "<html><body><p>No booking info here</p></body></html>"
with pytest.raises(ValueError, match="Missing required booking fields in email"):
parse_booking_html(html)