部署优化
This commit is contained in:
@@ -7,9 +7,19 @@ from datetime import date
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from company_reports.contracts import BatchSnapshot, ErrorCode
|
||||
from openpyxl import load_workbook
|
||||
|
||||
from company_reports.contracts import (
|
||||
BatchSnapshot,
|
||||
CompanyReport,
|
||||
DailyVersionPin,
|
||||
ErrorCode,
|
||||
PeriodReport,
|
||||
ReportRow,
|
||||
)
|
||||
from company_reports.core import build_company_report
|
||||
from company_reports.publishing import (
|
||||
ArtifactToolBuilder,
|
||||
AtomicReportPublisher,
|
||||
BuiltWorkbook,
|
||||
PublicationError,
|
||||
@@ -53,6 +63,38 @@ def empty_report():
|
||||
)
|
||||
|
||||
|
||||
def workbook_report() -> CompanyReport:
|
||||
row = ReportRow(
|
||||
arrival=date(2026, 7, 8),
|
||||
departure=date(2026, 7, 10),
|
||||
nights=2,
|
||||
block_code="=BLOCK-A",
|
||||
res_comment="SYN-GROUP-A",
|
||||
booking_room="【DBL】1",
|
||||
total_booking_price="+900",
|
||||
normalized_group_code="SYN-GROUP-A",
|
||||
record_ids=(1,),
|
||||
duplicate_group=True,
|
||||
multi_price_review=True,
|
||||
)
|
||||
return CompanyReport(
|
||||
company="QBD",
|
||||
report_year=2026,
|
||||
report_month=7,
|
||||
as_of_date=date(2026, 7, 10),
|
||||
filename="QBD-July-2026.xlsx",
|
||||
periods=(
|
||||
PeriodReport(1, 10, True, "QBD 01-10 Jul 2026", (row,)),
|
||||
PeriodReport(11, 20, False, "QBD 11-20 Jul 2026", ()),
|
||||
PeriodReport(21, 31, False, "QBD 21-31 Jul 2026", ()),
|
||||
),
|
||||
warnings=(),
|
||||
errors=(),
|
||||
daily_versions=(DailyVersionPin(date(2026, 7, 8), 100),),
|
||||
booking_versions={"SYN-GROUP-A": 700},
|
||||
)
|
||||
|
||||
|
||||
def synthetic_built_workbook(
|
||||
work_dir: Path,
|
||||
filename: str,
|
||||
@@ -70,6 +112,41 @@ def synthetic_built_workbook(
|
||||
|
||||
|
||||
class CompanyReportPublishingTests(unittest.TestCase):
|
||||
def test_builder_creates_xlsx_without_private_artifact_tool_runtime(self):
|
||||
with tempfile.TemporaryDirectory(prefix="company-report-builder-test-") as temp_dir:
|
||||
root = Path(temp_dir)
|
||||
report = workbook_report()
|
||||
builder = ArtifactToolBuilder(
|
||||
Path("/private/artifact-tool/build_workbook.mjs"),
|
||||
node_binary="/definitely/not/node",
|
||||
)
|
||||
|
||||
built = builder.build(report, root)
|
||||
|
||||
self.assertTrue(built.path.is_file())
|
||||
self.assertEqual(built.path.stat().st_mode & 0o777, 0o600)
|
||||
self.assertEqual(built.summary["status"], "success")
|
||||
self.assertEqual(built.summary["row_counts"], [1, 0, 0])
|
||||
self.assertEqual(built.summary["formula_count"], 0)
|
||||
self.assertEqual(len(built.summary["semantic_sha256"]), 64)
|
||||
workbook = load_workbook(built.path)
|
||||
self.assertEqual(workbook.sheetnames, [period.sheet_name for period in report.periods])
|
||||
sheet = workbook[report.periods[0].sheet_name]
|
||||
self.assertEqual(
|
||||
[cell.value for cell in sheet[1]],
|
||||
[
|
||||
"ARRIVAL",
|
||||
"DEPARTURE",
|
||||
"NIGHTS",
|
||||
"BLOCK_CODE",
|
||||
"RES_COMMENT",
|
||||
"Booking Room",
|
||||
"Total Booking Price",
|
||||
],
|
||||
)
|
||||
self.assertEqual(sheet["D2"].value, "'=BLOCK-A")
|
||||
self.assertEqual(sheet["G2"].value, "'+900")
|
||||
|
||||
def test_publish_archives_prior_current_and_activates_new_version(self):
|
||||
with tempfile.TemporaryDirectory(prefix="company-report-publish-test-") as temp_dir:
|
||||
project_root = Path(temp_dir) / "project"
|
||||
|
||||
Reference in New Issue
Block a user