Skip to content

Commit

Permalink
Change labels with past dates to show "Now"
Browse files Browse the repository at this point in the history
  • Loading branch information
KentShikama committed Apr 13, 2020
1 parent 95624d4 commit ea9b24a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/backend/expungeservice/record_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def compute_charge_eligibility(
):
return ChargeEligibility(
ChargeEligibilityStatus.POSSIBLY_WILL_BE_ELIGIBLE,
f"Possibly Eligible Now OR {will_be_eligibles_string} (review)",
f"Possibly Eligible Now {will_be_eligibles_string} (review)",
)
else:
return ChargeEligibility(
Expand All @@ -164,12 +164,22 @@ def compute_charge_eligibility(
if all([time_eligibility.status == EligibilityStatus.ELIGIBLE for time_eligibility in time_eligibilities]):
return ChargeEligibility(ChargeEligibilityStatus.ELIGIBLE_NOW, "Eligible")
else:
date_will_be_eligibles = [
will_be_eligibles = [
time_eligibility.date_will_be_eligible.strftime("%b %-d, %Y")
for time_eligibility in time_eligibilities
if time_eligibility.status != EligibilityStatus.ELIGIBLE
]
eligible_date_string = " ⬥ ".join(date_will_be_eligibles)
return ChargeEligibility(ChargeEligibilityStatus.WILL_BE_ELIGIBLE, f"Eligible {eligible_date_string}")
eligible_date_string = " ⬥ ".join(will_be_eligibles)
if any(
[time_eligibility.status == EligibilityStatus.ELIGIBLE for time_eligibility in time_eligibilities]
):
return ChargeEligibility(
ChargeEligibilityStatus.WILL_BE_ELIGIBLE, f"Eligible Now ⬥ {eligible_date_string}"
)
else:
return ChargeEligibility(
ChargeEligibilityStatus.WILL_BE_ELIGIBLE, f"Eligible {eligible_date_string}"
)
else:
raise ValueError("Either all, some, or no time eligibilities will have an eligibility date of date.max.")

Expand Down
21 changes: 18 additions & 3 deletions src/backend/tests/models/test_expungement_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ def test_eligible():


def test_will_be_eligible():
today = date.today()
type_eligibility = TypeEligibility(EligibilityStatus.ELIGIBLE, "Eligible under some statute")
time_eligibility = TimeEligibility(EligibilityStatus.INELIGIBLE, "Ineligible under some statute", today)
time_eligibility = TimeEligibility(
EligibilityStatus.INELIGIBLE, "Ineligible under some statute", Time.ONE_YEARS_FROM_NOW
)
charge_eligibility = RecordMerger.compute_charge_eligibility(type_eligibility, [time_eligibility])

assert charge_eligibility.status == ChargeEligibilityStatus.WILL_BE_ELIGIBLE
assert charge_eligibility.label == f"Eligible {today.strftime('%b %-d, %Y')}"
assert charge_eligibility.label == f"Eligible {Time.ONE_YEARS_FROM_NOW.strftime('%b %-d, %Y')}"


def test_possibly_eligible():
Expand Down Expand Up @@ -48,6 +49,20 @@ def test_possibly_will_be_eligible():
assert charge_eligibility.label == f"Possibly Eligible {Time.ONE_YEARS_FROM_NOW.strftime('%b %-d, %Y')} (review)"


def test_multiple_will_be_eligible():
type_eligibility = TypeEligibility(EligibilityStatus.ELIGIBLE, "Eligible under some statute")
time_eligibility = TimeEligibility(EligibilityStatus.ELIGIBLE, "Eligible Now", Time.THREE_YEARS_AGO)
time_eligibility_2 = TimeEligibility(
EligibilityStatus.INELIGIBLE, "Ineligible under some statute", Time.ONE_YEARS_FROM_NOW
)
charge_eligibility = RecordMerger.compute_charge_eligibility(
type_eligibility, [time_eligibility, time_eligibility_2]
)

assert charge_eligibility.status == ChargeEligibilityStatus.WILL_BE_ELIGIBLE
assert charge_eligibility.label == f"Eligible Now ⬥ {Time.ONE_YEARS_FROM_NOW.strftime('%b %-d, %Y')}"


def test_ineligible():
type_eligibility = TypeEligibility(EligibilityStatus.INELIGIBLE, "Ineligible under some statute")
charge_eligibility = RecordMerger.compute_charge_eligibility(type_eligibility, [])
Expand Down

0 comments on commit ea9b24a

Please sign in to comment.