Skip to content

Commit

Permalink
Handle missing dob in record summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Drabenstott committed Jan 27, 2024
1 parent 12248aa commit c8c1343
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 5 additions & 2 deletions dear_petition/petition/export/documents/records_summary.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import logging
from django.conf import settings
from docxtpl import DocxTemplate
Expand Down Expand Up @@ -155,6 +156,8 @@ def __create_offense_record_data(offense_record):

def __format_date(date):
"""
Format the date for the Summary Document.
Format the date for the Summary Document. If not a date or datetime, return empty string.
"""
return utils.format_petition_date(date)
if isinstance(date, (datetime.date, datetime.datetime)):
return utils.format_petition_date(date)
return ""
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import datetime

import pytest
from datetime import date

from dear_petition.petition.export.documents.records_summary import generate_context
from dear_petition.petition.export.documents.records_summary import generate_context, __format_date
from dear_petition.petition.tests.factories import (
AttorneyFactory, CIPRSRecordFactory, ClientFactory, OffenseRecordFactory, OffenseFactory,
)
Expand Down Expand Up @@ -369,6 +371,17 @@ def test_records_summary_context__additional_offenses(batch):
assert not offense_records[4]["has_additional_offenses"]


@pytest.mark.parametrize("input_date, expected_output", [
(datetime.datetime(2024, 1, 31, 11, 59, 59), "01/31/2024"),
(datetime.date(2024, 1, 31), "01/31/2024"),
(None, ""),
("", ""),
("not a date", ""),
])
def test_format_date(input_date, expected_output):
assert __format_date(input_date) == expected_output


def create_offense_record(offense, action, description, severity):
"""
Create offense record
Expand Down

0 comments on commit c8c1343

Please sign in to comment.