adding some tests on payments, not passing yet
This commit is contained in:
@@ -217,17 +217,22 @@ def create_subscription(rower,data):
|
||||
"payment_method_nonce": nonce_from_the_client
|
||||
})
|
||||
|
||||
print 'aap'
|
||||
|
||||
if result.is_success:
|
||||
payment_method_token = result.payment_method.token
|
||||
else:
|
||||
return False,0
|
||||
|
||||
print 'noot'
|
||||
|
||||
result = gateway.subscription.create({
|
||||
"payment_method_token": payment_method_token,
|
||||
"plan_id": plan.external_id
|
||||
})
|
||||
|
||||
if result.is_success:
|
||||
print 'mies'
|
||||
rower.paidplan = plan
|
||||
rower.planexpires = result.subscription.billing_period_end_date
|
||||
rower.teamplanexpires = result.subscription.billing_period_end_date
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<p>
|
||||
This is a preview of the page with advanced functionality for Pro users.
|
||||
See <a href="/rowers/about">the About page</a> for more information
|
||||
See <a href="/rowers/about/">the About page</a> for more information
|
||||
and to sign up for Pro Membership
|
||||
</p>
|
||||
{% endif %}
|
||||
@@ -30,7 +30,7 @@
|
||||
</tr>
|
||||
<th>Public link to this workout</th>
|
||||
<td>
|
||||
<a href="/rowers/workout/{{ workout.id }}">https://rowsandall.com/rowers/workout/{{ workout.id }}</a>
|
||||
<a href="/rowers/workout/{{ workout.id }}/">https://rowsandall.com/rowers/workout/{{ workout.id }}</a>
|
||||
<td>
|
||||
|
||||
</table>
|
||||
@@ -42,7 +42,7 @@
|
||||
{% if instrokemetrics %}
|
||||
{% for metric in instrokemetrics %}
|
||||
<p>
|
||||
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/instroke/{{ metric }}">{{ metric }}</a>
|
||||
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/instroke/{{ metric }}/">{{ metric }}</a>
|
||||
</p>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
While the wind and stream correction is fairly reliable, the OTW to OTE conversion sometimes throws errors. Those data points are omitted and replaced by interpolated values. We are sorry if this messed up some of your plots.
|
||||
</li>
|
||||
<li>
|
||||
Read more details about the way we calculate things <a href="/rowers/physics">here</a>.
|
||||
Read more details about the way we calculate things <a href="/rowers/physics/">here</a>.
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
@@ -172,6 +172,126 @@ class MockStravalibClient():
|
||||
def update_activity(*args, **kwargs):
|
||||
return StravaActivity()
|
||||
|
||||
class gatewayresult():
|
||||
def __init__(self,*args,**kwargs):
|
||||
self.is_success = kwargs.pop('is_success',True)
|
||||
self.customer_id = 1
|
||||
self.transaction = vtransaction()
|
||||
self.payment_method = payment_method()
|
||||
self.subscription = vsubscription()
|
||||
|
||||
class credit_card():
|
||||
def __init__(self, *args, **kwargs):
|
||||
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):
|
||||
return gatewayresult(is_success=True)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.credit_cards = [credit_card(),credit_card()]
|
||||
self.paypal_accounts = [paypal_account()]
|
||||
|
||||
class client_token():
|
||||
def generate(*args, **kwargs):
|
||||
return 'aapnooit'
|
||||
|
||||
class plan():
|
||||
def all(*args, **kwargs):
|
||||
return []
|
||||
|
||||
|
||||
|
||||
class transaction():
|
||||
def sale(*args, **kwargs):
|
||||
return gatewayresult(is_success=True)
|
||||
|
||||
def search(*args, **kwargs):
|
||||
return [gatewayresult(is_success=True),gatewayresult(is_success=True)]
|
||||
|
||||
def __init__(self,*args, **kwargs):
|
||||
self.amount = 15
|
||||
self.credit_card_details = credit_card()
|
||||
self.customer = {
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doe',
|
||||
'id': 12
|
||||
}
|
||||
self.created_at = datetime.datetime.now()
|
||||
self.currency_iso_code = 'EUR'
|
||||
|
||||
class vtransaction():
|
||||
def __init__(self,*args, **kwargs):
|
||||
self.amount = 15
|
||||
self.credit_card_details = credit_card()
|
||||
self.customer = {
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doe',
|
||||
'id': 12
|
||||
}
|
||||
self.created_at = datetime.datetime.now()
|
||||
self.currency_iso_code = 'EUR'
|
||||
|
||||
class vsubscription():
|
||||
def update(*args, **kwargs):
|
||||
return gatewayresult(is_success=True)
|
||||
|
||||
def cancel(*args, **kwargs):
|
||||
return gatewayresult()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.id = 121
|
||||
self.billing_period_end_date = (datetime.datetime.now()+datetime.timedelta(days=365)).date()
|
||||
self.status = 'Active'
|
||||
self.plan_id = 12
|
||||
self.price = 15
|
||||
self.never_expires = True
|
||||
|
||||
class subscription():
|
||||
def create(*args, **kwargs):
|
||||
return gatewayresult(is_success=True)
|
||||
|
||||
def update(*args, **kwargs):
|
||||
return gatewayresult(is_success=True)
|
||||
|
||||
def cancel(*args, **kwargs):
|
||||
return gatewayresult()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.id = 121
|
||||
self.billing_period_end_date = (datetime.datetime.now()+datetime.timedelta(days=365)).date()
|
||||
self.transactions = [vtransaction()]
|
||||
self.status = 'Active'
|
||||
self.plan_id = 12
|
||||
self.price = 15
|
||||
self.never_expires = True
|
||||
|
||||
|
||||
class payment_method():
|
||||
def create(*args, **kwargs):
|
||||
return gatewayresult()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.token = 'liesjeleerdelotje'
|
||||
|
||||
# mock braintree gateway
|
||||
class MockBraintreeGateway():
|
||||
def __init__(self,*args, **kwargs):
|
||||
self.customer = customer()
|
||||
self.client_token = client_token()
|
||||
self.plan = plan()
|
||||
self.transaction = transaction()
|
||||
self.subscription = subscription()
|
||||
self.payment_method = payment_method()
|
||||
|
||||
|
||||
class mocked_rowingdata(rowingdata):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
@@ -17,3 +17,6 @@ class TestErrorPages(TestCase):
|
||||
self.assertEqual(response.status_code, 500)
|
||||
self.assertIn('500 Internal Server Error', unicode(response))
|
||||
|
||||
response = error400_view(request)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
|
||||
270
rowers/tests/test_payments.py
Normal file
270
rowers/tests/test_payments.py
Normal file
@@ -0,0 +1,270 @@
|
||||
from statements import *
|
||||
|
||||
nu = datetime.datetime.now()
|
||||
|
||||
from django_countries import countries
|
||||
|
||||
class PaymentTest(TestCase):
|
||||
def setUp(self):
|
||||
self.u = UserFactory()
|
||||
self.r = Rower.objects.create(user=self.u,
|
||||
birthdate=faker.profile()['birthdate'],
|
||||
gdproptin=True,
|
||||
gdproptindate=timezone.now(),
|
||||
rowerplan='coach',
|
||||
paymentprocessor='braintree',
|
||||
street_address = faker.street_address(),
|
||||
city = faker.city(),
|
||||
postal_code = faker.postalcode(),
|
||||
country = faker.country(),
|
||||
)
|
||||
|
||||
p = PaidPlan(
|
||||
shortname='free',
|
||||
name='Basic',
|
||||
external_id='a',
|
||||
price=0,
|
||||
paymentprocessor='braintree',
|
||||
paymenttype='single',
|
||||
)
|
||||
|
||||
p.save()
|
||||
|
||||
p = PaidPlan(
|
||||
shortname='pro_recurring',
|
||||
name='Pro (recurring)',
|
||||
external_id='b',
|
||||
price=15,
|
||||
paymentprocessor='braintree',
|
||||
paymenttype='single',
|
||||
)
|
||||
|
||||
p.save()
|
||||
|
||||
p = PaidPlan(
|
||||
shortname='pro_single',
|
||||
name='Pro (single)',
|
||||
external_id='c',
|
||||
price=20,
|
||||
paymentprocessor='braintree',
|
||||
paymenttype='single',
|
||||
)
|
||||
|
||||
p.save()
|
||||
|
||||
self.c = Client()
|
||||
self.password = faker.word()
|
||||
self.u.set_password(self.password)
|
||||
self.u.save()
|
||||
|
||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
||||
def test_billing_view(self,mock_gateway):
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = '/rowers/billing/'
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
plans = PaidPlan.objects.filter(price__gt=0).order_by('price')
|
||||
plan = plans[0]
|
||||
|
||||
country = faker.country()
|
||||
countrycode = 'NL'
|
||||
for code, name in list(countries):
|
||||
if name.lower() == country.lower():
|
||||
countrycode = code
|
||||
|
||||
form_data = {
|
||||
'street_address':faker.street_address(),
|
||||
'city':faker.city(),
|
||||
'postal_code':faker.postalcode(),
|
||||
'country':countrycode,
|
||||
'plan':plan.id,
|
||||
}
|
||||
|
||||
form = RowerBillingAddressForm(form_data)
|
||||
self.assertTrue(form.is_valid)
|
||||
|
||||
form = PlanSelectForm(form_data,paymentprocessor='braintree')
|
||||
self.assertTrue(form.is_valid)
|
||||
|
||||
response = self.c.post(url,form_data,follow=True)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
expected_url = '/rowers/checkout/'+str(plan.id)+'/'
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url = expected_url,
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
||||
def test_upgrade_view(self,mock_gateway):
|
||||
self.r.country = 'NL'
|
||||
self.r.customer_id = 34
|
||||
self.r.subscription_id = 34
|
||||
self.r.save()
|
||||
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = '/rowers/upgrade/'
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
plans = PaidPlan.objects.filter(price__gt=0).order_by('price')
|
||||
plan = plans[0]
|
||||
|
||||
country = faker.country()
|
||||
countrycode = 'NL'
|
||||
for code, name in list(countries):
|
||||
if name.lower() == country.lower():
|
||||
countrycode = code
|
||||
|
||||
form_data = {
|
||||
'street_address':faker.street_address(),
|
||||
'city':faker.city(),
|
||||
'postal_code':faker.postalcode(),
|
||||
'country':countrycode,
|
||||
'plan':plan.id,
|
||||
}
|
||||
|
||||
form = RowerBillingAddressForm(form_data)
|
||||
self.assertTrue(form.is_valid)
|
||||
|
||||
form = PlanSelectForm(form_data,paymentprocessor='braintree')
|
||||
self.assertTrue(form.is_valid)
|
||||
|
||||
response = self.c.post(url,form_data,follow=True)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
expected_url = '/rowers/upgradecheckout/'+str(plan.id)+'/'
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url = expected_url,
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
||||
def test_down_view(self,mock_gateway):
|
||||
self.r.country = 'NL'
|
||||
self.r.customer_id = 34
|
||||
self.r.subscription_id = 34
|
||||
self.r.save()
|
||||
|
||||
plans = PaidPlan.objects.all().order_by('price')
|
||||
plan = plans[1]
|
||||
|
||||
self.r.paidplan = plan
|
||||
self.r.save()
|
||||
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = '/rowers/downgrade/'
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
country = faker.country()
|
||||
countrycode = 'NL'
|
||||
for code, name in list(countries):
|
||||
if name.lower() == country.lower():
|
||||
countrycode = code
|
||||
|
||||
form_data = {
|
||||
'street_address':faker.street_address(),
|
||||
'city':faker.city(),
|
||||
'postal_code':faker.postalcode(),
|
||||
'country':countrycode,
|
||||
'plan':plans[0].id,
|
||||
}
|
||||
|
||||
form = RowerBillingAddressForm(form_data)
|
||||
self.assertTrue(form.is_valid)
|
||||
|
||||
form = PlanSelectForm(form_data,paymentprocessor='braintree')
|
||||
self.assertTrue(form.is_valid)
|
||||
|
||||
response = self.c.post(url,form_data,follow=True)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
expected_url = '/rowers/downgradecheckout/'+str(plans[0].id)+'/'
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url = expected_url,
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
||||
def test_planstop_view(self,mock_gateway):
|
||||
self.r.country = 'NL'
|
||||
self.r.customer_id = 34
|
||||
self.r.subscription_id = 34
|
||||
self.r.save()
|
||||
|
||||
plans = PaidPlan.objects.all().order_by('price')
|
||||
plan = plans[1]
|
||||
|
||||
self.r.paidplan = plan
|
||||
self.r.save()
|
||||
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = '/rowers/me/cancelsubscriptions/'
|
||||
|
||||
response = self.c.get(url)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
|
||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
||||
def test_planstobasic_view(self,mock_gateway):
|
||||
self.r.country = 'NL'
|
||||
self.r.customer_id = 34
|
||||
self.r.subscription_id = 34
|
||||
self.r.save()
|
||||
|
||||
plans = PaidPlan.objects.all().order_by('price')
|
||||
plan = plans[1]
|
||||
|
||||
self.r.paidplan = plan
|
||||
self.r.save()
|
||||
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = '/rowers/me/cancelsubscription/34/'
|
||||
|
||||
response = self.c.get(url,follow=True)
|
||||
self.assertEqual(response.status_code,200)
|
||||
self.assertRedirects(response,
|
||||
expected_url = '/rowers/me/cancelsubscriptions/',
|
||||
status_code=302,target_status_code=200)
|
||||
|
||||
@patch('rowers.braintreestuff.braintree.BraintreeGateway',side_effect=MockBraintreeGateway)
|
||||
def test_checkouts_view(self,mock_gateway):
|
||||
|
||||
plans = PaidPlan.objects.all().order_by('price')
|
||||
plan = plans[1]
|
||||
|
||||
form_data = {
|
||||
'amount':'15.00',
|
||||
'plan': plans[1].id,
|
||||
'payment_method_nonce': 'aap',
|
||||
}
|
||||
|
||||
form = BillingForm(form_data)
|
||||
self.assertTrue(form.is_valid)
|
||||
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
url = '/rowers/checkouts/'
|
||||
|
||||
response = self.c.post(url, form_data,follow=True)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
self.assertRedirects(response,
|
||||
expected_url = '/rowers/paymentcompleted/',
|
||||
status_code=302,target_status_code=200)
|
||||
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
Binary file not shown.
2523
rowers/tests/testdata/testdata.tcx
vendored
2523
rowers/tests/testdata/testdata.tcx
vendored
File diff suppressed because it is too large
Load Diff
@@ -1102,9 +1102,9 @@ def billing_view(request):
|
||||
setattr(r, attr, value)
|
||||
r.save()
|
||||
|
||||
if billingaddressform.is_valid():
|
||||
if planselectform.is_valid():
|
||||
plan = planselectform.cleaned_data['plan']
|
||||
if billingaddressform.is_valid():
|
||||
try:
|
||||
customer_id = braintreestuff.create_customer(r)
|
||||
except ProcessorCustomerError:
|
||||
@@ -1117,6 +1117,7 @@ def billing_view(request):
|
||||
})
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
else:
|
||||
billingaddressform = RowerBillingAddressForm(instance=r)
|
||||
planselectform = PlanSelectForm(paymentprocessor='braintree')
|
||||
|
||||
Reference in New Issue
Block a user