Ejemplo n.º 1
0
def _charges_pointing_to_total_bond(bond_amount, bond_type, bond_status,
                                    charges):
    """Infers a bond from the total_bond field and creates a copy of all charges
    updated to point to the inferred bond. If no charges exist, then also infer
    a charge."""
    inferred_bond = entities.Bond(
        external_id=None,
        amount_dollars=bond_amount,
        bond_type=bond_type,
        bond_type_raw_text=None,
        status=bond_status,
        status_raw_text=None,
        bond_agent=None,
    )

    if not charges:
        inferred_charge = entities.Charge.new_with_defaults(
            bond=inferred_bond, status=ChargeStatus.PRESENT_WITHOUT_INFO)
        return [inferred_charge]

    if any(c.bond is not None for c in charges):
        raise ValueError("Can't use total_bond and create a bond on a charge")

    charges_pointing_to_inferred_bond = copy.deepcopy(charges)
    for c in charges_pointing_to_inferred_bond:
        c.bond = inferred_bond

    return charges_pointing_to_inferred_bond
Ejemplo n.º 2
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)