From 95b17b8776ae969c43ac0955fdbcbcdbe475ab79 Mon Sep 17 00:00:00 2001 From: Jonas Linter <{email_address}> Date: Thu, 9 Oct 2025 09:38:54 +0200 Subject: [PATCH] I think acknowledgments work just fine now --- src/alpine_bits_python/alpine_bits_helpers.py | 4 +- tests/test_alpine_bits_server_read.py | 46 +++++++++++++++++-- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/alpine_bits_python/alpine_bits_helpers.py b/src/alpine_bits_python/alpine_bits_helpers.py index 6d367f6..5975106 100644 --- a/src/alpine_bits_python/alpine_bits_helpers.py +++ b/src/alpine_bits_python/alpine_bits_helpers.py @@ -1,7 +1,7 @@ import logging import traceback from dataclasses import dataclass -from datetime import UTC, datetime +from datetime import UTC from enum import Enum from typing import Any @@ -786,7 +786,7 @@ def _process_single_reservation( ) hotel_reservation = HotelReservation( - create_date_time=datetime.now(UTC).isoformat(), + create_date_time=reservation.created_at.replace(tzinfo=UTC).isoformat(), res_status=HotelReservationResStatus.REQUESTED, room_stay_reservation="true", unique_id=unique_id, diff --git a/tests/test_alpine_bits_server_read.py b/tests/test_alpine_bits_server_read.py index 251a9e9..551ab33 100644 --- a/tests/test_alpine_bits_server_read.py +++ b/tests/test_alpine_bits_server_read.py @@ -713,7 +713,11 @@ class TestAcknowledgments: @pytest.mark.asyncio async def test_acknowledgments_work_with_date_filters( - self, alpinebits_server, populated_db_session, client_info + self, + alpinebits_server, + populated_db_session, + client_info, + read_request_xml_no_date_filter, ): """Test 5: Verify acknowledgments still work when SelectionCriteria date filters are applied.""" # Read request with date filter @@ -749,9 +753,14 @@ class TestAcknowledgments: ): initial_count = len(initial_parsed.reservations_list.hotel_reservation) + assert initial_count > 0, "Initial count with date filter should be > 0" + assert initial_count == 1, ( + "Should only return one reservation with this date filter" + ) + # Acknowledge one reservation that falls within the date range - # The sample_reservation has dates 2024-12-25 to 2024-12-31, which should be in range - sample_unique_id = "RES-2024-001" + # The sample_reservation was created at 2024-11-01 and thus falls out of range + sample_unique_id = "RES-2024-002" md5_hash = hashlib.md5(sample_unique_id.encode()).hexdigest() acked_request = AckedRequest( @@ -762,6 +771,31 @@ class TestAcknowledgments: populated_db_session.add(acked_request) await populated_db_session.commit() + without_filter_read = await alpinebits_server.handle_request( + request_action_name="OTA_Read:GuestRequests", + request_xml=read_request_xml_no_date_filter, + client_info=client_info, + version="2024-10", + dbsession=populated_db_session, + ) + + without_filter_parsed = parser.from_string( + without_filter_read.xml_content, OtaResRetrieveRs + ) + + without_filter_count = 0 + if ( + without_filter_parsed.reservations_list + and without_filter_parsed.reservations_list.hotel_reservation + ): + without_filter_count = len( + without_filter_parsed.reservations_list.hotel_reservation + ) + + assert without_filter_count == 1, ( + "Without date filter, should return one reservation after acknowledgment" + ) + # Second read with same date filter second_response = await alpinebits_server.handle_request( request_action_name="OTA_Read:GuestRequests", @@ -781,8 +815,10 @@ class TestAcknowledgments: ): second_count = len(second_parsed.reservations_list.hotel_reservation) - # Should have fewer reservations even with date filter - assert second_count < initial_count + # Should have exactly the same amount of reservations + assert second_count == initial_count, ( + "Acknowledgment should not affect count when date filter is applied" + ) if __name__ == "__main__":