Esempio n. 1
0
def test_recalculate_petitions(petition):
    petition = PetitionFactory(form_type=constants.UNDERAGED_CONVICTIONS)
    batch = petition.batch
    record = CIPRSRecordFactory(batch=batch,
                                jurisdiction=constants.DISTRICT_COURT,
                                county="DURHAM")
    offense = OffenseFactory(
        disposition_method="PROBATION OTHER",
        ciprs_record=record,
        jurisdiction=constants.DISTRICT_COURT,
    )
    offense_record_ids = []
    for i in range(12):
        offense_record = OffenseRecordFactory(offense=offense,
                                              action="CHARGED")
        petition.offense_records.add(offense_record)
        if len(offense_record_ids) < 5:
            offense_record_ids.append(offense_record.id)
    link_offense_records(petition)
    create_documents(petition)

    assert (petition.offense_records.filter(
        petitionoffenserecord__active=True).count() == 12)
    assert petition.has_attachments()
    recalculate_petitions(petition.id, offense_record_ids)
    assert (petition.offense_records.filter(
        petitionoffenserecord__active=True).count() == 5)
    assert not petition.has_attachments()
def test_not_both_dismissed_and_not_guilty(batch, record1):
    offense = OffenseFactory(
        disposition_method="DISMISSAL WITHOUT LEAVE BY DA",
        verdict="Not Guilty",
        ciprs_record=record1,
    )
    offense_record = OffenseRecordFactory(action="CHARGED", offense=offense)
    assert offense_record not in batch.not_guilty_offense_records(
        jurisdiction=record1.jurisdiction)
Esempio n. 3
0
def test_offense_records_by_jurisdiction(batch, jurisdiction):
    """Offense records helper function should allow filtering by jurisdiction."""
    ciprs_record = CIPRSRecordFactory(jurisdiction=jurisdiction, batch=batch)
    offense = OffenseFactory(
        disposition_method=constants.DISMISSED_DISPOSITION_METHODS[0],
        ciprs_record=ciprs_record,
    )
    offense_record = OffenseRecordFactory(action="CHARGED", offense=offense)
    records = batch.dismissed_offense_records(jurisdiction=jurisdiction)
    assert offense_record in records
def many_offense_records(batch, size):
    for i in range(size):
        record = CIPRSRecordFactory(batch=batch,
                                    jurisdiction=constants.DISTRICT_COURT,
                                    county="DURHAM")
        offense = OffenseFactory(
            disposition_method=dismissed.DISMISSED_DISPOSITION_METHODS[0],
            ciprs_record=record,
            jurisdiction=constants.DISTRICT_COURT,
        )
        OffenseRecordFactory(offense=offense, action="CHARGED")
Esempio n. 5
0
 def create_new_ciprs_record(file_no):
     ciprs_record = CIPRSRecordFactory(
         batch=batch,
         file_no=file_no,
         jurisdiction=constants.DISTRICT_COURT,
         county="DURHAM")
     offense = OffenseFactory(
         ciprs_record=ciprs_record,
         jurisdiction=constants.DISTRICT_COURT,
         disposition_method=dismissed.DISMISSED_DISPOSITION_METHODS[0],
     )
     offense_record = OffenseRecordFactory(offense=offense)
     return offense_record.id
def test_paginator_same_record_number_order(petition, records_10):
    # get the 10th offense record so we can attach one more offense
    # record to the same CIPRSRecord, so that it crosses the
    # attachment boundary
    charge_1 = petition.get_all_offense_records().last()
    # attach a 2nd dismissed charge
    charge_2 = OffenseRecordFactory(
        offense=OffenseFactory(
            disposition_method=dismissed.DISMISSED_DISPOSITION_METHODS[0],
            ciprs_record=charge_1.offense.ciprs_record,
            jurisdiction=constants.DISTRICT_COURT,
        ),
        action="CHARGED",
    )
    link_offense_records_and_attachments(petition)
    attachment = petition.attachments.order_by("pk").first()
    # the 1st charge should always be on the first petition
    assert charge_1.pk in petition.offense_records.values_list("pk", flat=True)
    # the 2nd charge should always be on the attachment
    assert charge_2.pk in attachment.offense_records.values_list("pk",
                                                                 flat=True)
Esempio n. 7
0
def test_guilty_to_lesser(batch, record1):
    offense = OffenseFactory(
        ciprs_record=record1,
        jurisdiction=constants.DISTRICT_COURT,
        plea="GUILTY TO LESSER",
        disposition_method="DISPOSED BY JUDGE",
    )

    offense_record_charged = OffenseRecordFactory(action="CHARGED",
                                                  offense=offense)
    offense_record_convicted = OffenseRecordFactory(action="CONVICTED",
                                                    offense=offense)

    petition = PetitionFactory(
        form_type=constants.DISMISSED,
        jurisdiction=record1.jurisdiction,
        county=record1.county,
        batch=batch,
    )

    petition_offense_records = petition.get_all_offense_records()

    assert offense_record_charged in petition_offense_records
    assert offense_record_convicted not in petition_offense_records
Esempio n. 8
0
def offense1(record2):
    yield OffenseFactory(
        ciprs_record=record2,
        disposition_method=constants.DISTRICT_COURT_WITHOUT_DA_LEAVE,
    )
Esempio n. 9
0
def not_guilty_offense(record1):
    return OffenseFactory(
        ciprs_record=record1,
        jurisdiction=constants.DISTRICT_COURT,
        verdict="Not Guilty",
    )
Esempio n. 10
0
def non_dismissed_offense(record1):
    return OffenseFactory(disposition_method="OTHER", ciprs_record=record1)
Esempio n. 11
0
def dismissed_offense(record1):
    return OffenseFactory(
        disposition_method=dismissed.DISMISSED_DISPOSITION_METHODS[0],
        ciprs_record=record1,
        jurisdiction=constants.DISTRICT_COURT,
    )
def test_non_not_guilty_verdict(batch, record1):
    offense = OffenseFactory(verdict="Guilty", ciprs_record=record1)
    offense_record = OffenseRecordFactory(action="CHARGED", offense=offense)
    assert offense_record not in batch.not_guilty_offense_records()
Esempio n. 13
0
def test_charged_disposition_methods(batch, record1, method):
    """CHARGED offense records should be included for all dismissed disposition methods."""
    offense = OffenseFactory(disposition_method=method, ciprs_record=record1)
    offense_record = OffenseRecordFactory(action="CHARGED", offense=offense)
    assert offense_record in batch.dismissed_offense_records()