Ejemplo n.º 1
0
def generate_supervision_violation(
        person, **kwargs) -> schema.StateSupervisionViolation:
    args = {
        "state_code": _STATE_CODE,
    }
    args.update(kwargs)
    return schema.StateSupervisionViolation(person=person, **args)
def generate_test_supervision_violation(person_id,
                                        supervision_violation_responses) -> \
        state_schema.StateSupervisionViolation:

    instance = state_schema.StateSupervisionViolation(
        supervision_violation_id=321,
        violation_type=StateSupervisionViolationType.TECHNICAL.value,
        state_code='us_ca',
        person_id=person_id,
        supervision_violated_conditions=[
            state_schema.StateSupervisionViolatedConditionEntry(
                supervision_violated_condition_entry_id=765,
                state_code='us_ca',
                condition='CURFEW',
                person_id=person_id,
            )
        ],
        supervision_violation_types=[
            state_schema.StateSupervisionViolationTypeEntry(
                supervision_violation_type_entry_id=987,
                state_code='us_ca',
                violation_type=StateSupervisionViolationType.TECHNICAL.value,
                violation_type_raw_text='T',
                person_id=person_id,
            )
        ],
        supervision_violation_responses=supervision_violation_responses
    )

    return instance
Ejemplo n.º 3
0
 def test_removeSeosFromViolationIds_unexpectedFormat(self):
     with pytest.raises(ValueError):
         sv = schema.StateSupervisionViolation(external_id='bad_id')
         sp = schema.StateSupervisionPeriod(
             supervision_violation_entries=[sv])
         ss = schema.StateSupervisionSentence(supervision_periods=[sp])
         sg = schema.StateSentenceGroup(supervision_sentences=[ss])
         p = schema.StatePerson(sentence_groups=[sg])
         remove_suffix_from_violation_ids([p])
Ejemplo n.º 4
0
def generate_test_supervision_violation(person_id,
                                        supervision_violation_responses) -> \
        state_schema.StateSupervisionViolation:

    instance = state_schema.StateSupervisionViolation(
        supervision_violation_id=321,
        violation_type=StateSupervisionViolationType.TECHNICAL.value,
        state_code='us_ca',
        person_id=person_id,
        supervision_violation_responses=supervision_violation_responses)

    return instance
Ejemplo n.º 5
0
    def test_removeSeosFromViolationIds(self):
        svr = schema.StateSupervisionViolationResponse(
            external_id='DOC-CYC-VSN1-SEO-FSO')
        sv = schema.StateSupervisionViolation(
            external_id='DOC-CYC-VSN1-SEO-FSO',
            supervision_violation_responses=[svr])
        svr_2 = schema.StateSupervisionViolationResponse(
            external_id='DOC-CYC-VSN1-SEO-FSO')
        sv_2 = schema.StateSupervisionViolation(
            external_id='DOC-CYC-VSN1-SEO-FSO',
            supervision_violation_responses=[svr_2])
        sp = schema.StateSupervisionPeriod(
            supervision_violation_entries=[sv, sv_2])
        ss = schema.StateSupervisionSentence(supervision_periods=[sp])
        sg = schema.StateSentenceGroup(supervision_sentences=[ss])
        p = schema.StatePerson(sentence_groups=[sg])

        expected_svr = StateSupervisionViolationResponse.new_with_defaults(
            external_id='DOC-CYC-VSN1')
        expected_sv = StateSupervisionViolation.new_with_defaults(
            external_id='DOC-CYC-VSN1',
            supervision_violation_responses=[expected_svr])
        expected_svr_2 = attr.evolve(expected_svr)
        expected_sv_2 = attr.evolve(
            expected_sv,
            supervision_violation_responses=[expected_svr_2])
        expected_sp = StateSupervisionPeriod.new_with_defaults(
            supervision_violation_entries=[expected_sv, expected_sv_2])
        expected_ss = StateSupervisionSentence.new_with_defaults(
            supervision_periods=[expected_sp])
        expected_sg = StateSentenceGroup.new_with_defaults(
            supervision_sentences=[expected_ss])
        expected_p = StatePerson.new_with_defaults(
            sentence_groups=[expected_sg])

        remove_suffix_from_violation_ids([p])
        self.assertEqual(expected_p, self.to_entity(p))
Ejemplo n.º 6
0
 def test_removeSeosFromViolationIds_unexpectedFormat(self) -> None:
     with pytest.raises(ValueError) as e:
         sv = schema.StateSupervisionViolation(external_id="bad_id")
         sp = schema.StateSupervisionPeriod(
             supervision_violation_entries=[sv],
             status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
         )
         ss = schema.StateSupervisionSentence(supervision_periods=[sp])
         sg = schema.StateSentenceGroup(supervision_sentences=[ss])
         p = schema.StatePerson(sentence_groups=[sg])
         remove_suffix_from_violation_ids([p])
     self.assertEqual(
         str(e.value),
         "Unexpected id format [bad_id] for [StateSupervisionViolation(external_id=bad_id)]",
     )
Ejemplo n.º 7
0
    def build_data_dict(
            fake_person_id: int,
            fake_supervision_violation_id: int) -> Dict[str, List[Any]]:
        """Builds a data_dict for a basic run of the pipeline."""
        fake_person = schema.StatePerson(
            state_code="US_XX",
            person_id=fake_person_id,
            gender=Gender.FEMALE,
            birthdate=date(1985, 2, 1),
        )
        persons_data = [normalized_database_base_dict(fake_person)]

        race_1 = schema.StatePersonRace(
            person_race_id=111,
            state_code="US_XX",
            race=Race.ASIAN,
            person_id=fake_person_id,
        )
        race_2 = schema.StatePersonRace(
            person_race_id=111,
            state_code="US_XX",
            race=Race.AMERICAN_INDIAN_ALASKAN_NATIVE,
            person_id=fake_person_id,
        )

        races_data = normalized_database_base_dict_list([race_1, race_2])

        ethnicity = schema.StatePersonEthnicity(
            person_ethnicity_id=111,
            state_code="US_XX",
            ethnicity=Ethnicity.NOT_HISPANIC,
            person_id=fake_person_id,
        )

        ethnicity_data = normalized_database_base_dict_list([ethnicity])

        violation_type = schema.StateSupervisionViolationTypeEntry(
            state_code="US_XX",
            violation_type=StateSupervisionViolationType.FELONY,
            person_id=fake_person_id,
        )
        incomplete_response = schema.StateSupervisionViolationResponse(
            state_code="US_XX",
            supervision_violation_response_id=1234,
            response_type=entities.StateSupervisionViolationResponseType.
            VIOLATION_REPORT,
            response_date=date(2021, 1, 4),
            is_draft=False,
            person_id=fake_person_id,
        )
        violation = schema.StateSupervisionViolation(
            state_code="US_XX",
            supervision_violation_id=fake_supervision_violation_id,
            violation_date=date(2021, 1, 1),
            is_violent=False,
            is_sex_offense=False,
            supervision_violation_types=[violation_type],
            supervision_violation_responses=[incomplete_response],
            person_id=fake_person_id,
        )
        incomplete_response.supervision_violation_id = fake_supervision_violation_id
        violation_type.supervision_violation_id = fake_supervision_violation_id

        violation_decision = schema.StateSupervisionViolationResponseDecisionEntry(
            state_code="US_XX",
            decision=StateSupervisionViolationResponseDecision.
            SHOCK_INCARCERATION,
            person_id=fake_person_id,
            supervision_violation_response_decision_entry_id=234,
            supervision_violation_response_id=1234,
        )
        complete_violation_response = schema.StateSupervisionViolationResponse(
            state_code="US_XX",
            supervision_violation_response_id=1234,
            response_type=entities.StateSupervisionViolationResponseType.
            VIOLATION_REPORT,
            response_date=date(2021, 1, 4),
            is_draft=False,
            supervision_violation_response_decisions=[violation_decision],
            person_id=fake_person_id,
        )
        complete_violation_response.supervision_violation_id = (
            fake_supervision_violation_id)

        violations_data = [normalized_database_base_dict(violation)]
        violation_responses_data = [
            normalized_database_base_dict(complete_violation_response)
        ]
        violation_types_data = [normalized_database_base_dict(violation_type)]
        violation_decisions_data = [
            normalized_database_base_dict(violation_decision)
        ]

        state_race_ethnicity_population_count_data = [{
            "state_code":
            "US_XX",
            "race_or_ethnicity":
            "ASIAN",
            "population_count":
            1,
            "representation_priority":
            1,
        }]

        data_dict: Dict[str, List[Any]] = {
            schema.StatePerson.__tablename__:
            persons_data,
            schema.StatePersonRace.__tablename__:
            races_data,
            schema.StatePersonEthnicity.__tablename__:
            ethnicity_data,
            schema.StateSupervisionViolation.__tablename__:
            violations_data,
            schema.StateSupervisionViolationResponse.__tablename__:
            violation_responses_data,
            schema.StateSupervisionViolationTypeEntry.__tablename__:
            violation_types_data,
            schema.StateSupervisionViolatedConditionEntry.__tablename__: [],
            schema.StateSupervisionViolationResponseDecisionEntry.__tablename__:
            violation_decisions_data,
            schema.StatePersonExternalId.__tablename__: [],
            schema.StatePersonAlias.__tablename__: [],
            schema.StateAssessment.__tablename__: [],
            schema.StateProgramAssignment.__tablename__: [],
            schema.StateSentenceGroup.__tablename__: [],
            "state_race_ethnicity_population_counts":
            state_race_ethnicity_population_count_data,
        }
        return data_dict
Ejemplo n.º 8
0
    def test_removeSeosFromViolationIds(self) -> None:
        svr = schema.StateSupervisionViolationResponse(
            state_code=_STATE_CODE, external_id="DOC-CYC-VSN1-SEO-FSO")
        sv = schema.StateSupervisionViolation(
            state_code=_STATE_CODE,
            external_id="DOC-CYC-VSN1-SEO-FSO",
            supervision_violation_responses=[svr],
        )
        svr_2 = schema.StateSupervisionViolationResponse(
            state_code=_STATE_CODE, external_id="DOC-CYC-VSN1-SEO-FSO")
        sv_2 = schema.StateSupervisionViolation(
            state_code=_STATE_CODE,
            external_id="DOC-CYC-VSN1-SEO-FSO",
            supervision_violation_responses=[svr_2],
        )
        sp = schema.StateSupervisionPeriod(
            state_code=_STATE_CODE,
            supervision_violation_entries=[sv, sv_2],
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )
        ss = schema.StateSupervisionSentence(
            state_code=_STATE_CODE,
            supervision_periods=[sp],
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
        )
        sg = schema.StateSentenceGroup(
            state_code=_STATE_CODE,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            supervision_sentences=[ss],
        )
        p = schema.StatePerson(state_code=_STATE_CODE, sentence_groups=[sg])

        expected_svr = StateSupervisionViolationResponse.new_with_defaults(
            state_code=_STATE_CODE, external_id="DOC-CYC-VSN1")
        expected_sv = StateSupervisionViolation.new_with_defaults(
            state_code=_STATE_CODE,
            external_id="DOC-CYC-VSN1",
            supervision_violation_responses=[expected_svr],
        )
        expected_svr_2 = attr.evolve(expected_svr)
        expected_sv_2 = attr.evolve(
            expected_sv, supervision_violation_responses=[expected_svr_2])
        expected_sp = StateSupervisionPeriod.new_with_defaults(
            state_code=_STATE_CODE,
            supervision_violation_entries=[expected_sv, expected_sv_2],
            status=StateSupervisionPeriodStatus.PRESENT_WITHOUT_INFO,
        )
        expected_ss = StateSupervisionSentence.new_with_defaults(
            state_code=_STATE_CODE,
            supervision_periods=[expected_sp],
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
        )
        expected_sg = StateSentenceGroup.new_with_defaults(
            state_code=_STATE_CODE,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO,
            supervision_sentences=[expected_ss],
        )
        expected_p = StatePerson.new_with_defaults(
            state_code=_STATE_CODE, sentence_groups=[expected_sg])

        remove_suffix_from_violation_ids([p])
        self.assertEqual(expected_p, self.to_entity(p))