def testParseStateBond(self) -> None: # Arrange ingest_bond = ingest_info_pb2.StateBond( status="ACTIVE", bond_type="CASH", state_bond_id="BOND_ID", date_paid="1/2/2111", state_code="us_nd", county_code="BISMARCK", bond_agent="AGENT", amount="$125.00", ) # Act result = state_bond.convert(ingest_bond, _EMPTY_METADATA) # Assert expected_result = entities.StateBond( status=BondStatus.SET, status_raw_text="ACTIVE", bond_type=BondType.CASH, bond_type_raw_text="CASH", external_id="BOND_ID", date_paid=date(year=2111, month=1, day=2), state_code="US_ND", county_code="BISMARCK", bond_agent="AGENT", amount_dollars=125, ) self.assertEqual(result, expected_result)
def testParseStateBond(self): # Arrange ingest_bond = ingest_info_pb2.StateBond( status='ACTIVE', bond_type='CASH', state_bond_id='BOND_ID', date_paid='1/2/2111', state_code='us_nd', county_code='BISMARCK', bond_agent='AGENT', amount='$125.00', ) # Act result = state_bond.convert(ingest_bond, _EMPTY_METADATA) # Assert expected_result = entities.StateBond( status=BondStatus.SET, status_raw_text='ACTIVE', bond_type=BondType.CASH, bond_type_raw_text='CASH', external_id='BOND_ID', date_paid=date(year=2111, month=1, day=2), state_code='US_ND', county_code='BISMARCK', bond_agent='AGENT', amount_dollars=125, ) self.assertEqual(result, expected_result)
def testParseBond_AmountIsBondDenied_UsesAmountAsType(self): # Arrange ingest_bond = ingest_info_pb2.StateBond(amount='Bond Denied') # Act result = state_bond.convert(ingest_bond, _EMPTY_METADATA) # Assert expected_result = entities.StateBond.new_with_defaults( bond_type=BondType.DENIED, status=BondStatus.SET) self.assertEqual(result, expected_result)
def testParseBond_OnlyAmount_InfersCash(self): # Arrange ingest_bond = ingest_info_pb2.StateBond(amount='1,500') # Act result = state_bond.convert(ingest_bond, _EMPTY_METADATA) # Assert expected_result = entities.StateBond.new_with_defaults( bond_type=BondType.CASH, status=BondStatus.PRESENT_WITHOUT_INFO, amount_dollars=1500) self.assertEqual(result, expected_result)
def testParseBond_AmountIsNoBond_UsesAmountAsType(self) -> None: # Arrange ingest_bond = ingest_info_pb2.StateBond(state_code="us_xx", amount="No Bond") # Act result = state_bond.convert(ingest_bond, _EMPTY_METADATA) # Assert expected_result = entities.StateBond.new_with_defaults( state_code="US_XX", bond_type=BondType.DENIED, status=BondStatus.SET) self.assertEqual(result, expected_result)
def testParseBond_MapStatusToType(self): # Arrange ingest_bond = ingest_info_pb2.StateBond(bond_type='bond revoked') overrides_builder = EnumOverrides.Builder() overrides_builder.add('BOND REVOKED', BondStatus.REVOKED, BondType) overrides = overrides_builder.build() # Act result = state_bond.convert( ingest_bond, attr.evolve(_EMPTY_METADATA, enum_overrides=overrides)) # Assert expected_result = entities.StateBond.new_with_defaults( bond_type_raw_text='BOND REVOKED', status=BondStatus.REVOKED) self.assertEqual(result, expected_result)
def _convert_charge(self, ingest_charge: StateCharge) \ -> entities.StateCharge: """Converts an ingest_info proto StateCharge to a persistence entity.""" charge_builder = entities.StateCharge.builder() state_charge.copy_fields_to_builder(charge_builder, ingest_charge, self.metadata) charge_builder.bond = \ fn(lambda i: state_bond.convert(self.bonds[i], self.metadata), 'state_bond_id', ingest_charge) charge_builder.court_case = \ fn(lambda i: self._convert_court_case(self.court_cases[i]), 'state_court_case_id', ingest_charge) return charge_builder.build()
def testParseBond_MapStatusToType(self) -> None: # Arrange ingest_bond = ingest_info_pb2.StateBond(state_code="us_xx", bond_type="bond revoked") overrides_builder = EnumOverrides.Builder() overrides_builder.add("BOND REVOKED", BondStatus.REVOKED, BondType) overrides = overrides_builder.build() # Act result = state_bond.convert( ingest_bond, attr.evolve(_EMPTY_METADATA, enum_overrides=overrides)) # Assert expected_result = entities.StateBond.new_with_defaults( state_code="US_XX", bond_type_raw_text="BOND REVOKED", status=BondStatus.REVOKED, ) self.assertEqual(result, expected_result)