Added tests for double reservation by one customer

This commit is contained in:
Jonas Linter
2025-10-10 16:50:43 +02:00
parent 1248772f60
commit 5cec464ac2

View File

@@ -830,6 +830,123 @@ class TestAcknowledgments:
"Acknowledgment should not affect count when date filter is applied"
)
@pytest.mark.asyncio
async def test_same_customer_multiple_reservations(
self,
alpinebits_server,
test_db_session,
client_info,
sample_customer,
):
"""Test same customer with multiple reservations returns all."""
# Add the customer to the database
test_db_session.add(sample_customer)
await test_db_session.commit()
# Create two reservations for the same customer
first_reservation = ReservationData(
unique_id="RES-2024-MULTI-001",
start_date=date(2024, 12, 25),
end_date=date(2024, 12, 31),
num_adults=2,
num_children=0,
children_ages=[],
hotel_code="HOTEL123",
hotel_name="Alpine Paradise Resort",
created_at=datetime(2024, 11, 1, 12, 0, 0, tzinfo=UTC),
)
second_reservation = ReservationData(
unique_id="RES-2024-MULTI-002",
start_date=date(2025, 3, 15),
end_date=date(2025, 3, 20),
num_adults=2,
num_children=1,
children_ages=[10],
hotel_code="HOTEL123",
hotel_name="Alpine Paradise Resort",
created_at=datetime(2024, 11, 15, 10, 0, 0, tzinfo=UTC),
)
# Convert to DB reservations
first_data = first_reservation.model_dump(exclude_none=True)
children_list = first_data.pop("children_ages", [])
children_csv = (
",".join(str(int(a)) for a in children_list) if children_list else ""
)
first_data["children_ages"] = children_csv
db_first_reservation = Reservation(
id=100,
customer_id=sample_customer.id,
**first_data,
)
second_data = second_reservation.model_dump(exclude_none=True)
children_list = second_data.pop("children_ages", [])
children_csv = (
",".join(str(int(a)) for a in children_list) if children_list else ""
)
second_data["children_ages"] = children_csv
db_second_reservation = Reservation(
id=101,
customer_id=sample_customer.id,
**second_data,
)
# Add both reservations to the database
test_db_session.add(db_first_reservation)
test_db_session.add(db_second_reservation)
await test_db_session.commit()
# Send read request
read_xml = """<?xml version="1.0" encoding="UTF-8"?>
<OTA_ReadRQ xmlns="http://www.opentravel.org/OTA/2003/05"
EchoToken="12345"
TimeStamp="2024-10-07T10:00:00"
Version="8.000">
<ReadRequests>
<HotelReadRequest HotelCode="HOTEL123" HotelName="Alpine Paradise Resort"/>
</ReadRequests>
</OTA_ReadRQ>"""
response = await alpinebits_server.handle_request(
request_action_name="OTA_Read:GuestRequests",
request_xml=read_xml,
client_info=client_info,
version="2024-10",
dbsession=test_db_session,
)
assert response is not None
assert response.status_code == HTTP_OK
# Parse response to verify both reservations are returned
parser = XmlParser()
parsed_response = parser.from_string(response.xml_content, OtaResRetrieveRs)
assert parsed_response.reservations_list is not None
assert parsed_response.reservations_list.hotel_reservation is not None
reservation_count = len(parsed_response.reservations_list.hotel_reservation)
expected_reservations = 2
assert reservation_count == expected_reservations, (
"Should return 2 reservations for the same customer"
)
# Verify both reservations are present in the response
xml_content = response.xml_content
assert "John" in xml_content # Customer first name
assert "Doe" in xml_content # Customer last name
# Both reservations should be linked to the same customer
# Verify this by checking that customer appears in both reservation contexts
min_customer_name_occurrences = 2
assert xml_content.count("John") >= min_customer_name_occurrences, (
"Customer name should appear for each reservation"
)
if __name__ == "__main__":
pytest.main([__file__, "-v"])