Skip to content

Commit

Permalink
Merge pull request #1699 from wittejm/remove-clackamas-form
Browse files Browse the repository at this point in the history
Remove clackamas form
  • Loading branch information
wittejm authored May 11, 2023
2 parents 9fe717a + 28ac825 commit 0aea0ac
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 186 deletions.
Binary file removed src/backend/expungeservice/files/clackamas.pdf
Binary file not shown.
76 changes: 4 additions & 72 deletions src/backend/expungeservice/form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,15 +445,10 @@ class PDF:
DATE_FORMAT = "%b %-d, %Y"
STR_CONNECTOR = "; "

@classmethod
def fill_form(cls, mapper: PDFFieldMapper, should_validate=False):
klass = cls
county = mapper.get("(County)")

if county and county.lower() == "clackamas":
klass = ClackamasPDF
@staticmethod
def fill_form(mapper: PDFFieldMapper, should_validate=False):

pdf = klass(mapper)
pdf = PDF(mapper)
if should_validate:
pdf.validate_initial_state()

Expand Down Expand Up @@ -550,72 +545,9 @@ def validate_initial_state(self):
self.get_annotation_dict()
), "[PDF] PDF fields do not match annotations"


class ClackamasPDF(PDF):
FONT_SIZE_MEDIUM = "8"

def set_text_value(self, annotation, value):
index, is_rest = self._get_list_index(annotation)

if index is None:
super().set_text_value(annotation, value)
return

if index >= len(value):
return

if is_rest:
new_value = "\n".join(
[
f"{c.name}, {c.disposition.date.strftime(self.DATE_FORMAT)}, {c.disposition.status}"
for i, c in enumerate(value)
if i >= index
]
)
elif isinstance(value[index], DateWithFuture):
new_value = value[index].strftime(self.DATE_FORMAT)
else:
new_value = value[index]

annotation.V = PdfString.encode(new_value)
self._set_charges_font(annotation)
annotation.update(PdfDict(AP=""))

def _get_list_index(self, annotation) -> Tuple[Optional[int], bool]:
"""
Parses annotation names and returns the index and whether there
is a "rest" parameter. Ex,
"(Full Name---)" -> (None, False)
"(Eligible Charge Names---1)" -> (1, False)
"(Eligible Charges List---2rest)" -> (2, True)
"""
split_str = annotation.T[1:-1].split(self.mapper.STRING_FOR_DUPLICATES)

if len(split_str) < 2:
return None, False

index_str = split_str[1]
is_rest = "rest" in index_str
idx = None if index_str == "" else int(index_str.split("rest")[0])
return idx, is_rest

def _set_charges_font(self, annotation):
font_size = self.FONT_SIZE

if not "Eligible Charge" in annotation.T:
return super().set_font(annotation)

if "Names" in annotation.T:
font_size = self.FONT_SIZE_SMALL
else: # List
font_size = self.FONT_SIZE_MEDIUM

annotation.DA = PdfString.encode(f"/{self.FONT_FAMILY} {font_size} Tf 0 g")


class FormFilling:
OREGON_PDF_NAME = "oregon"
NON_OREGON_PDF_COUNTIES = ["multnomah", "clackamas"]
NON_OREGON_PDF_COUNTIES = ["multnomah"]
COUNTIES_NEEDING_CONVICTION_OR_ARREST_ORDER = ["douglas", "umatilla", "multnomah"]
COUNTIES_NEEDING_COUNTY_SPECIFIC_DOWNLOAD_NAME = ["douglas", "umatilla"]
OSP_PDF_NAME = "OSP_Form"
Expand Down
114 changes: 0 additions & 114 deletions src/backend/tests/test_form_filling.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,117 +727,3 @@ def test_font_shrinking_and_pdf_write_text(self, MockPdfWriter, pdf_factory: Moc
assert not MockPdfWriter.return_value.addpages.called
pdf.add_text("foo text")
assert MockPdfWriter.return_value.addpages.called


class TestBuildClackamsPDF(TestBuildOregonPDF):
county = "Clackamas"
expected_county_data = {
# county
"(FOR THE COUNTY OF)": "(Clackamas)",
# da_address
"(the District Attorney at address 2)": "(807 Main Street - Oregon City, OR 97045)",
# "(County)": "(Clackamas)",
}
expected_clackamas_order_values = {
"(Case Number)": "(base case number)",
"(Case Name)": "(Case Name 0)",
"(Full Name)": "(foo bar)",
"(Date Of Birth)": "(1/2/1999)",
"(SID---)": "(sid0)",
}
expected_conviction_values = {
# case_number_with_comments
"(Case No)": "(base case number)",
# not has_no_complaint
"(record of arrest with charges filed and the associated check all that apply)": "/On",
# conviction_dates
"(Date of conviction contempt finding or judgment of GEI)": "(Dec 3, 1999)",
# has_conviction
"(conviction)": "/On",
"(ORS 137225 does not prohibit a setaside of this conviction see Instructions)": "/On",
"(I have fully completed complied with or performed all terms of the sentence of the court)": "/On",
# Clackamas order
"(Eligible Charge Names---0)": "(Aggravated Theft In The First Degree)",
"(Eligible Arrest Dates All---0)": "(Feb 3, 2020)",
"(Eligible Dispositions---0)": "(Convicted)",
}

def assert_pdf_values(self, pdf: PDF, new_expected_values):
all_expected_values = {
**self.expected_county_data,
**self.expected_base_values,
**self.expected_clackamas_order_values,
**new_expected_values,
}
assert_pdf_values(pdf, all_expected_values)

@pytest.fixture
def conviction_charge_factory(self) -> Callable:
def factory(
name="Aggravated Theft in the First Degree",
charge_type=FelonyClassB(),
disposition_status=DispositionStatus.CONVICTED,
):
charge = Mock(spec=Charge)
charge.date = create_date(2020, 2, 3)
charge.name = name
charge.edit_status = "not delete"
charge.expungement_result.charge_eligibility.status = ChargeEligibilityStatus.ELIGIBLE_NOW
charge.charge_type = charge_type
charge.disposition = Mock()
charge.disposition.date = create_date(1999, 12, 3)
charge.disposition.status = disposition_status
charge.convicted.return_value = True
charge.dismissed.return_value = False
charge.probation_revoked = False
return charge

return factory

@pytest.fixture
def conviction_charge(self, conviction_charge_factory: Callable) -> Mock:
return conviction_charge_factory()

def test_multiple_charges(self, case: Mock, conviction_charge_factory: Callable):
charge0 = conviction_charge_factory(charge_type=Mock())
charge_name = "Person under 21 Attempt to Purchase Alcoholic Beverages Reduced - DA Elected "
extra_charges = [conviction_charge_factory(charge_name + str(i), charge_type=Mock()) for i in range(50)]
case.charges = [charge0] + extra_charges
case_results = CaseResults.build(case, self.user_data, sid="sid0")

pdf = FormFilling._create_pdf(case_results, validate_initial_pdf_state=False)

charge_date = "Dec 3, 1999"
charge_disposition = "Convicted"
rest_charges_str = "\n".join([f"{charge_name}{i}, {charge_date}, {charge_disposition}" for i in range(1, 50)])
expected_values = {
"(Eligible Charge Names---1)": "(Person Under 21 Attempt To Purchase Alcoholic Beverages Reduced - Da Elected 0)",
"(Eligible Arrest Dates All---1)": "(Feb 3, 2020)",
"(Eligible Dispositions---1)": "(Convicted)",
"(Eligible Charges List---2rest)": "(" + rest_charges_str + ")",
}

self.assert_pdf_values(pdf, {**self.expected_conviction_values, **expected_values})

def test_has_no_complaint_has_dismissed(self, conviction_charge_factory: Callable, pdf_factory: Callable):
new_expected_values = {
"(record of arrest with no charges filed)": "/On",
"(no accusatory instrument was filed and at least 60 days have passed since the)": "/On",
"(an accusatory instrument was filed and I was acquitted or the case was dismissed)": "/On",
"(record of citation or charge that was dismissedacquitted)": "/On",
"(Case No)": "(base case number)",
"(Eligible Charge Names---0)": "(Aggravated Theft In The First Degree)",
"(Eligible Arrest Dates All---0)": "(Feb 3, 2020)",
"(Eligible Dispositions---0)": "(Dismissed)",
}
charge = conviction_charge_factory(disposition_status=DispositionStatus.DISMISSED)
charge.disposition.date = create_date(2023, 6, 7)
charge.charge_type = Mock()
charge.date = create_date(2020, 2, 3)
charge.convicted.return_value = False
charge.dismissed.return_value = True

self.assert_pdf_values(pdf_factory([charge]), new_expected_values)

def test_oregon_base_case(self, case: Mock):
pass

0 comments on commit 0aea0ac

Please sign in to comment.