<s> import braintree <EOL> from django . conf import settings <EOL> from django . test import TestCase <EOL> from django . utils . unittest import skipIf <EOL> from billing import get_gateway , CreditCard <EOL> from billing . signals import * <EOL> from billing . gateway import CardNotSupported , InvalidData <EOL> from billing . utils . credit_card import Visa <EOL> @ skipIf ( not settings . MERCHANT_SETTINGS . get ( "<STR_LIT>" , None ) , "<STR_LIT>" ) <EOL> class BraintreePaymentsGatewayTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . merchant = get_gateway ( "<STR_LIT>" ) <EOL> self . merchant . test_mode = True <EOL> self . credit_card = CreditCard ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" , <EOL> month = <NUM_LIT:10> , year = <NUM_LIT> , <EOL> number = "<STR_LIT>" , <EOL> verification_value = "<STR_LIT:100>" ) <EOL> def assertBraintreeResponseSuccess ( self , resp , msg = None ) : <EOL> if resp [ '<STR_LIT:status>' ] == "<STR_LIT>" : <EOL> standardMsg = resp [ '<STR_LIT>' ] . message <EOL> self . fail ( self . _formatMessage ( msg , standardMsg ) ) <EOL> else : <EOL> self . assertEquals ( resp [ '<STR_LIT:status>' ] , "<STR_LIT>" ) <EOL> def assertBraintreeResponseFailure ( self , resp , msg = None ) : <EOL> self . assertEquals ( resp [ '<STR_LIT:status>' ] , "<STR_LIT>" ) <EOL> def testCardSupported ( self ) : <EOL> self . credit_card . number = "<STR_LIT>" <EOL> self . assertRaises ( CardNotSupported , <EOL> lambda : self . merchant . purchase ( <NUM_LIT:1000> , self . credit_card ) ) <EOL> def testCardType ( self ) : <EOL> self . merchant . validate_card ( self . credit_card ) <EOL> self . assertEquals ( self . credit_card . card_type , Visa ) <EOL> def testPurchase ( self ) : <EOL> resp = self . merchant . purchase ( <NUM_LIT:5> , self . credit_card ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> def testFailedPurchase ( self ) : <EOL> resp = self . merchant . purchase ( <NUM_LIT> , self . credit_card ) <EOL> self . assertBraintreeResponseFailure ( resp ) <EOL> def testDeclinedPurchase ( self ) : <EOL> resp = self . merchant . purchase ( <NUM_LIT> , self . credit_card ) <EOL> self . assertBraintreeResponseFailure ( resp ) <EOL> def testPaymentSuccessfulSignal ( self ) : <EOL> received_signals = [ ] <EOL> def receive ( sender , ** kwargs ) : <EOL> received_signals . append ( kwargs . get ( "<STR_LIT>" ) ) <EOL> transaction_was_successful . connect ( receive ) <EOL> resp = self . merchant . purchase ( <NUM_LIT:1> , self . credit_card ) <EOL> self . assertEquals ( received_signals , [ transaction_was_successful ] ) <EOL> def testPaymentUnSuccessfulSignal ( self ) : <EOL> received_signals = [ ] <EOL> def receive ( sender , ** kwargs ) : <EOL> received_signals . append ( kwargs . get ( "<STR_LIT>" ) ) <EOL> transaction_was_unsuccessful . connect ( receive ) <EOL> resp = self . merchant . purchase ( <NUM_LIT> , self . credit_card ) <EOL> self . assertEquals ( received_signals , [ transaction_was_unsuccessful ] ) <EOL> def testCreditCardExpired ( self ) : <EOL> credit_card = CreditCard ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" , <EOL> month = <NUM_LIT:10> , year = <NUM_LIT> , <EOL> number = "<STR_LIT>" , <EOL> verification_value = "<STR_LIT:100>" ) <EOL> resp = self . merchant . purchase ( <NUM_LIT> , credit_card ) <EOL> self . assertNotEquals ( resp [ "<STR_LIT:status>" ] , "<STR_LIT>" ) <EOL> def testAuthorizeAndCapture ( self ) : <EOL> resp = self . merchant . authorize ( <NUM_LIT:100> , self . credit_card ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> resp = self . merchant . capture ( <NUM_LIT:50> , resp [ "<STR_LIT>" ] . transaction . id ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> def testAuthorizeAndVoid ( self ) : <EOL> resp = self . merchant . authorize ( <NUM_LIT> , self . credit_card ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> resp = self . merchant . void ( resp [ "<STR_LIT>" ] . transaction . id ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> def testStoreMissingCustomer ( self ) : <EOL> self . assertRaises ( InvalidData , <EOL> lambda : self . merchant . store ( self . credit_card , { } ) ) <EOL> def testStoreWithoutBillingAddress ( self ) : <EOL> options = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> } , <EOL> } <EOL> resp = self . merchant . store ( self . credit_card , options = options ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> self . assertEquals ( resp [ "<STR_LIT>" ] . customer . credit_cards [ <NUM_LIT:0> ] . expiration_date , <EOL> "<STR_LIT>" % ( self . credit_card . month , <EOL> self . credit_card . year ) ) <EOL> self . assertTrue ( getattr ( resp [ "<STR_LIT>" ] . customer . credit_cards [ <NUM_LIT:0> ] , "<STR_LIT>" ) ) <EOL> self . assertTrue ( getattr ( resp [ "<STR_LIT>" ] . customer . credit_cards [ <NUM_LIT:0> ] , "<STR_LIT>" ) ) <EOL> def testStoreWithBillingAddress ( self ) : <EOL> options = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> resp = self . merchant . store ( self . credit_card , options = options ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> self . assertTrue ( getattr ( resp [ "<STR_LIT>" ] . customer . credit_cards [ <NUM_LIT:0> ] , "<STR_LIT>" ) ) <EOL> billing_address = resp [ "<STR_LIT>" ] . customer . credit_cards [ <NUM_LIT:0> ] . billing_address <EOL> self . assertEquals ( billing_address . country_code_alpha2 , "<STR_LIT>" ) <EOL> self . assertEquals ( billing_address . postal_code , "<STR_LIT>" ) <EOL> self . assertEquals ( billing_address . street_address , "<STR_LIT>" ) <EOL> self . assertEquals ( billing_address . extended_address , "<STR_LIT>" ) <EOL> self . assertEquals ( billing_address . locality , "<STR_LIT>" ) <EOL> def testUnstore ( self ) : <EOL> options = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> } , <EOL> } <EOL> resp = self . merchant . store ( self . credit_card , options = options ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> resp = self . merchant . unstore ( resp [ "<STR_LIT>" ] . customer . credit_cards [ <NUM_LIT:0> ] . token ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> def testRecurring1 ( self ) : <EOL> options = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } , <EOL> } <EOL> resp = self . merchant . recurring ( <NUM_LIT:10> , self . credit_card , options = options ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> subscription = resp [ "<STR_LIT>" ] . subscription <EOL> self . assertEquals ( subscription . status , <EOL> braintree . Subscription . Status . Active ) <EOL> def testRecurring2 ( self ) : <EOL> options = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:15> <EOL> } , <EOL> } <EOL> resp = self . merchant . recurring ( <NUM_LIT:15> , self . credit_card , options = options ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> subscription = resp [ "<STR_LIT>" ] . subscription <EOL> self . assertEquals ( subscription . price , <NUM_LIT:15> ) <EOL> def testRecurring3 ( self ) : <EOL> options = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:email>" : "<STR_LIT>" , <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> } , <EOL> } <EOL> resp = self . merchant . recurring ( <NUM_LIT:20> , self . credit_card , options = options ) <EOL> self . assertBraintreeResponseSuccess ( resp ) <EOL> subscription = resp [ "<STR_LIT>" ] . subscription <EOL> self . assertEquals ( subscription . number_of_billing_cycles , <NUM_LIT:12> ) </s>
