Skip to content

Commit

Permalink
Merge pull request #522 from dulshen/summary_dob_portal_imports
Browse files Browse the repository at this point in the history
Populate DOB on record summary from Petitioner Info
  • Loading branch information
dulshen authored Dec 15, 2024
2 parents fb11bfb + f0235ba commit 0050aca
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
27 changes: 27 additions & 0 deletions dear_petition/petition/api/tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
OffenseFactory,
ClientFactory,
OffenseRecordFactory,
UserFactory,
)

pytestmark = pytest.mark.django_db
Expand Down Expand Up @@ -77,3 +78,29 @@ def test_adjust_for_new_client_dob():
batch.save()
batch.adjust_for_new_client_dob()
assert offense_record not in batch.underaged_conviction_records()


def test_populate_client_dob_from_batch_dob(api_client):
"""
Tests that when client dob is left empty, it is populated from the batch dob when
batch has an available dob value.
"""
# set up a user that will have access to the batch/client data
user = UserFactory()
api_client.force_authenticate(user=user)

# set dob to use for the batch record and create batch/record
dob = datetime.date(1992, 1, 28)
batch = BatchFactory(user=user, client=None)
CIPRSRecordFactory(batch=batch, dob=dob) # add record with DOB to batch

client = ClientFactory(user=user, dob=None) # add client with no DOB
assert client.dob == None

# use API to assign the client to the batch
data = {"client_id": client.pk}
api_client.post(reverse("api:batch-assign-client-to-batch", args=[batch.pk]), data=data)

# check that client dob updated appropriately during assignment
client.refresh_from_db()
assert client.dob == dob
3 changes: 3 additions & 0 deletions dear_petition/petition/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ def assign_client_to_batch(self, request, pk):
batch = self.get_object()
batch.client = client
batch.save()
if not client.dob and batch.dob:
client.dob = batch.dob
client.save()
batch.adjust_for_new_client_dob()
return Response({"batch_id": batch.pk})

Expand Down
2 changes: 1 addition & 1 deletion dear_petition/petition/export/documents/records_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def generate_summary(batch):


def generate_context(batch, attorney, client):
dob = batch.dob
dob = client.dob if client.dob else batch.dob
birthday_18th = "None"
birthday_22nd = "None"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,68 @@ def test_records_summary_context__birthdays(
assert context["birthday_22nd"] == formatted_22nd_bday


@pytest.mark.parametrize(
"dob, formatted_dob, formatted_18th_bday, formatted_22nd_bday",
[
(date(1986, 6, 15), "06/15/1986", "06/15/2004", "06/15/2008"),
# born in leap year
(date(1996, 2, 29), "02/29/1996", "03/01/2014", "03/01/2018"),
],
)
def test_records_summary_context_no_batch_birthday(
batch, dob, formatted_dob, formatted_18th_bday, formatted_22nd_bday
):
"""
Test generate_context method for a batch that has no date of birth, but client info has
date of birth, (e.g. for portal imported batches)
"""

PETITIONER_INFO_WITH_DOB = {"name": "Pete Petitioner", "dob": dob}

offense = create_offense(
batch, "DURHAM", DISTRICT_COURT, "10CR000001", None, "NOT GUILTY", "JURY TRIAL", False
)
create_offense_record(offense, CHARGED, "SIMPLE ASSAULT", "MISDEMEANOR")

attorney = AttorneyFactory(name="E. Toruney")
client = ClientFactory(**PETITIONER_INFO_WITH_DOB)
context = generate_context(batch, attorney, client)

assert context["dob"] == formatted_dob
assert context["birthday_18th"] == formatted_18th_bday
assert context["birthday_22nd"] == formatted_22nd_bday


def test_records_summary_context_birthdays_discrepancy(batch):
"""
Test generate_context method where client date of birth does not match batch date of birth.
Client date of birth should be used in this case.
"""

client_dob, formatted_dob, formatted_18th_bday, formatted_22nd_bday = (
date(1986, 6, 15),
"06/15/1986",
"06/15/2004",
"06/15/2008",
)
batch_dob = date(1993, 5, 22)

PETITIONER_INFO_WITH_DOB = {"name": "Pete Petitioner", "dob": client_dob}

offense = create_offense(
batch, "DURHAM", DISTRICT_COURT, "10CR000001", batch_dob, "NOT GUILTY", "JURY TRIAL", False
)
create_offense_record(offense, CHARGED, "SIMPLE ASSAULT", "MISDEMEANOR")

attorney = AttorneyFactory(name="E. Toruney")
client = ClientFactory(**PETITIONER_INFO_WITH_DOB)
context = generate_context(batch, attorney, client)

assert context["dob"] == formatted_dob
assert context["birthday_18th"] == formatted_18th_bday
assert context["birthday_22nd"] == formatted_22nd_bday


def test_records_summary_context__additional_offenses(batch):
"""
Test generate_context method with many offense records in a table. Check that addl_offense_file_nos in the table has
Expand Down

0 comments on commit 0050aca

Please sign in to comment.