Esempio n. 1
0
    def testParseBond(self):
        # Arrange
        ingest_bond = ingest_info_pb2.Bond(
            bond_id="BOND_ID",
            bond_type="CASH",
            amount="$125.00",
            status="ACTIVE",
            bond_agent="AGENT",
        )

        # Act
        result = bond.convert(ingest_bond, _EMPTY_METADATA)

        # Assert
        expected_result = entities.Bond(
            external_id="BOND_ID",
            bond_type=BondType.CASH,
            bond_type_raw_text="CASH",
            amount_dollars=125,
            status=BondStatus.SET,
            status_raw_text="ACTIVE",
            bond_agent="AGENT",
        )

        self.assertEqual(result, expected_result)
Esempio n. 2
0
    def testParseBond_AmountIsBondDenied_UsesAmountAsType(self):
        # Arrange
        ingest_bond = ingest_info_pb2.Bond(amount="Bond Denied")

        # Act
        result = bond.convert(ingest_bond, _EMPTY_METADATA)

        # Assert
        expected_result = entities.Bond.new_with_defaults(
            bond_type=BondType.DENIED, status=BondStatus.SET)
        self.assertEqual(result, expected_result)
Esempio n. 3
0
    def testParseBond_OnlyAmount_InfersCash(self):
        # Arrange
        ingest_bond = ingest_info_pb2.Bond(amount='1,500')

        # Act
        result = bond.convert(ingest_bond, _EMPTY_METADATA)

        # Assert
        expected_result = entities.Bond.new_with_defaults(
            bond_type=BondType.CASH,
            status=BondStatus.PRESENT_WITHOUT_INFO,
            amount_dollars=1500)
        self.assertEqual(result, expected_result)
Esempio n. 4
0
    def _convert_charge(self, ingest_charge):
        """Converts an ingest_info proto Charge to a persistence entity."""
        charge_builder = entities.Charge.builder()

        charge.copy_fields_to_builder(charge_builder, ingest_charge,
                                      self.metadata)

        charge_builder.bond = \
            fn(lambda i: bond.convert(self.bonds[i], self.metadata),
               'bond_id',
               ingest_charge)
        charge_builder.sentence = \
            fn(lambda i: self._convert_sentence(self.sentences[i]),
               'sentence_id', ingest_charge)

        return charge_builder.build()
Esempio n. 5
0
    def testParseBond_MapStatusToType(self):
        # Arrange
        ingest_bond = ingest_info_pb2.Bond(bond_type="bond revoked")
        overrides_builder = EnumOverrides.Builder()
        overrides_builder.add("BOND REVOKED", BondStatus.REVOKED, BondType)
        overrides = overrides_builder.build()

        # Act
        result = bond.convert(
            ingest_bond, attr.evolve(_EMPTY_METADATA,
                                     enum_overrides=overrides))

        # Assert
        expected_result = entities.Bond.new_with_defaults(
            bond_type_raw_text="BOND REVOKED", status=BondStatus.REVOKED)
        self.assertEqual(result, expected_result)