Skip to content

Commit

Permalink
Missing or unresolvable values for renewal count are treated as zero
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrineyev committed Feb 13, 2025
1 parent ea8a9e4 commit 88d1bf8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/folio_migration_tools/transaction_migration/legacy_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def __init__(
self.out_date: datetime = temp_date_out
self.correct_for_1_day_loans()
self.make_utc()
self.renewal_count = int(legacy_loan_dict["renewal_count"])
self.renewal_count = 0
self.set_renewal_count(legacy_loan_dict)
self.next_item_status = legacy_loan_dict.get("next_item_status", "").strip()
if self.next_item_status not in legal_statuses:
self.errors.append(("Not an allowed status", self.next_item_status))
Expand All @@ -101,6 +102,17 @@ def __init__(
else fallback_service_point_id
)

def set_renewal_count(self, loan: dict):
if "renewal_count" in loan:
renewal_count = loan["renewal_count"]
try:
self.renewal_count = int(renewal_count)
except ValueError:
self.report(
f"Unresolvable {renewal_count=} was replaced with 0.")
else:
self.report(f"Missing renewal count was replaced with 0.")

def correct_for_1_day_loans(self):
try:
if self.due_date.date() <= self.out_date.date():
Expand Down
31 changes: 31 additions & 0 deletions tests/test_legacy_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,34 @@ def test_init_tz_5(): # Test dates with(out) DST
"Provided out_date is not UTC, setting tzinfo to tenant timezone (America/Chicago)"
in migration_report.report["Details"]
)


def test_init_renewal_count_is_empty():
loan_dict = {
"item_barcode": "the barcode with trailing space ",
"patron_barcode": " the barcode with leading space",
"due_date": "20220113 16:00",
"out_date": "20220113 14:00",
"next_item_status": "Checked out",
}
tenant_timezone = ZoneInfo("UTC")
migration_report = MigrationReport()
legacy_loan = LegacyLoan(
loan_dict, "", migration_report, tenant_timezone)
assert legacy_loan.renewal_count == 0


def test_init_renewal_count_is_unresolvable():
loan_dict = {
"item_barcode": "the barcode with trailing space ",
"patron_barcode": " the barcode with leading space",
"due_date": "20220113 16:00",
"out_date": "20220113 14:00",
"renewal_count": "abc",
"next_item_status": "Checked out",
}
tenant_timezone = ZoneInfo("UTC")
migration_report = MigrationReport()
legacy_loan = LegacyLoan(
loan_dict, "", migration_report, tenant_timezone)
assert legacy_loan.renewal_count == 0

0 comments on commit 88d1bf8

Please sign in to comment.