Example #1
0
    def test_create_payment_profile(self, PaymentProfile, CreateRequest):
        payment_profile = Mock()
        PaymentProfile.return_value = payment_profile
        _request = Mock()
        _request.make_request.return_value = self.payment_profile_id
        CreateRequest.return_value = _request

        # Scenario: call is successful, no validationMode is passed
        return_value = create_payment_profile(self.customer_id, 'address',
                                              'credit_card')
        PaymentProfile.assert_called_once_with(billTo='address',
                                               card='credit_card')
        CreateRequest.assert_called_once_with(customerProfileId=self.customer_id,
                                              paymentProfile=payment_profile,
                                              validationMode=None)
        self.assertTrue(_request.make_request.called)
        self.assertEqual(return_value, self.payment_profile_id)

        # Scenario: call is successful, validationMode is passed
        create_payment_profile(self.customer_id, 'address', 'credit_card',
                               'liveMode')
        CreateRequest.assert_called_with(customerProfileId=self.customer_id,
                                         paymentProfile=payment_profile,
                                         validationMode='liveMode')

        # Scenario: call raises AuthorizeNetException
        _request.make_request.side_effect = AuthorizeNetException('')
        self.assertRaises(AuthorizeNetException, create_payment_profile,
                          self.customer_id, 'address', 'credit_card')
Example #2
0
    def test_create_payment_profile(self, PaymentProfile, CreateRequest):
        payment_profile = Mock()
        PaymentProfile.return_value = payment_profile
        _request = Mock()
        _request.make_request.return_value = self.payment_profile_id
        CreateRequest.return_value = _request

        # Scenario: call is successful, no validationMode is passed
        return_value = create_payment_profile(self.customer_id, 'address',
                                              'credit_card')
        PaymentProfile.assert_called_once_with(billTo='address',
                                               card='credit_card')
        CreateRequest.assert_called_once_with(
            customerProfileId=self.customer_id,
            paymentProfile=payment_profile,
            validationMode=None)
        self.assertTrue(_request.make_request.called)
        self.assertEqual(return_value, self.payment_profile_id)

        # Scenario: call is successful, validationMode is passed
        create_payment_profile(self.customer_id, 'address', 'credit_card',
                               'liveMode')
        CreateRequest.assert_called_with(customerProfileId=self.customer_id,
                                         paymentProfile=payment_profile,
                                         validationMode='liveMode')

        # Scenario: call raises AuthorizeNetException
        _request.make_request.side_effect = AuthorizeNetException('')
        self.assertRaises(AuthorizeNetException, create_payment_profile,
                          self.customer_id, 'address', 'credit_card')
Example #3
0
    def test_payment_profile(self):
        from r2.lib.authorize.api import PaymentProfile

        profile = PaymentProfile(billTo="Joe", paymentId="222", card="1111222233334444", validationMode="42")
        expected = (
            "<billTo>Joe</billTo>"
            + "<payment>"
            + "<creditCard>1111222233334444</creditCard>"
            + "</payment>"
            + "<customerPaymentProfileId>222</customerPaymentProfileId>"
            + "<validationMode>42</validationMode>"
        )
        self.assertEqual(profile.toXML(), expected)
Example #4
0
 def test_payment_profile(self):
     from r2.lib.authorize.api import PaymentProfile
     profile = PaymentProfile(
         billTo="Joe",
         paymentId="222",
         card="1111222233334444",
         validationMode="42",
     )
     expected = (
         "<billTo>Joe</billTo>" + "<payment>" +
         "<creditCard>1111222233334444</creditCard>" + "</payment>" +
         "<customerPaymentProfileId>222</customerPaymentProfileId>" +
         "<validationMode>42</validationMode>")
     self.assertEqual(profile.toXML(), expected)