Private
Public Access
1
0

more coverage stuff

This commit is contained in:
Sander Roosendaal
2021-04-26 11:34:37 +02:00
parent df86eaac0c
commit 544b27e7c0
9 changed files with 312 additions and 152 deletions

View File

@@ -36,13 +36,13 @@ def paidplans_view(request):
@login_required()
def billing_view(request):
if not PAYMENT_PROCESSING_ON: # pragma: no cover
if not PAYMENT_PROCESSING_ON: # pragma: no cover # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
r = request.user.rower
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
if payments.is_existing_customer(r): # pragma: no cover
@@ -89,7 +89,7 @@ def billing_view(request):
message="This functionality requires a Coach or Self-Coach plan",
redirect_field_name=None)
def buy_trainingplan_view(request,id=0):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
@@ -97,10 +97,10 @@ def buy_trainingplan_view(request,id=0):
plan = get_object_or_404(InstantPlan,pk=id)
if r.paymentprocessor != 'braintree':
if r.paymentprocessor != 'braintree': # pragma: no cover
messages.error(request,"This purchase is currently only available through BrainTree (by PayPal)")
if id == 0 or id is None:
if id == 0 or id is None: # pragma: no cover
messages.error(request,"There was an error accessing this plan")
url = reverse('rower_view_instantplan',kwargs={
'id':plan.uuid,
@@ -111,7 +111,7 @@ def buy_trainingplan_view(request,id=0):
if request.method == 'POST':
billingaddressform = RowerBillingAddressForm(instance=r)
form = InstantPlanSelectForm(request.POST)
if billingaddressform.is_valid():
if billingaddressform.is_valid(): # pragma: no cover
cd = billingaddressform.cleaned_data
for attr, value in cd.items():
setattr(r, attr, value)
@@ -134,16 +134,16 @@ def buy_trainingplan_view(request,id=0):
try:
targetid = request.POST['target']
if targetid != '':
if targetid != '': # pragma: no cover
target = TrainingTarget.objects.get(id=int(targetid))
else:
else: # pragma: no cover
target = None
except KeyError:
target = None
if target and datechoice == 'target':
if target and datechoice == 'target': # pragma: no cover
enddate = target.date
elif datechoice == 'startdate':
elif datechoice == 'startdate': # pragma: no cover
enddate = startdate+datetime.timedelta(days=plan.duration)
else:
startdate = enddate-datetime.timedelta(days=plan.duration)
@@ -177,13 +177,13 @@ def buy_trainingplan_view(request,id=0):
message="This functionality requires a Coach or Self-Coach plan",
redirect_field_name=None)
def purchase_checkouts_view(request):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
r = request.user.rower
if request.method != 'POST':
if request.method != 'POST': # pragma: no cover
url = reverse('rower_view_instantplan',kwargs={
'id':plan.uuid,
})
@@ -199,7 +199,7 @@ def purchase_checkouts_view(request):
url = settings.WORKOUTS_FIT_URL+"/trainingplan/"+str(plan.uuid)
headers = {'Authorization':authorizationstring}
response = requests.get(url=url,headers=headers)
if response.status_code != 200:
if response.status_code != 200: # pragma: no cover
messages.error(request,"Could not connect to the training plan server")
return HttpResponseRedirect(reverse('rower_select_instantplan'))
@@ -233,13 +233,13 @@ def purchase_checkouts_view(request):
url = url+'?when='+timeperiod
return HttpResponseRedirect(url)
else:
else: # pragma: no cover
messages.error(request,"There was a problem with your payment")
url = reverse('rower_view_instantplan',kwargs={
'id':plan.uuid,
})
return HttpResponseRedirect(url)
elif 'tac' not in request.POST:
elif 'tac' not in request.POST: # pragma: no cover
try:
planid=int(request.POST['plan'])
enddate = request.POST['enddate']
@@ -250,19 +250,19 @@ def purchase_checkouts_view(request):
url = reverse("purchase_checkouts_view")
return HttpResponseRedirect(url)
url = reverse('rower_select_instantplan')
if 'plan' in request.POST:
url = reverse('rower_select_instantplan') # pragma: no cover
if 'plan' in request.POST: # pragma: no cover
plan = plan = InstantPlan.objects.get(id=request.POST['plan'])
url = reverse('rower_view_instantplan',kwargs={
'id':plan.uuid,
})
return HttpResponseRedirect(url)
return HttpResponseRedirect(url) # pragma: no cover
@user_passes_test(can_plan,login_url="/rowers/paidplans",
message="This functionality requires a Coach or Self-Coach plan",
redirect_field_name=None)
def confirm_trainingplan_purchase_view(request,id = 0):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
@@ -270,10 +270,10 @@ def confirm_trainingplan_purchase_view(request,id = 0):
plan = get_object_or_404(InstantPlan,pk=id)
if r.paymentprocessor != 'braintree':
if r.paymentprocessor != 'braintree': # pragma: no cover
messages.error(request,"This purchase is currently only available through BrainTree (by PayPal)")
if id == 0 or id is None:
if id == 0 or id is None: # pragma: no cover
messages.error(request,"There was an error accessing this plan")
url = reverse('rower_view_instantplan',kwargs={
'id':plan.uuid,
@@ -287,7 +287,7 @@ def confirm_trainingplan_purchase_view(request,id = 0):
name = request.GET.get('name','')
status = request.GET.get('status',True)
notes = request.GET.get('notes','')
if enddate is None:
if enddate is None: # pragma: no cover
messages.error(request,"There was an error accessing this plan")
url = reverse('rower_view_instantplan',kwargs={
'id':plan.uuid,
@@ -307,16 +307,16 @@ def confirm_trainingplan_purchase_view(request,id = 0):
@login_required()
def upgrade_view(request):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
r = request.user.rower
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
if r.subscription_id is None or r.subscription_id == '':
if r.subscription_id is None or r.subscription_id == '': # pragma: no cover
url = reverse(billing_view)
return HttpResponseRedirect(url)
@@ -352,16 +352,16 @@ def upgrade_view(request):
@login_required()
def downgrade_view(request):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
r = request.user.rower
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
if r.subscription_id is None or r.subscription_id == '':
if r.subscription_id is None or r.subscription_id == '': # pragma: no cover
url = reverse(billing_view)
return HttpResponseRedirect(url)
@@ -378,9 +378,9 @@ def downgrade_view(request):
if planselectform.is_valid():
plan = planselectform.cleaned_data['plan']
if plan.price > r.paidplan.price:
if plan.price > r.paidplan.price: # pragma: no cover
nextview = upgrade_confirm_view
elif plan.price == r.paidplan.price:
elif plan.price == r.paidplan.price: # pragma: no cover
messages.info(request,'You did not select a new plan')
url = reverse(downgrade_view)
return HttpResponseRedirect(url)
@@ -409,7 +409,7 @@ def downgrade_view(request):
@login_required()
def plan_stop_view(request):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
@@ -417,13 +417,13 @@ def plan_stop_view(request):
subscriptions = []
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
if r.paidplan is not None and r.paidplan.paymentprocessor == 'braintree':
try:
subscriptions = braintreestuff.find_subscriptions(r)
except ProcessorCustomerError:
except ProcessorCustomerError: # pragma: no cover
r.paymentprocessor = None
r.save()
@@ -437,13 +437,13 @@ def plan_stop_view(request):
@login_required()
def plan_tobasic_view(request,id=0):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
r = request.user.rower
if r.paidplan.paymentprocessor == 'braintree':
if r.paidplan.paymentprocessor == 'braintree': # pragma: no cover
success, themessages,errormessages = braintreestuff.cancel_subscription(r,id)
for message in themessages:
messages.info(request,message)
@@ -459,20 +459,20 @@ def plan_tobasic_view(request,id=0):
@login_required()
def upgrade_confirm_view(request,planid = 0):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
try:
plan = PaidPlan.objects.get(id=planid)
except PaidPlan.DoesNotExist:
except PaidPlan.DoesNotExist: # pragma: no cover
messages.error(request,"Something went wrong. Please try again.")
url = reverse(billing_view)
return HttpResponseRedirect(url)
r = request.user.rower
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
client_token = braintreestuff.get_client_token(r)
@@ -487,13 +487,13 @@ def upgrade_confirm_view(request,planid = 0):
@login_required()
def downgrade_confirm_view(request,planid = 0):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
try:
plan = PaidPlan.objects.get(id=planid)
except PaidPlan.DoesNotExist:
except PaidPlan.DoesNotExist: # pragma: no cover
messages.error(request,"Something went wrong. Please try again.")
url = reverse(billing_view)
return HttpResponseRedirect(url)
@@ -513,20 +513,20 @@ def downgrade_confirm_view(request,planid = 0):
@login_required()
def payment_confirm_view(request,planid = 0):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
try:
plan = PaidPlan.objects.get(id=planid)
except PaidPlan.DoesNotExist:
except PaidPlan.DoesNotExist: # pragma: no cover
messages.error(request,"Something went wrong. Please try again.")
url = reverse(billing_view)
return HttpResponseRedirect(url)
r = request.user.rower
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
client_token = braintreestuff.get_client_token(r)
@@ -542,17 +542,17 @@ def payment_confirm_view(request,planid = 0):
@login_required()
def checkouts_view(request):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
r = request.user.rower
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring':
if r.paymentprocessor != 'braintree' and r.paymenttype == 'recurring': # pragma: no cover
messages.error(request,'Automated payment processing is currently only available through BrainTree (by PayPal). You are currently on a recurring payment plan with PayPal. Contact the site administrator at support@rowsandall.com before you proceed')
if request.method != 'POST':
if request.method != 'POST': # pragma: no cover
url = reverse(paidplans_view)
return HttpResponseRedirect(url)
@@ -566,11 +566,11 @@ def checkouts_view(request):
baseurl = reverse(payment_completed_view),
amount = amount)
return HttpResponseRedirect(url)
else:
else: # pragma: no cover
messages.error(request,"There was a problem with your payment")
url = reverse(billing_view)
return HttpResponseRedirect(url)
elif 'tac' not in request.POST:
elif 'tac' not in request.POST: # pragma: no cover
try:
planid = int(request.POST['plan'])
url = reverse('payment_confirm_view',kwargs={'planid':planid})
@@ -580,24 +580,24 @@ def checkouts_view(request):
messages.error(request,"There was an error in the payment form")
url = reverse('billing_view')
return HttpResponseRedirect(url)
else:
else: # pragma: no cover
messages.error(request,"There was an error in the payment form")
url = reverse(billing_view)
return HttpResponseRedirect(url)
url = reverse(paidplans_view)
return HttpResponseRedirect(url)
url = reverse(paidplans_view) # pragma: no cover
return HttpResponseRedirect(url) # pragma: no cover
@login_required()
def upgrade_checkouts_view(request):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
r = request.user.rower
if request.method != 'POST':
if request.method != 'POST': # pragma: no cover
url = reverse(paidplans_view)
return HttpResponseRedirect(url)
@@ -611,12 +611,12 @@ def upgrade_checkouts_view(request):
baseurl = reverse(payment_completed_view),
amount = amount)
return HttpResponseRedirect(url)
else:
else: # pragma: no cover
messages.error(request,"There was a problem with your payment")
url = reverse(upgrade_view)
return HttpResponseRedirect(url)
elif 'tac' not in request.POST:
elif 'tac' not in request.POST: # pragma: no cover
try:
planid = int(request.POST['plan'])
url = reverse('upgrade_confirm_view',kwargs={'planid':planid})
@@ -626,24 +626,24 @@ def upgrade_checkouts_view(request):
messages.error(request,"There was an error in the payment form")
url = reverse('billing_view')
return HttpResponseRedirect(url)
else:
else: # pragma: no cover
messages.error(request,"There was an error in the payment form")
url = reverse(upgrade_view)
return HttpResponseRedirect(url)
url = reverse(paidplans_view)
return HttpResponseRedirect(url)
url = reverse(paidplans_view) # pragma: no cover
return HttpResponseRedirect(url) # pragma: no cover
@login_required()
def downgrade_checkouts_view(request):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
r = request.user.rower
if request.method != 'POST':
if request.method != 'POST': # pragma: no cover
url = reverse(paidplans_view)
return HttpResponseRedirect(url)
@@ -655,11 +655,11 @@ def downgrade_checkouts_view(request):
messages.info(request,"Your plan has been updated")
url = reverse(downgrade_completed_view)
return HttpResponseRedirect(url)
else:
else: # pragma: no cover
messages.error(request,"There was a problem with your transaction")
url = reverse(upgrade_view)
return HttpResponseRedirect(url)
elif 'tac' not in request.POST:
elif 'tac' not in request.POST: # pragma: no cover
try:
planid = int(request.POST['plan'])
url = reverse('downgrade_confirm_view',kwargs={'planid':planid})
@@ -670,18 +670,18 @@ def downgrade_checkouts_view(request):
url = reverse('billing_view')
return HttpResponseRedirect(url)
else:
else: # pragma: no cover
messages.error(request,"There was an error in the payment form")
url = reverse(upgrade_view)
return HttpResponseRedirect(url)
url = reverse(paidplans_view)
return HttpResponseRedirect(url)
url = reverse(paidplans_view) # pragma: no cover
return HttpResponseRedirect(url) # pragma: no cover
@login_required()
def payment_completed_view(request):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
@@ -699,7 +699,7 @@ def payment_completed_view(request):
@login_required()
def downgrade_completed_view(request):
if not PAYMENT_PROCESSING_ON:
if not PAYMENT_PROCESSING_ON: # pragma: no cover
url = reverse('promembership')
return HttpResponseRedirect(url)
@@ -716,7 +716,7 @@ from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from django.contrib.sites.shortcuts import get_current_site
from rowers.tokens import account_activation_token
# Email activation
def useractivate(request, uidb64, token):
def useractivate(request, uidb64, token): # pragma: no cover
try:
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(id=uid)
@@ -768,7 +768,7 @@ def useractivate(request, uidb64, token):
def rower_register_view(request):
nextpage = request.GET.get('next','/rowers/list-workouts/')
if nextpage == '':
if nextpage == '': # pragma: no cover
nextpage = '/rowers/list-workouts/'
if request.method == 'POST':
@@ -848,7 +848,7 @@ def rower_register_view(request):
return HttpResponseRedirect(nextpage)
# '/rowers/register/thankyou/')
else:
else: # pragma: no cover
return render(request,
"registration_form.html",
{'form':form,
@@ -861,10 +861,10 @@ def rower_register_view(request):
'next':nextpage,})
# User registration
def freecoach_register_view(request):
def freecoach_register_view(request): # pragma: no cover
nextpage = request.GET.get('next','/rowers/me/teams/')
if nextpage == '':
if nextpage == '': # pragma: no cover
nextpage = '/rowers/me/teams/'
if request.method == 'POST':
@@ -924,7 +924,7 @@ def freecoach_register_view(request):
return HttpResponseRedirect(nextpage)
else:
else: # pragma: no cover
return render(request,
"freecoach_registration_form.html",
{'form':form,
@@ -941,7 +941,7 @@ def freecoach_register_view(request):
@login_required()
@permission_required('rower.is_staff',fn=get_user_by_userid,raise_exception=True)
def transactions_view(request):
def transactions_view(request): # pragma: no cover
if not request.user.is_staff:
raise PermissionDenied("Not Allowed")