def parse_bond_amount_type_and_status( provided_amount: str, provided_bond_type: Optional[BondType] = None, provided_status: Optional[BondStatus] = None, ) -> Tuple[Optional[int], Optional[BondType], BondStatus]: """Returns bond amount, bond type, and bond status, setting any missing values that can be inferred from the other fields. """ # Amount field can sometimes contain type and status info instead of being # a numeric value type_from_amount = None status_from_amount = None if provided_amount: type_from_amount = BOND_TYPE_MAP.get(provided_amount.upper(), None) status_from_amount = BOND_STATUS_MAP.get(provided_amount.upper(), None) # If provided_amount was a non-numeric value but was not included in # BOND_TYPE_MAP or BOND_STATUS_MAP, the below call will throw (ValueError). # This is intentional, to ensure all values that should be converted are # properly captured. amount = None if ( provided_amount is not None and type_from_amount is None and status_from_amount is None ): amount = parse_dollars(provided_amount) bond_type = provided_bond_type or type_from_amount status = provided_status or status_from_amount # Infer missing fields from known fields if bond_type is None and amount is not None: bond_type = BondType.CASH if status is None and bond_type in (BondType.DENIED, BondType.NOT_REQUIRED): status = BondStatus.SET # Fall back on default status if no other status was set if status is None: status = BondStatus.PRESENT_WITHOUT_INFO return amount, bond_type, status # type: ignore
def test_parseBadDollarAmount(self): with pytest.raises(ValueError): parse_dollars('ABC')
def test_parseDollarAmount(self): assert parse_dollars('$100.00') == 100 assert parse_dollars('$') == 0
def test_parseBadDollarAmount(self) -> None: with pytest.raises(ValueError): parse_dollars("ABC")
def test_parseDollarAmount(self) -> None: assert parse_dollars("$100.00") == 100 assert parse_dollars("$") == 0