fix: support bilingual Booking Excel headers

This commit is contained in:
Wyndham ARR
2026-08-11 15:29:42 +08:00
parent ca3e8e18fa
commit c947230471
15 changed files with 366 additions and 30 deletions

View File

@@ -31,6 +31,37 @@ def valid_workbook() -> bytes:
return output.getvalue()
def bilingual_workbook(*, exact_headers: bool = True) -> bytes:
workbook = Workbook()
worksheet = workbook.active
worksheet.title = "QBD"
worksheet.append(["QBD export"])
worksheet.append([])
tour_header = "Tour Code / 主团号" if exact_headers else "Tour Code / 主团号(备用)"
worksheet.append(
[
"Month",
"NO.",
tour_header,
"Tour Days",
"Raw Hotel Detail / วางข้อมูลที่นี่ / 酒店明细",
]
)
worksheet.append(
[
"2026-08",
1,
"SYN-G1",
"",
"酒店 (【U-TWN8.5】 2,【U-เตียงเสริม13】 1)",
]
)
output = io.BytesIO()
workbook.save(output)
workbook.close()
return output.getvalue()
def summary(disposition: str = "imported_and_activated") -> BookingSourceSummary:
return BookingSourceSummary(
source_batch_id=7,
@@ -199,6 +230,31 @@ class ProgramBookingSourceCoordinatorTests(unittest.TestCase):
self.assertEqual(len(repository.created), 1)
self.assertEqual(repository.created[0][1].original_filename, "Booking 报表.xlsx")
def test_bilingual_header_upload_is_stored_then_becomes_review_draft(self) -> None:
store = FakeStore()
repository = FakeRepository()
coordinator = ProgramBookingSourceCoordinator(store, repository)
result = coordinator.submit("QBD 八月.xlsx", bilingual_workbook())
self.assertEqual(result["summary"]["filename"], "Booking 报表.xlsx")
self.assertEqual(result["summary"]["pending_items"], 1)
self.assertEqual(len(store.calls), 1)
self.assertEqual(store.calls[0]["original_filename"], "QBD 八月.xlsx")
self.assertEqual(len(repository.created), 1)
def test_unrecognized_bilingual_header_never_reaches_storage_or_database(self) -> None:
store = FakeStore()
repository = FakeRepository()
coordinator = ProgramBookingSourceCoordinator(store, repository)
with self.assertRaises(PortalError) as raised:
coordinator.submit("not.xlsx", bilingual_workbook(exact_headers=False))
self.assertEqual(raised.exception.code, "BOOKING_EXCEL_HEADERS_MISSING")
self.assertEqual(store.calls, [])
self.assertEqual(repository.created, [])
def test_reextracting_same_content_still_creates_a_fresh_draft(self) -> None:
store = FakeStore()
repository = FakeRepository(summary())