<s> from tests . test_helper import * <EOL> import time <EOL> from braintree . test . nonces import Nonces <EOL> import braintree . test . venmo_sdk as venmo_sdk <EOL> class TestPayPalAccount ( unittest . TestCase ) : <EOL> def test_find_returns_paypal_account ( self ) : <EOL> customer_id = Customer . create ( ) . customer . id <EOL> result = PaymentMethod . create ( { <EOL> "<STR_LIT>" : customer_id , <EOL> "<STR_LIT>" : Nonces . PayPalFuturePayment <EOL> } ) <EOL> self . assertTrue ( result . is_success ) <EOL> found_account = PayPalAccount . find ( result . payment_method . token ) <EOL> self . assertNotEqual ( None , found_account ) <EOL> self . assertEquals ( found_account . __class__ , PayPalAccount ) <EOL> self . assertEquals ( found_account . token , result . payment_method . token ) <EOL> self . assertNotEqual ( None , found_account . image_url ) <EOL> self . assertNotEqual ( None , found_account . created_at ) <EOL> self . assertNotEqual ( None , found_account . updated_at ) <EOL> def test_find_raises_on_not_found_token ( self ) : <EOL> self . assertRaises ( NotFoundError , PayPalAccount . find , "<STR_LIT>" ) <EOL> def test_find_will_not_return_credit_card ( self ) : <EOL> credit_card = CreditCard . create ( { <EOL> "<STR_LIT>" : Customer . create ( ) . customer . id , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ) . credit_card <EOL> self . assertRaises ( NotFoundError , PayPalAccount . find , credit_card . token ) <EOL> def test_find_returns_subscriptions_associated_with_a_paypal_account ( self ) : <EOL> customer_id = Customer . create ( ) . customer . id <EOL> payment_method_token = "<STR_LIT>" + str ( int ( time . time ( ) ) ) <EOL> nonce = TestHelper . nonce_for_paypal_account ( { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : payment_method_token <EOL> } ) <EOL> result = PaymentMethod . create ( { <EOL> "<STR_LIT>" : nonce , <EOL> "<STR_LIT>" : customer_id <EOL> } ) <EOL> self . assertTrue ( result . is_success ) <EOL> token = result . payment_method . token <EOL> subscription1 = Subscription . create ( { <EOL> "<STR_LIT>" : token , <EOL> "<STR_LIT>" : TestHelper . trialless_plan [ "<STR_LIT:id>" ] <EOL> } ) . subscription <EOL> subscription2 = Subscription . create ( { <EOL> "<STR_LIT>" : token , <EOL> "<STR_LIT>" : TestHelper . trialless_plan [ "<STR_LIT:id>" ] <EOL> } ) . subscription <EOL> paypal_account = PayPalAccount . find ( result . payment_method . token ) <EOL> self . assertTrue ( subscription1 . id in [ s . id for s in paypal_account . subscriptions ] ) <EOL> self . assertTrue ( subscription2 . id in [ s . id for s in paypal_account . subscriptions ] ) <EOL> def test_find_retuns_billing_agreement_id_with_a_paypal_account ( self ) : <EOL> customer_id = Customer . create ( ) . customer . id <EOL> payment_method_token = "<STR_LIT>" + str ( int ( time . time ( ) ) ) <EOL> result = PaymentMethod . create ( { <EOL> "<STR_LIT>" : Nonces . PayPalBillingAgreement , <EOL> "<STR_LIT>" : customer_id <EOL> } ) <EOL> self . assertTrue ( result . is_success ) <EOL> paypal_account = PayPalAccount . find ( result . payment_method . token ) <EOL> self . assertNotEquals ( None , paypal_account . billing_agreement_id ) <EOL> def test_delete_deletes_paypal_account ( self ) : <EOL> result = PaymentMethod . create ( { <EOL> "<STR_LIT>" : Customer . create ( ) . customer . id , <EOL> "<STR_LIT>" : Nonces . PayPalFuturePayment <EOL> } ) <EOL> self . assertTrue ( result . is_success ) <EOL> paypal_account_token = result . payment_method . token <EOL> delete_result = PayPalAccount . delete ( paypal_account_token ) <EOL> self . assertTrue ( delete_result . is_success ) <EOL> self . assertRaises ( NotFoundError , PayPalAccount . find , paypal_account_token ) <EOL> def test_delete_raises_on_not_found ( self ) : <EOL> self . assertRaises ( NotFoundError , PayPalAccount . delete , "<STR_LIT>" ) <EOL> def test_delete_delete_wont_delete_credit_card ( self ) : <EOL> credit_card = CreditCard . create ( { <EOL> "<STR_LIT>" : Customer . create ( ) . customer . id , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ) . credit_card <EOL> self . assertRaises ( NotFoundError , PayPalAccount . delete , credit_card . token ) <EOL> def test_update_can_update_token_and_default ( self ) : <EOL> customer_id = Customer . create ( ) . customer . id <EOL> credit_card = CreditCard . create ( { <EOL> "<STR_LIT>" : customer_id , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ) . credit_card <EOL> result = PaymentMethod . create ( { <EOL> "<STR_LIT>" : customer_id , <EOL> "<STR_LIT>" : Nonces . PayPalFuturePayment <EOL> } ) <EOL> self . assertTrue ( result . is_success ) <EOL> old_token = result . payment_method . token <EOL> new_token = "<STR_LIT>" % int ( round ( time . time ( ) * <NUM_LIT:1000> ) ) <EOL> result = PayPalAccount . update ( old_token , { <EOL> "<STR_LIT>" : new_token , <EOL> "<STR_LIT>" : { "<STR_LIT>" : True } <EOL> } ) <EOL> self . assertTrue ( result . is_success ) <EOL> updated_account = PayPalAccount . find ( new_token ) <EOL> self . assertEquals ( updated_account . default , True ) <EOL> def test_update_returns_validation_errors ( self ) : <EOL> payment_method_token = "<STR_LIT>" % int ( round ( time . time ( ) * <NUM_LIT:1000> ) ) <EOL> customer_id = Customer . create ( ) . customer . id <EOL> credit_card = CreditCard . create ( { <EOL> "<STR_LIT>" : payment_method_token , <EOL> "<STR_LIT>" : customer_id , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } ) . credit_card <EOL> result = PaymentMethod . create ( { <EOL> "<STR_LIT>" : customer_id , <EOL> "<STR_LIT>" : Nonces . PayPalFuturePayment <EOL> } ) <EOL> self . assertTrue ( result . is_success ) <EOL> old_token = result . payment_method . token <EOL> result = PayPalAccount . update ( old_token , { <EOL> "<STR_LIT>" : payment_method_token , <EOL> } ) <EOL> self . assertFalse ( result . is_success ) <EOL> self . assertEquals ( <EOL> ErrorCodes . PayPalAccount . TokenIsInUse , <EOL> result . errors . for_object ( "<STR_LIT>" ) . on ( "<STR_LIT>" ) [ <NUM_LIT:0> ] . code <EOL> ) <EOL> result = PayPalAccount . update ( old_token , { <EOL> "<STR_LIT>" : payment_method_token , <EOL> } ) <EOL> self . assertFalse ( result . is_success ) <EOL> self . assertEquals ( <EOL> ErrorCodes . PayPalAccount . TokenIsInUse , <EOL> result . errors . for_object ( "<STR_LIT>" ) . on ( "<STR_LIT>" ) [ <NUM_LIT:0> ] . code <EOL> ) </s>
