Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Fix tests on master #3581

Merged
merged 13 commits into from
Jul 2, 2015
3 changes: 3 additions & 0 deletions gratipay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,9 @@ def render_notifications(self, state):
def get_bank_account_error(self):
return getattr(ExchangeRoute.from_network(self, 'balanced-ba'), 'error', None)

def get_paypal_error(self):
return getattr(ExchangeRoute.from_network(self, 'paypal'), 'error', None)

def get_credit_card_error(self):
if self.braintree_customer_id:
return getattr(ExchangeRoute.from_network(self, 'braintree-cc'), 'error', None)
Expand Down
18 changes: 4 additions & 14 deletions gratipay/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,6 @@ def show_table(self, table):
print("{0:{width}}".format(unicode(v), width=w), end=' | ')
print()


@classmethod
def make_balanced_customer(cls):
import balanced
seq = next(cls.seq)
return unicode(balanced.Customer(meta=dict(seq=seq)).save().href)


def make_team(self, *a, **kw):

_kw = defaultdict(str)
Expand All @@ -171,7 +163,7 @@ def make_team(self, *a, **kw):
_kw['is_approved'] = False

if Participant.from_username(_kw['owner']) is None:
self.make_participant(_kw['owner'], claimed_time='now', last_ach_result='')
self.make_participant(_kw['owner'], claimed_time='now', last_paypal_result='')

team = self.db.one("""
INSERT INTO teams
Expand Down Expand Up @@ -204,16 +196,14 @@ def make_participant(self, username, **kw):

# Insert exchange routes
if 'last_bill_result' in kw:
ExchangeRoute.insert(participant, 'balanced-cc', '/cards/foo', kw.pop('last_bill_result'))
if 'last_ach_result' in kw:
ExchangeRoute.insert(participant, 'balanced-ba', '/bank_accounts/bar', kw.pop('last_ach_result'))
ExchangeRoute.insert(participant, 'braintree-cc', '/cards/foo', kw.pop('last_bill_result'))
if 'last_paypal_result' in kw:
ExchangeRoute.insert(participant, 'paypal', '[email protected]', kw.pop('last_paypal_result'))

# Update participant
if kw:
if kw.get('claimed_time') == 'now':
kw['claimed_time'] = utcnow()
if kw.get('balanced_customer_href') == 'new':
kw['balanced_customer_href'] = self.make_balanced_customer()
cols, vals = zip(*kw.items())
cols = ', '.join(cols)
placeholders = ', '.join(['%s']*len(vals))
Expand Down
68 changes: 5 additions & 63 deletions gratipay/testing/billing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import itertools

import balanced
import braintree
from braintree.test.nonces import Nonces

Expand All @@ -15,23 +12,6 @@
class BillingHarness(Harness):

def setUp(self):
# Balanced Customer without funding instruments
self.david = self.make_participant('david', is_suspicious=False,
claimed_time='now',
balanced_customer_href=self.david_href)

# Balanced Customer with CC attached
self.janet = self.make_participant('janet', is_suspicious=False,
claimed_time='now',
balanced_customer_href=self.janet_href)
self.janet_route = ExchangeRoute.insert(self.janet, 'balanced-cc', self.card_href)

# Balanced Customer with BA attached
self.homer = self.make_participant('homer', is_suspicious=False,
claimed_time='now',
balanced_customer_href=self.homer_href)
self.homer_route = ExchangeRoute.insert(self.homer, 'balanced-ba', self.bank_account_href)

# Braintree Customer without funding instruments
self.roman = self.make_participant('roman', is_suspicious=False,
claimed_time='now',
Expand All @@ -41,15 +21,14 @@ def setUp(self):
claimed_time='now',
braintree_customer_id=self.obama_bt_id)
self.obama_route = ExchangeRoute.insert(self.obama, 'braintree-cc', self.obama_cc_token)
# A customer with Paypal attached.
self.homer = self.make_participant('homer', is_suspicious=False,
claimed_time='now')
self.homer_route = ExchangeRoute.insert(self.homer, 'paypal', '[email protected]')


@classmethod
def tearDownClass(cls):
has_exchange_id = balanced.Transaction.f.meta.contains('exchange_id')
credits = balanced.Credit.query.filter(has_exchange_id)
debits = balanced.Debit.query.filter(has_exchange_id)
for t in itertools.chain(credits, debits):
t.meta.pop('exchange_id')
t.save()
# Braintree Cleanup
existing_holds = braintree.Transaction.search(
braintree.TransactionSearch.status == 'authorized'
Expand All @@ -61,43 +40,6 @@ def tearDownClass(cls):

with use_cassette('BillingHarness'):
cls = BillingHarness
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)

cls.roman_bt_id = braintree.Customer.create().customer.id

Expand Down
Loading