diff --git a/gratipay/testing/__init__.py b/gratipay/testing/__init__.py index 29713d2385..e0b79ffa36 100644 --- a/gratipay/testing/__init__.py +++ b/gratipay/testing/__init__.py @@ -196,8 +196,7 @@ def make_exchange(self, route, amount, fee, participant, status='succeeded', err network = route route = ExchangeRoute.from_network(participant, network) if not route: - from .balanced import BalancedHarness - route = ExchangeRoute.insert(participant, network, BalancedHarness.card_href) + route = ExchangeRoute.insert(participant, network, 'dummy-address') assert route e_id = record_exchange(self.db, route, amount, fee, participant, 'pre') record_exchange_result(self.db, e_id, status, error, participant) diff --git a/gratipay/testing/balanced.py b/gratipay/testing/balanced.py index dfbb1dd8ca..0d905a4840 100644 --- a/gratipay/testing/balanced.py +++ b/gratipay/testing/balanced.py @@ -24,6 +24,49 @@ def setUp(self): balanced_customer_href=self.homer_href) self.homer_route = ExchangeRoute.insert(self.homer, 'balanced-ba', self.bank_account_href) + @classmethod + def setUpClass(cls): + with use_cassette('BalancedHarness'): + balanced.configure(balanced.APIKey().save().secret) + mp = balanced.Marketplace.my_marketplace + if not mp: + mp = balanced.Marketplace().save() + cls.balanced_marketplace = mp + + cls.david_href = cls.make_balanced_customer() + + cls.janet_href = cls.make_balanced_customer() + cls.card = balanced.Card( + number='4111111111111111', + expiration_month=10, + expiration_year=2020, + address={ + 'line1': "123 Main Street", + 'state': 'Confusion', + 'postal_code': '90210', + }, + # gratipay stores some of the address data in the meta fields, + # continue using them to support backwards compatibility + meta={ + 'address_2': 'Box 2', + 'city_town': '', + 'region': 'Confusion', + } + ).save() + cls.card.associate_to_customer(cls.janet_href) + cls.card_href = unicode(cls.card.href) + + cls.homer_href = cls.make_balanced_customer() + cls.bank_account = balanced.BankAccount( + name='Homer Jay', + account_number='112233a', + routing_number='121042882', + ).save() + cls.bank_account.associate_to_customer(cls.homer_href) + cls.bank_account_href = unicode(cls.bank_account.href) + + super(BalancedHarness, cls).setUpClass() + @classmethod def tearDownClass(cls): has_exchange_id = balanced.Transaction.f.meta.contains('exchange_id') @@ -35,42 +78,4 @@ def tearDownClass(cls): super(BalancedHarness, cls).tearDownClass() -with use_cassette('BalancedHarness'): - cls = BalancedHarness - balanced.configure(balanced.APIKey().save().secret) - mp = balanced.Marketplace.my_marketplace - if not mp: - mp = balanced.Marketplace().save() - cls.balanced_marketplace = mp - - cls.david_href = cls.make_balanced_customer() - - cls.janet_href = cls.make_balanced_customer() - cls.card = balanced.Card( - number='4111111111111111', - expiration_month=10, - expiration_year=2020, - address={ - 'line1': "123 Main Street", - 'state': 'Confusion', - 'postal_code': '90210', - }, - # gratipay stores some of the address data in the meta fields, - # continue using them to support backwards compatibility - meta={ - 'address_2': 'Box 2', - 'city_town': '', - 'region': 'Confusion', - } - ).save() - cls.card.associate_to_customer(cls.janet_href) - cls.card_href = unicode(cls.card.href) - cls.homer_href = cls.make_balanced_customer() - cls.bank_account = balanced.BankAccount( - name='Homer Jay', - account_number='112233a', - routing_number='121042882', - ).save() - cls.bank_account.associate_to_customer(cls.homer_href) - cls.bank_account_href = unicode(cls.bank_account.href)