예제 #1
0
    def test_form_is_invalid_when_credit_card_information_is_missing(
            self, sale_mock):
        '''
        Test that the form is invalid when no credit card information is entered
        by the user.
        '''
        # Mock errors returned by the Payment Gateway.
        error = ValidationError(
            attributes={
                'code':
                '91569',
                'attribute':
                'payment_method_nonce',
                'message': (
                    'payment_method_nonce does not contain a valid payment '
                    'instrument type.')
            })
        error2 = ValidationError(
            attributes={
                'code': '81714',
                'attribute': 'number',
                'message': 'Credit card number is required.'
            })
        error3 = ValidationError(
            attributes={
                'code':
                '81725',
                'attribute':
                'base',
                'message':
                ('Credit card must include number, payment_method_nonce, or '
                 'venmo_sdk_payment_method_code.')
            })
        error4 = ValidationError(attributes={
            'code': '81706',
            'attribute': 'cvv',
            'message': 'CVV is required.'
        })
        sale_mock.return_value.is_success = False
        sale_mock.return_value.errors.deep_errors = [
            error, error2, error3, error4
        ]

        # Instantiate Form.
        form = PaymentForm(
            amount=Decimal(1.00),  # Set Test Amount to 'Authorized'.
            data={'payment_method_nonce': 'fake-valid-nonce'})

        # Perform Form validation.
        result = form.is_valid()

        self.assertFalse(result)
예제 #2
0
    def test_form_is_invalid_when_payment_gateway_responds_with_error(
            self, sale_mock):
        '''
        Test that the Form is invalid when the Payment Gateway returns any type
        of error.
        '''
        # Mock error returned by the Payment Gateway.
        error = ValidationError(
            attributes={
                'code': '12345',
                'attribute': 'foo',
                'message': 'This is a generic test error.'
            })
        sale_mock.return_value.is_success = False
        sale_mock.return_value.errors.deep_errors = [error]

        # Instantiate Form.
        form = PaymentForm(
            amount=Decimal(1.00),  # Set Test Amount to 'Authorized'.
            data={'payment_method_nonce': 'fake-valid-nonce'})

        # Perform Form validation.
        result = form.is_valid()

        self.assertFalse(result)
예제 #3
0
    def test_form_is_invalid_when_postal_code_is_missing(self, sale_mock):
        '''
        Test that the Form is invalid when no postal code is entered by the
        user.
        '''
        # Mock error returned by the Payment Gateway.
        error = ValidationError(
            attributes={
                'code': '81801',
                'attribute': 'base',
                'message': 'Addresses must have at least one field filled in.'
            })
        sale_mock.return_value.is_success = False
        sale_mock.return_value.errors.deep_errors = [error]

        # Instantiate Form.
        form = PaymentForm(
            amount=Decimal(1.00),  # Set Test Amount to 'Authorized'.
            data={'payment_method_nonce': 'fake-valid-nonce'})

        # Perform Form validation.
        result = form.is_valid()

        self.assertFalse(result)
예제 #4
0
    def errors(self):
        """Returns a list of :class:`ValidationError <braintree.validation_error.ValidationError>` objects."""

        return [ValidationError(error) for error in self.data["errors"]]