def test_clean_charge():
    # Amount should be a positive number
    payment = Mock()
    amount = Decimal("0.00")
    with pytest.raises(PaymentError):
        clean_charge(payment, amount)

    # Payment cannot be charged
    payment = Mock(can_charge=Mock(return_value=False))
    amount = Decimal("1.00")
    with pytest.raises(PaymentError):
        clean_charge(payment, amount)

    # Amount is larger than payment's total
    payment = Mock(
        can_capture=Mock(return_value=True),
        total=Decimal("1.00"),
        captured_amount=Decimal("0.00"),
    )
    amount = Decimal("2.00")
    with pytest.raises(PaymentError):
        clean_charge(payment, amount)

    amount = Decimal("2.00")
    payment = Mock(
        can_charge=Mock(return_value=True),
        total=amount,
        captured_amount=Decimal("0.00"),
    )
    clean_charge(payment, amount)
Example #2
0
def test_clean_charge():
    # Amount should be a positive number
    payment = Mock()
    amount = Decimal('0.00')
    with pytest.raises(PaymentError):
        clean_charge(payment, amount)

    # Payment cannot be charged
    payment = Mock(can_charge=Mock(return_value=False))
    amount = Decimal('1.00')
    with pytest.raises(PaymentError):
        clean_charge(payment, amount)

    # Amount is larger than payment's total
    payment = Mock(
        can_capture=Mock(return_value=True),
        total=Decimal('1.00'),
        captured_amount=Decimal('0.00'))
    amount = Decimal('2.00')
    with pytest.raises(PaymentError):
        clean_charge(payment, amount)

    amount = Decimal('2.00')
    payment = Mock(
        can_charge=Mock(return_value=True),
        total=amount,
        captured_amount=Decimal('0.00'))
    clean_charge(payment, amount)