def test_associate_valid_card(self): billing.associate(self.db, "credit card", "alice", None, self.card_href) user = authentication.User.from_username("alice") customer = balanced.Customer.fetch(user.participant.balanced_customer_href) cards = customer.cards.all() assert len(cards) == 1 assert cards[0].href == self.card_href
def test_associate_invalid_card(self): #, find): billing.associate( self.db , u"credit card" , 'david' , self.david_href , '/cards/CC123123123123', # invalid href ) david = Participant.from_username('david') assert david.last_bill_result == '404 Client Error: NOT FOUND'
def test_associate_valid_card(self, gba): gba.return_value.uri = self.balanced_account_uri # first time through, payment processor account is None billing.associate(u"credit card", 'alice', None, self.card_uri) assert gba.call_count == 1 assert gba.return_value.add_card.call_count == 1 assert gba.return_value.add_bank_account.call_count == 0
def test_associate_invalid_card(self): # , find): billing.associate( self.db, "credit card", "alice", self.balanced_customer_href, "/cards/CC123123123123" # invalid href ) user = authentication.User.from_username("alice") # participant in db should be updated to reflect the error message of # last update assert user.participant.last_bill_result == "404 Client Error: NOT FOUND"
def test_associate_bank_account_invalid(self, find): ex = balanced.exc.HTTPError('errrrrror') find.return_value.add_bank_account.side_effect = ex billing.associate(u"bank account", 'alice', self.balanced_account_uri, self.balanced_destination_uri) user = authentication.User.from_id('alice') # participant in db should be updated assert user.last_ach_result == 'errrrrror'
def test_associate_bank_account_invalid(self, find): ex = balanced.exc.HTTPError("errrrrror") find.return_value.add_bank_account.side_effect = ex find.return_value.uri = self.balanced_account_uri billing.associate("bank account", "alice", self.balanced_account_uri, self.balanced_destination_uri) user = authentication.User.from_username("alice") # participant in db should be updated assert user.last_ach_result == "errrrrror"
def test_associate_valid_card(gba): with foo_user(): gba.return_value.uri = balanced_account_uri # first time through, payment processor account is None billing.associate(u"credit card", 'foo', None, card_uri) assert gba.call_count == 1 assert gba.return_value.add_card.call_count == 1 assert gba.return_value.add_bank_account.call_count == 0
def test_associate_valid_card(self): billing.associate(self.db, u"credit card", 'alice', None, self.card_href) user = authentication.User.from_username('alice') customer = balanced.Customer.fetch( user.participant.balanced_customer_href) cards = customer.cards.all() assert len(cards) == 1 assert cards[0].href == self.card_href
def test_associate_valid_card(self, gba): gba.return_value.uri = self.balanced_account_uri # first time through, payment processor account is None billing.associate(u"credit card", self.participant_id, None, self.card_uri) self.assertEqual(gba.call_count, 1) self.assertEqual(gba.return_value.add_card.call_count, 1) self.assertEqual(gba.return_value.add_bank_account.call_count, 0)
def test_associate_bank_account_invalid(self, find): balanced_destination_uri = '/v1/bank_accounts/X' ex = balanced.exc.HTTPError('errrrrror') find.return_value.add_bank_account.side_effect = ex billing.associate(u"bank account", self.participant_id, self.balanced_account_uri, balanced_destination_uri) user = authentication.User.from_id(self.participant_id) # participant in db should be updated self.assertEqual(user.session['last_ach_result'], 'errrrrror')
def test_associate_bank_account_invalid(self): billing.associate( self.db , u"bank account" , 'david' , self.david_href , '/bank_accounts/BA123123123123123123' # invalid href ) david = Participant.from_username('david') assert david.last_ach_result == '404 Client Error: NOT FOUND'
def test_credit_card_page_loads_when_there_is_a_card(self): self.db.run( "UPDATE participants SET balanced_customer_href=%s WHERE username='******'", (self.balanced_customer_href, )) billing.associate(self.db, 'credit card', 'alice', self.balanced_customer_href, self.card_href) expected = 'Your credit card is <em id="status">working' actual = self.client.GET('/credit-card.html', auth_as='alice').body.decode('utf8') assert expected in actual
def test_associate_bank_account_invalid(self, find): ex = balanced.exc.HTTPError('errrrrror') find.return_value.add_bank_account.side_effect = ex find.return_value.uri = self.balanced_account_uri billing.associate(u"bank account", 'alice', self.balanced_account_uri, self.balanced_destination_uri) # participant in db should be updated alice = Participant.from_username('alice') assert alice.last_ach_result == 'errrrrror'
def test_associate_bank_account_invalid(self): billing.associate( self.db , u"bank account" , 'alice' , self.balanced_customer_href , '/bank_accounts/BA123123123123123123' # invalid href ) # participant in db should be updated alice = Participant.from_username('alice') assert alice.last_ach_result == '404 Client Error: NOT FOUND'
def test_associate_invalid_card(self): #, find): billing.associate( self.db, u"credit card", 'alice', self.balanced_customer_href, '/cards/CC123123123123', # invalid href ) user = authentication.User.from_username('alice') # participant in db should be updated to reflect the error message of # last update assert user.participant.last_bill_result == '404 Client Error: NOT FOUND'
def test_associate_valid_card(self, gba): gba.return_value.uri = self.balanced_account_uri # first time through, payment processor account is None billing.associate( u"credit card" , self.participant_id , None , self.card_uri ) self.assertEqual(gba.call_count, 1) self.assertEqual(gba.return_value.add_card.call_count, 1) self.assertEqual(gba.return_value.add_bank_account.call_count, 0)
def test_associate_bank_account_invalid(self): billing.associate( self.db, u"bank account", 'alice', self.balanced_customer_href, '/bank_accounts/BA123123123123123123' # invalid href ) # participant in db should be updated alice = Participant.from_username('alice') assert alice.last_ach_result == '404 Client Error: NOT FOUND'
def test_associate_invalid_card(self, ba): error_message = 'Something terrible' not_found = balanced.exc.HTTPError(error_message) ba.find.return_value.save.side_effect = not_found # second time through, payment processor account is balanced # account_uri billing.associate(self.participant_id, self.balanced_account_uri, self.card_uri) user = authentication.User.from_id(self.participant_id) # participant in db should be updated to reflect the error message of # last update self.assertEqual(user.session['last_bill_result'], error_message) self.assertTrue(ba.find.call_count)
def test_credit_card_page_loads_when_there_is_a_card(self): self.db.run( "UPDATE participants SET balanced_customer_href=%s WHERE username='******'" , (self.balanced_customer_href,) ) billing.associate( self.db , 'credit card' , 'alice' , self.balanced_customer_href , self.card_href ) expected = 'Your credit card is <em id="status">working' actual = self.client.GET('/credit-card.html', auth_as='alice').body.decode('utf8') assert expected in actual
def test_associate_invalid_card(self, find): error_message = 'Something terrible' not_found = balanced.exc.HTTPError(error_message) find.return_value.add_card.side_effect = not_found # second time through, payment processor account is balanced # account_uri billing.associate(u"credit card", 'alice', self.balanced_account_uri, self.card_uri) user = authentication.User.from_id('alice') # participant in db should be updated to reflect the error message of # last update assert user.last_bill_result == error_message assert find.call_count
def test_associate_bank_account_invalid(self, find): ex = balanced.exc.HTTPError('errrrrror') find.return_value.add_bank_account.side_effect = ex find.return_value.uri = self.balanced_account_uri billing.associate( u"bank account" , 'alice' , self.balanced_account_uri , self.balanced_destination_uri ) # participant in db should be updated alice = Participant.from_username('alice') assert alice.last_ach_result == 'errrrrror'
def test_associate_bank_account_invalid(self, find): balanced_destination_uri = '/v1/bank_accounts/X' ex = balanced.exc.HTTPError('errrrrror') find.return_value.add_bank_account.side_effect = ex billing.associate( u"bank account" , self.participant_id , self.balanced_account_uri , balanced_destination_uri ) user = authentication.User.from_id(self.participant_id) # participant in db should be updated self.assertEqual(user.session['last_ach_result'], 'errrrrror')
def test_associate_bank_account_valid(self, find): billing.associate(u"bank account", 'alice', self.balanced_account_uri, self.balanced_destination_uri) args, _ = find.call_args assert args == (self.balanced_account_uri,) args, _ = find.return_value.add_bank_account.call_args assert args == (self.balanced_destination_uri,) user = authentication.User.from_id('alice') # participant in db should be updated assert user.last_ach_result == ''
def test_associate_bank_account_valid(self): billing.associate(self.db, "bank account", "alice", self.balanced_customer_href, self.bank_account_href) # args, _ = find.call_args customer = balanced.Customer.fetch(self.balanced_customer_href) bank_accounts = customer.bank_accounts.all() assert len(bank_accounts) == 1 assert bank_accounts[0].href == self.bank_account_href user = authentication.User.from_username("alice") # participant in db should be updated assert user.participant.last_ach_result == ""
def test_associate_bank_account_invalid(find): with foo_user(): balanced_destination_uri = '/v1/bank_accounts/X' ex = balanced.exc.HTTPError('errrrrror') find.return_value.add_bank_account.side_effect = ex billing.associate( u"bank account" , 'foo' , balanced_account_uri , balanced_destination_uri ) user = authentication.User.from_id('foo') # participant in db should be updated assert user.session['last_ach_result'] == 'errrrrror'
def test_associate_bank_account_valid(self, find): billing.associate(u"bank account", 'alice', self.balanced_account_uri, self.balanced_destination_uri) args, _ = find.call_args assert args == (self.balanced_account_uri, ) args, _ = find.return_value.add_bank_account.call_args assert args == (self.balanced_destination_uri, ) user = authentication.User.from_id('alice') # participant in db should be updated assert user.last_ach_result == ''
def test_associate_valid(self, ba): not_found = balanced.exc.NoResultFound() ba.query.filter.return_value.one.side_effect = not_found ba.return_value.save.return_value.uri = self.balanced_account_uri # first time through, payment processor account is None billing.associate(self.participant_id, None, self.card_uri) expected_email_address = '{}@gittip.com'.format(self.participant_id) _, kwargs = balanced.Account.call_args self.assertTrue(kwargs['email_address'], expected_email_address) user = authentication.User.from_id(self.participant_id) # participant in db should be updated self.assertEqual(user.session['balanced_account_uri'], self.balanced_account_uri)
def test_associate_bank_account_valid(self, find): balanced_destination_uri = '/v1/bank_accounts/X' billing.associate(u"bank account", self.participant_id, self.balanced_account_uri, balanced_destination_uri) args, _ = find.call_args self.assertEqual(args, (self.balanced_account_uri, )) args, _ = find.return_value.add_bank_account.call_args self.assertEqual(args, (balanced_destination_uri, )) user = authentication.User.from_id(self.participant_id) # participant in db should be updated self.assertEqual(user.session['last_ach_result'], '')
def test_associate_bank_account_valid(self): billing.associate(self.db, u"bank account", 'alice', self.balanced_customer_href, self.bank_account_href) #args, _ = find.call_args customer = balanced.Customer.fetch(self.balanced_customer_href) bank_accounts = customer.bank_accounts.all() assert len(bank_accounts) == 1 assert bank_accounts[0].href == self.bank_account_href user = authentication.User.from_username('alice') # participant in db should be updated assert user.participant.last_ach_result == ''
def test_associate_bank_account_valid(self, find): balanced_destination_uri = '/v1/bank_accounts/X' billing.associate( u"bank account" , self.participant_id , self.balanced_account_uri , balanced_destination_uri ) args, _ = find.call_args self.assertEqual(args, (self.balanced_account_uri,)) args, _ = find.return_value.add_bank_account.call_args self.assertEqual(args, (balanced_destination_uri,)) user = authentication.User.from_id(self.participant_id) # participant in db should be updated self.assertEqual(user.session['last_ach_result'], '')
def test_associate_bank_account_valid(find): with foo_user(): balanced_destination_uri = '/v1/bank_accounts/X' billing.associate( u"bank account" , 'foo' , balanced_account_uri , balanced_destination_uri ) args, _ = find.call_args assert args == (balanced_account_uri,) args, _ = find.return_value.add_bank_account.call_args assert args == (balanced_destination_uri,) user = authentication.User.from_id('foo') # participant in db should be updated assert user.session['last_ach_result'] == ''
def test_associate_valid_card(self): self.david.set_tip_to(self.homer, 10) card = balanced.Card( number='4242424242424242', expiration_year=2020, expiration_month=12 ).save() billing.associate( self.db , 'credit card' , 'david' , self.david_href , unicode(card.href) ) customer = balanced.Customer.fetch(self.david_href) cards = customer.cards.all() assert len(cards) == 1 assert cards[0].href == card.href homer = Participant.from_id(self.homer.id) assert homer.receiving == 10
def test_associate_bank_account_valid(self): bank_account = balanced.BankAccount( name='Alice G. Krebs' , routing_number='321174851' , account_number='9900000001' , account_type='checking' ).save() billing.associate( self.db , u"bank account" , 'david' , self.david_href , unicode(bank_account.href) ) #args, _ = find.call_args customer = balanced.Customer.fetch(self.david_href) bank_accounts = customer.bank_accounts.all() assert len(bank_accounts) == 1 assert bank_accounts[0].href == unicode(bank_account.href) david = Participant.from_username('david') assert david.last_ach_result == ''