コード例 #1
0
def get_violation_type_subtype_strings_for_violation(
    violation: StateSupervisionViolation,
) -> List[str]:
    """Returns a list of strings that represent the violation subtypes present on the given |violation|. If there's no
    state-specific logic for determining the subtypes, then a list of the violation_type raw values in the violation's
    supervision_violation_types is returned."""
    if violation.state_code.upper() == "US_MO":
        return us_mo_violation_utils.us_mo_get_violation_type_subtype_strings_for_violation(
            violation
        )
    if violation.state_code.upper() == "US_PA":
        return us_pa_violation_utils.us_pa_get_violation_type_subtype_strings_for_violation(
            violation
        )

    supervision_violation_types = violation.supervision_violation_types

    if supervision_violation_types:
        return [
            violation_type_entry.violation_type.value
            for violation_type_entry in supervision_violation_types
            if violation_type_entry.violation_type
        ]

    return []
コード例 #2
0
    def test_us_pa_get_violation_type_subtype_strings_for_violation_no_types(
            self) -> None:
        # Arrange
        violation = StateSupervisionViolation.new_with_defaults(
            state_code=_STATE_CODE, supervision_violation_types=None)

        # Act
        type_subtype_strings = us_pa_get_violation_type_subtype_strings_for_violation(
            violation)

        # Assert
        expected_type_subtype_strings: List[str] = []
        self.assertEqual(expected_type_subtype_strings, type_subtype_strings)
コード例 #3
0
    def test_us_pa_get_violation_type_subtype_strings_for_violation(
            self) -> None:
        # Arrange
        violation = StateSupervisionViolation.new_with_defaults(
            state_code=_STATE_CODE,
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    violation_type=StateSupervisionViolationType.LAW)
            ])

        # Act
        type_subtype_strings = us_pa_get_violation_type_subtype_strings_for_violation(
            violation)

        # Assert
        expected_type_subtype_strings = ['LAW']
        self.assertEqual(expected_type_subtype_strings, type_subtype_strings)
コード例 #4
0
    def test_us_pa_get_violation_type_subtype_strings_for_violation_unsupported_raw_text(
            self) -> None:
        # Arrange
        violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code='US_PA',
            violation_date=date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text='XL'),
            ])

        # Act
        with pytest.raises(ValueError):
            _ = us_pa_get_violation_type_subtype_strings_for_violation(
                violation)
コード例 #5
0
    def test_us_pa_get_violation_type_subtype_strings_for_violation_electronic_monitoring(
            self) -> None:
        # Arrange
        violation = StateSupervisionViolation.new_with_defaults(
            state_code=_STATE_CODE,
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text='M16')
            ])

        # Act
        type_subtype_strings = us_pa_get_violation_type_subtype_strings_for_violation(
            violation)

        # Assert
        expected_type_subtype_strings = ['ELEC_MONITORING']
        self.assertEqual(expected_type_subtype_strings, type_subtype_strings)
コード例 #6
0
    def test_us_pa_get_violation_type_subtype_strings_for_violation_substance(
            self) -> None:
        # Arrange
        violation = StateSupervisionViolation.new_with_defaults(
            state_code=_STATE_CODE,
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text='H12')
            ])

        # Act
        type_subtype_strings = us_pa_get_violation_type_subtype_strings_for_violation(
            violation)

        # Assert
        expected_type_subtype_strings = ['SUBSTANCE_ABUSE']
        self.assertEqual(expected_type_subtype_strings, type_subtype_strings)
コード例 #7
0
    def test_us_pa_get_violation_type_subtype_strings_for_violation_unsupported_technical(
            self) -> None:
        # Arrange
        violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code='US_PA',
            violation_date=date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    # We expect all TECHNICAL violations to have definable raw text values
                    violation_type_raw_text=None),
            ])

        # Act
        with pytest.raises(ValueError):
            _ = us_pa_get_violation_type_subtype_strings_for_violation(
                violation)
コード例 #8
0
    def test_us_pa_get_violation_type_subtype_strings_for_violation_low_technical(
            self) -> None:
        # Arrange
        violation = StateSupervisionViolation.new_with_defaults(
            state_code=_STATE_CODE,
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text='L05')
            ],
        )

        # Act
        type_subtype_strings = us_pa_get_violation_type_subtype_strings_for_violation(
            violation)

        # Assert
        expected_type_subtype_strings = ['LOW_TECH']
        self.assertEqual(expected_type_subtype_strings, type_subtype_strings)
コード例 #9
0
    def test_us_pa_get_violation_type_subtype_strings_for_violation_high_technical(
            self) -> None:
        # Arrange
        violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code='US_PA',
            violation_date=date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text='H05'),
            ])

        # Act
        type_subtype_strings = us_pa_get_violation_type_subtype_strings_for_violation(
            violation)

        # Assert
        expected_type_subtype_strings = ['HIGH_TECH']
        self.assertEqual(expected_type_subtype_strings, type_subtype_strings)
コード例 #10
0
    def test_us_pa_get_violation_type_subtype_strings_for_violation_medium_technical(
        self, ) -> None:
        # Arrange
        violation = StateSupervisionViolation.new_with_defaults(
            supervision_violation_id=123455,
            state_code="US_PA",
            violation_date=date(2009, 1, 3),
            supervision_violation_types=[
                StateSupervisionViolationTypeEntry.new_with_defaults(
                    state_code=_STATE_CODE,
                    violation_type=StateSupervisionViolationType.TECHNICAL,
                    violation_type_raw_text="M05",
                ),
            ],
        )

        # Act
        type_subtype_strings = us_pa_get_violation_type_subtype_strings_for_violation(
            violation)

        # Assert
        expected_type_subtype_strings = ["MED_TECH"]
        self.assertEqual(expected_type_subtype_strings, type_subtype_strings)