got a little further - still failing
This commit is contained in:
@@ -43,6 +43,7 @@ else:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
from rowers.models import Rower,PaidPlan
|
from rowers.models import Rower,PaidPlan
|
||||||
from rowers.utils import ProcessorCustomerError
|
from rowers.utils import ProcessorCustomerError
|
||||||
|
|
||||||
@@ -208,6 +209,9 @@ def update_subscription(rower,data,method='up'):
|
|||||||
def create_subscription(rower,data):
|
def create_subscription(rower,data):
|
||||||
planid = data['plan']
|
planid = data['plan']
|
||||||
plan = PaidPlan.objects.get(id=planid)
|
plan = PaidPlan.objects.get(id=planid)
|
||||||
|
print plan
|
||||||
|
print data
|
||||||
|
raise ValueError
|
||||||
nonce_from_the_client = data['payment_method_nonce']
|
nonce_from_the_client = data['payment_method_nonce']
|
||||||
amount = data['amount']
|
amount = data['amount']
|
||||||
|
|
||||||
@@ -217,22 +221,18 @@ def create_subscription(rower,data):
|
|||||||
"payment_method_nonce": nonce_from_the_client
|
"payment_method_nonce": nonce_from_the_client
|
||||||
})
|
})
|
||||||
|
|
||||||
print 'aap'
|
|
||||||
|
|
||||||
if result.is_success:
|
if result.is_success:
|
||||||
payment_method_token = result.payment_method.token
|
payment_method_token = result.payment_method.token
|
||||||
else:
|
else:
|
||||||
return False,0
|
return False,0
|
||||||
|
|
||||||
print 'noot'
|
|
||||||
|
|
||||||
result = gateway.subscription.create({
|
result = gateway.subscription.create({
|
||||||
"payment_method_token": payment_method_token,
|
"payment_method_token": payment_method_token,
|
||||||
"plan_id": plan.external_id
|
"plan_id": plan.external_id
|
||||||
})
|
})
|
||||||
|
|
||||||
if result.is_success:
|
if result.is_success:
|
||||||
print 'mies'
|
|
||||||
rower.paidplan = plan
|
rower.paidplan = plan
|
||||||
rower.planexpires = result.subscription.billing_period_end_date
|
rower.planexpires = result.subscription.billing_period_end_date
|
||||||
rower.teamplanexpires = result.subscription.billing_period_end_date
|
rower.teamplanexpires = result.subscription.billing_period_end_date
|
||||||
|
|||||||
@@ -172,125 +172,131 @@ class MockStravalibClient():
|
|||||||
def update_activity(*args, **kwargs):
|
def update_activity(*args, **kwargs):
|
||||||
return StravaActivity()
|
return StravaActivity()
|
||||||
|
|
||||||
class gatewayresult():
|
def mocked_gateway(*args, **kwargs):
|
||||||
def __init__(self,*args,**kwargs):
|
class gatewayresult():
|
||||||
self.is_success = kwargs.pop('is_success',True)
|
def __init__(self,*args,**kwargs):
|
||||||
self.customer_id = 1
|
self.is_success = kwargs.pop('is_success',True)
|
||||||
self.transaction = vtransaction()
|
self.customer_id = 1
|
||||||
self.payment_method = payment_method()
|
self.transaction = vtransaction()
|
||||||
self.subscription = vsubscription()
|
self.payment_method = payment_method()
|
||||||
|
self.subscription = vsubscription()
|
||||||
class credit_card():
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __unicode__():
|
||||||
self.subscriptions = [vsubscription()]
|
return "mockedgatewayresult"
|
||||||
self.country_of_issuance = 'US'
|
|
||||||
|
|
||||||
class paypal_account():
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.subscriptions = [vsubscription(),vsubscription()]
|
|
||||||
|
|
||||||
class customer():
|
class credit_card():
|
||||||
def find(*arg, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
return self
|
self.subscriptions = [vsubscription()]
|
||||||
|
self.country_of_issuance = 'US'
|
||||||
|
|
||||||
|
class paypal_account():
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.subscriptions = [vsubscription(),vsubscription()]
|
||||||
|
|
||||||
|
class customer():
|
||||||
|
def find(*arg, **kwargs):
|
||||||
|
return self
|
||||||
|
|
||||||
def create(*args, **kwargs):
|
def create(*args, **kwargs):
|
||||||
return gatewayresult(is_success=True)
|
return gatewayresult(is_success=True)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.credit_cards = [credit_card(),credit_card()]
|
self.credit_cards = [credit_card(),credit_card()]
|
||||||
self.paypal_accounts = [paypal_account()]
|
self.paypal_accounts = [paypal_account()]
|
||||||
|
|
||||||
class client_token():
|
class client_token():
|
||||||
def generate(*args, **kwargs):
|
def generate(*args, **kwargs):
|
||||||
return 'aapnooit'
|
return 'aapnooit'
|
||||||
|
|
||||||
class plan():
|
class plan():
|
||||||
def all(*args, **kwargs):
|
def all(*args, **kwargs):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class transaction():
|
class transaction():
|
||||||
def sale(*args, **kwargs):
|
def sale(*args, **kwargs):
|
||||||
return gatewayresult(is_success=True)
|
return gatewayresult(is_success=True)
|
||||||
|
|
||||||
def search(*args, **kwargs):
|
def search(*args, **kwargs):
|
||||||
return [gatewayresult(is_success=True),gatewayresult(is_success=True)]
|
return [gatewayresult(is_success=True),gatewayresult(is_success=True)]
|
||||||
|
|
||||||
def __init__(self,*args, **kwargs):
|
def __init__(self,*args, **kwargs):
|
||||||
self.amount = 15
|
self.amount = 15
|
||||||
self.credit_card_details = credit_card()
|
self.credit_card_details = credit_card()
|
||||||
self.customer = {
|
self.customer = {
|
||||||
'first_name': 'John',
|
'first_name': 'John',
|
||||||
'last_name': 'Doe',
|
'last_name': 'Doe',
|
||||||
'id': 12
|
'id': 12
|
||||||
}
|
}
|
||||||
self.created_at = datetime.datetime.now()
|
self.created_at = datetime.datetime.now()
|
||||||
self.currency_iso_code = 'EUR'
|
self.currency_iso_code = 'EUR'
|
||||||
|
|
||||||
class vtransaction():
|
class vtransaction():
|
||||||
def __init__(self,*args, **kwargs):
|
def __init__(self,*args, **kwargs):
|
||||||
self.amount = 15
|
self.amount = 15
|
||||||
self.credit_card_details = credit_card()
|
self.credit_card_details = credit_card()
|
||||||
self.customer = {
|
self.customer = {
|
||||||
'first_name': 'John',
|
'first_name': 'John',
|
||||||
'last_name': 'Doe',
|
'last_name': 'Doe',
|
||||||
'id': 12
|
'id': 12
|
||||||
}
|
}
|
||||||
self.created_at = datetime.datetime.now()
|
self.created_at = datetime.datetime.now()
|
||||||
self.currency_iso_code = 'EUR'
|
self.currency_iso_code = 'EUR'
|
||||||
|
|
||||||
class vsubscription():
|
class vsubscription():
|
||||||
def update(*args, **kwargs):
|
def update(*args, **kwargs):
|
||||||
return gatewayresult(is_success=True)
|
print 'aap vsubscription'
|
||||||
|
return gatewayresult(is_success=True)
|
||||||
|
|
||||||
def cancel(*args, **kwargs):
|
def cancel(*args, **kwargs):
|
||||||
return gatewayresult()
|
return gatewayresult(is_success=True)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.id = 121
|
self.id = 121
|
||||||
self.billing_period_end_date = (datetime.datetime.now()+datetime.timedelta(days=365)).date()
|
self.billing_period_end_date = (datetime.datetime.now()+datetime.timedelta(days=365)).date()
|
||||||
self.status = 'Active'
|
self.status = 'Active'
|
||||||
self.plan_id = 12
|
self.plan_id = 12
|
||||||
self.price = 15
|
self.price = 15
|
||||||
self.never_expires = True
|
self.never_expires = True
|
||||||
|
|
||||||
class subscription():
|
class subscription():
|
||||||
def create(*args, **kwargs):
|
def create(*args, **kwargs):
|
||||||
return gatewayresult(is_success=True)
|
print 'aap subscription'
|
||||||
|
return gatewayresult(is_success=True)
|
||||||
def update(*args, **kwargs):
|
|
||||||
return gatewayresult(is_success=True)
|
def update(*args, **kwargs):
|
||||||
|
return gatewayresult(is_success=True)
|
||||||
def cancel(*args, **kwargs):
|
|
||||||
return gatewayresult()
|
def cancel(*args, **kwargs):
|
||||||
|
return gatewayresult(is_success=True)
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.id = 121
|
def __init__(self, *args, **kwargs):
|
||||||
self.billing_period_end_date = (datetime.datetime.now()+datetime.timedelta(days=365)).date()
|
self.id = 121
|
||||||
self.transactions = [vtransaction()]
|
self.billing_period_end_date = (datetime.datetime.now()+datetime.timedelta(days=365)).date()
|
||||||
self.status = 'Active'
|
self.transactions = [vtransaction()]
|
||||||
self.plan_id = 12
|
self.status = 'Active'
|
||||||
self.price = 15
|
self.plan_id = 12
|
||||||
self.never_expires = True
|
self.price = 15
|
||||||
|
self.never_expires = True
|
||||||
|
|
||||||
|
|
||||||
class payment_method():
|
class payment_method():
|
||||||
def create(*args, **kwargs):
|
def create(*args, **kwargs):
|
||||||
return gatewayresult()
|
return gatewayresult()
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.token = 'liesjeleerdelotje'
|
self.token = 'liesjeleerdelotje'
|
||||||
|
|
||||||
# mock braintree gateway
|
# mock braintree gateway
|
||||||
class MockBraintreeGateway():
|
class MockBraintreeGateway():
|
||||||
def __init__(self,*args, **kwargs):
|
def __init__(self,*args, **kwargs):
|
||||||
self.customer = customer()
|
self.customer = customer()
|
||||||
self.client_token = client_token()
|
self.client_token = client_token()
|
||||||
self.plan = plan()
|
self.plan = plan()
|
||||||
self.transaction = transaction()
|
self.transaction = transaction()
|
||||||
self.subscription = subscription()
|
self.subscription = subscription()
|
||||||
self.payment_method = payment_method()
|
self.payment_method = payment_method()
|
||||||
|
|
||||||
|
|
||||||
class mocked_rowingdata(rowingdata):
|
class mocked_rowingdata(rowingdata):
|
||||||
|
|||||||
@@ -19,46 +19,54 @@ class PaymentTest(TestCase):
|
|||||||
country = faker.country(),
|
country = faker.country(),
|
||||||
)
|
)
|
||||||
|
|
||||||
p = PaidPlan(
|
# settings.DEBUG = True
|
||||||
|
|
||||||
|
p1 = PaidPlan(
|
||||||
shortname='free',
|
shortname='free',
|
||||||
name='Basic',
|
name='Basic',
|
||||||
external_id='a',
|
external_id='a',
|
||||||
price=0,
|
price=0,
|
||||||
|
clubsize=0,
|
||||||
paymentprocessor='braintree',
|
paymentprocessor='braintree',
|
||||||
paymenttype='single',
|
paymenttype='single',
|
||||||
)
|
)
|
||||||
|
|
||||||
p.save()
|
p1.save()
|
||||||
|
|
||||||
p = PaidPlan(
|
p2 = PaidPlan(
|
||||||
shortname='pro_recurring',
|
shortname='pro_recurring',
|
||||||
name='Pro (recurring)',
|
name='Pro (recurring)',
|
||||||
external_id='b',
|
external_id='b',
|
||||||
price=15,
|
price=15,
|
||||||
|
clubsize=0,
|
||||||
paymentprocessor='braintree',
|
paymentprocessor='braintree',
|
||||||
paymenttype='single',
|
paymenttype='single',
|
||||||
)
|
)
|
||||||
|
|
||||||
p.save()
|
p2.save()
|
||||||
|
|
||||||
p = PaidPlan(
|
p3 = PaidPlan(
|
||||||
shortname='pro_single',
|
shortname='pro_single',
|
||||||
name='Pro (single)',
|
name='Pro (single)',
|
||||||
external_id='c',
|
external_id='c',
|
||||||
price=20,
|
price=20,
|
||||||
|
clubsize=0,
|
||||||
paymentprocessor='braintree',
|
paymentprocessor='braintree',
|
||||||
paymenttype='single',
|
paymenttype='single',
|
||||||
)
|
)
|
||||||
|
|
||||||
p.save()
|
p3.save()
|
||||||
|
|
||||||
self.c = Client()
|
self.c = Client()
|
||||||
self.password = faker.word()
|
self.password = faker.word()
|
||||||
self.u.set_password(self.password)
|
self.u.set_password(self.password)
|
||||||
self.u.save()
|
self.u.save()
|
||||||
|
|
||||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
# def tearDown(self):
|
||||||
def test_billing_view(self,mock_gateway):
|
# settings.DEBUG = False
|
||||||
|
|
||||||
|
@patch('rowers.braintreestuff.gateway',side_effect=mocked_gateway)
|
||||||
|
def test_billing_view(self,MockBraintreeGateway):
|
||||||
login = self.c.login(username=self.u.username, password=self.password)
|
login = self.c.login(username=self.u.username, password=self.password)
|
||||||
self.assertTrue(login)
|
self.assertTrue(login)
|
||||||
|
|
||||||
@@ -99,8 +107,8 @@ class PaymentTest(TestCase):
|
|||||||
expected_url = expected_url,
|
expected_url = expected_url,
|
||||||
status_code=302,target_status_code=200)
|
status_code=302,target_status_code=200)
|
||||||
|
|
||||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
@patch('rowers.braintreestuff.gateway',side_effect=mocked_gateway)
|
||||||
def test_upgrade_view(self,mock_gateway):
|
def test_upgrade_view(self,MockBraintreeGateway):
|
||||||
self.r.country = 'NL'
|
self.r.country = 'NL'
|
||||||
self.r.customer_id = 34
|
self.r.customer_id = 34
|
||||||
self.r.subscription_id = 34
|
self.r.subscription_id = 34
|
||||||
@@ -146,8 +154,8 @@ class PaymentTest(TestCase):
|
|||||||
expected_url = expected_url,
|
expected_url = expected_url,
|
||||||
status_code=302,target_status_code=200)
|
status_code=302,target_status_code=200)
|
||||||
|
|
||||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
@patch('rowers.braintreestuff.gateway',side_effect=mocked_gateway)
|
||||||
def test_down_view(self,mock_gateway):
|
def test_down_view(self,MockBraintreeGateway):
|
||||||
self.r.country = 'NL'
|
self.r.country = 'NL'
|
||||||
self.r.customer_id = 34
|
self.r.customer_id = 34
|
||||||
self.r.subscription_id = 34
|
self.r.subscription_id = 34
|
||||||
@@ -196,8 +204,8 @@ class PaymentTest(TestCase):
|
|||||||
expected_url = expected_url,
|
expected_url = expected_url,
|
||||||
status_code=302,target_status_code=200)
|
status_code=302,target_status_code=200)
|
||||||
|
|
||||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
@patch('rowers.braintreestuff.gateway',side_effect=mocked_gateway)
|
||||||
def test_planstop_view(self,mock_gateway):
|
def test_planstop_view(self,MockBraintreeGateway):
|
||||||
self.r.country = 'NL'
|
self.r.country = 'NL'
|
||||||
self.r.customer_id = 34
|
self.r.customer_id = 34
|
||||||
self.r.subscription_id = 34
|
self.r.subscription_id = 34
|
||||||
@@ -218,8 +226,8 @@ class PaymentTest(TestCase):
|
|||||||
self.assertEqual(response.status_code,200)
|
self.assertEqual(response.status_code,200)
|
||||||
|
|
||||||
|
|
||||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
@patch('rowers.braintreestuff.gateway',side_effect=mocked_gateway)
|
||||||
def test_planstobasic_view(self,mock_gateway):
|
def test_planstobasic_view(self,MockBraintreeGateway):
|
||||||
self.r.country = 'NL'
|
self.r.country = 'NL'
|
||||||
self.r.customer_id = 34
|
self.r.customer_id = 34
|
||||||
self.r.subscription_id = 34
|
self.r.subscription_id = 34
|
||||||
@@ -242,8 +250,8 @@ class PaymentTest(TestCase):
|
|||||||
expected_url = '/rowers/me/cancelsubscriptions/',
|
expected_url = '/rowers/me/cancelsubscriptions/',
|
||||||
status_code=302,target_status_code=200)
|
status_code=302,target_status_code=200)
|
||||||
|
|
||||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
@patch('rowers.braintreestuff.gateway',side_effect=mocked_gateway)
|
||||||
def test_checkouts_view(self,mock_gateway):
|
def test_checkouts_view(self,MockBraintreeGateway):
|
||||||
|
|
||||||
plans = PaidPlan.objects.all().order_by('price')
|
plans = PaidPlan.objects.all().order_by('price')
|
||||||
plan = plans[1]
|
plan = plans[1]
|
||||||
|
|||||||
@@ -1040,7 +1040,7 @@ def ispromember(user):
|
|||||||
if not user.is_anonymous():
|
if not user.is_anonymous():
|
||||||
try:
|
try:
|
||||||
r = Rower.objects.get(user=user)
|
r = Rower.objects.get(user=user)
|
||||||
except Rower.DoesNotExists:
|
except Rower.DoesNotExist:
|
||||||
r = Rower(user=user)
|
r = Rower(user=user)
|
||||||
r.save()
|
r.save()
|
||||||
|
|
||||||
@@ -1381,6 +1381,7 @@ def checkouts_view(request):
|
|||||||
form = BillingForm(request.POST)
|
form = BillingForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
data = form.cleaned_data
|
data = form.cleaned_data
|
||||||
|
print r
|
||||||
success,amount = braintreestuff.create_subscription(r,data)
|
success,amount = braintreestuff.create_subscription(r,data)
|
||||||
if success:
|
if success:
|
||||||
messages.info(request,"Your payment has succeeded and your plan has been updated")
|
messages.info(request,"Your payment has succeeded and your plan has been updated")
|
||||||
|
|||||||
Reference in New Issue
Block a user