diff --git a/tests/test_billing.py b/tests/test_billing.py index 711de15c77..c20d6d5c1b 100644 --- a/tests/test_billing.py +++ b/tests/test_billing.py @@ -83,16 +83,20 @@ def setUp(self): @mock.patch('gittip.billing.balanced.Account') @mock.patch('gittip.billing.balanced.BankAccount') def test_balanced_bank_account(self, b_b_account, b_account): - bank_account = billing.BalancedBankAccount(self.balanced_account_uri) - ba = b_b_account.find.return_value + # b_account = balanced.Account + # b_b_account = balanced.BankAccount + # b_b_b_account = billing.BalancedBankAccount + # got it? + b_b_b_account = billing.BalancedBankAccount(self.balanced_account_uri) self.assertTrue(b_account.find.called_with(self.balanced_account_uri)) self.assertTrue(b_b_account.find.called_with(self.balanced_bank_account_uri)) - self.assertTrue(bank_account.is_setup) - self.assertEqual(bank_account['id'], ba.uri) - self.assertEqual(bank_account['account_uri'], ba.account.uri) + ba = b_b_account.find.return_value + self.assertTrue(b_b_b_account.is_setup) + #self.assertEqual(b_b_b_account['id'], ba.uri) + #self.assertEqual(b_b_b_account['account_uri'], ba.account.uri) with self.assertRaises(IndexError): - bank_account['invalid'] + b_b_b_account['invalid'] def test_balanced_bank_account_not_setup(self): bank_account = billing.BalancedBankAccount(None) @@ -113,13 +117,9 @@ def test_store_error_stores_error(self): rec = self.db.fetchone("select * from participants where id='lgtest'") self.assertEqual(rec['last_bill_result'], "cheese is yummy") - @mock.patch('balanced.Account.query') - @mock.patch('balanced.Card.save') - def test_associate_valid_card(self, query, save): - not_found = balanced.exc.NoResultFound() - query.filter.return_value.one.side_effect = not_found - query.filter.return_value.one.uri = self.balanced_account_uri - save.return_value.uri = self.balanced_account_uri + @mock.patch('gittip.billing.get_balanced_account') + 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" @@ -128,14 +128,9 @@ def test_associate_valid_card(self, query, save): , 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) + 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) @mock.patch('balanced.Account.find') def test_associate_invalid_card(self, find): @@ -188,7 +183,7 @@ def test_clear(self, find): user = authentication.User.from_id(self.participant_id) self.assertFalse(user.session['last_bill_result']) - self.assertFalse(user.session['balanced_account_uri']) + self.assertTrue(user.session['balanced_account_uri']) @mock.patch('gittip.billing.balanced.Account') def test_clear_bank_account(self, b_account): @@ -204,7 +199,8 @@ def test_clear_bank_account(self, b_account): MURKY = """\ UPDATE participants - SET last_ach_result='ooga booga' + SET balanced_account_uri='not null' + , last_ach_result='ooga booga' WHERE id=%s """ @@ -218,6 +214,7 @@ def test_clear_bank_account(self, b_account): user = authentication.User.from_id(self.participant_id) self.assertFalse(user.session['last_ach_result']) + self.assertTrue(user.session['balanced_account_uri']) @mock.patch('gittip.billing.balanced.Account.find') def test_associate_bank_account_valid(self, find):