Skip to content

Commit

Permalink
fix verification testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jdungan authored and groovecoder committed Oct 30, 2016
1 parent bf76e2d commit d3a932d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
1 change: 0 additions & 1 deletion auctions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ def payout(self):
discount=discount_amount
)
new_offer.save()

# capture payment to this users account
payout = Payout(
user=offer.user,
Expand Down
1 change: 0 additions & 1 deletion payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def identity_verified(self):
else:
# returning True will allow the bank account_id to be assigned
return True

if not self.verification:
return True
else:
Expand Down
48 changes: 28 additions & 20 deletions payments/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,53 @@


def setUpPackage(self):
# mock stripe Customer
mock_id = fudge.Fake().has_attr(id='dammit')
mock_ext_acct = (
fudge.Fake().has_attr(external_account='').provides('save').is_a_stub()
)

mock_customer = (
fudge.Fake().provides('create').returns(mock_id)
)
self.patch_stripe = fudge.patch_object(
'payments.utils.stripe', 'Customer', mock_customer)

mock_keys = {"id": "acct_12QkqYGSOD4VcegJ",
"keys": {"secret": "sk_live_AxSI9q6ieYWjGIeRbURf6EG0",
"publishable": "pk_live_h9xguYGf2GcfytemKs5tHrtg"
}}

mock_account = (
fudge.Fake().provides('create').returns(mock_keys)
.provides('retrieve').returns(mock_ext_acct)
)

self.patch_stripe = fudge.patch_object(
'payments.utils.stripe', 'Account', mock_account)

# mock stripe Event
evt_resp = json.loads(payment_created)

mock_event = (
fudge.Fake().provides('retrieve').has_attr(verified=True)
.returns(evt_resp)
)

self.patch_stripe = fudge.patch_object(
'payments.utils.stripe', 'Event', mock_event)

# mock stripe account_id
setup_mock_account(verification=account_verified)


def tearDownPackage(self):
self.patch_stripe.restore()


def setup_mock_account(verification):
account_id = 'acct_12QkqYGSOD4VcegJ'
mock_ext_acct = (
fudge.Fake().has_attr(external_account='')
.provides('save').is_a_stub()
)
mock_ext_acct.has_attr(id=account_id)
mock_ext_acct.has_attr(verification=json.loads(verification))

mock_keys = {"id": account_id,
"keys": {"secret": "sk_live_AxSI9q6ieYWjGIeRbURf6EG0",
"publishable": "pk_live_h9xguYGf2GcfytemKs5tHrtg"}}

mock_account = (
fudge.Fake().provides('create').returns(mock_keys)
.provides('retrieve').returns(mock_ext_acct)
)

fudge.patch_object(
'payments.utils.stripe', 'Account', mock_account)


# test constants below:
account_verified = """
{
Expand All @@ -54,7 +62,7 @@ def tearDownPackage(self):

account_not_verified = """
{
"due_by": "null",
"due_by": "123",
"fields_needed": [
"legal_entity.first_name",
"legal_entity.last_name"
Expand Down
8 changes: 5 additions & 3 deletions payments/tests/model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from . import (
application_fee_created, balance_available, account_verified,
account_not_verified, payment_created, account_updated
account_not_verified, payment_created, account_updated, setup_mock_account
)


Expand All @@ -38,12 +38,14 @@ def test_identity_verified(self):
# new accounts should pass
self.assertTrue(account.identity_verified())

account.account_id = "something"

# test valid verification
account.verification = account_verified
setup_mock_account(verification=account_verified)
self.assertTrue(account.identity_verified())

# test invalid verification
account.verification = account_not_verified
setup_mock_account(verification=account_not_verified)
self.assertFalse(account.identity_verified())

def test_fields_needed(self):
Expand Down
1 change: 1 addition & 0 deletions payments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def refund(offer):
)
if refund:
offer.refund_id = refund.id
offer.save()
except Exception as e:
print e.message
offer.error_message = e.message
Expand Down

0 comments on commit d3a932d

Please sign in to comment.